blob: 2839c0b9963554ae973bc388f22241dcd270fa97 [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 *Global_type;
127static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000128 "names",
129};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000130static PyTypeObject *Expr_type;
131static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000132 "value",
133};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000134static PyTypeObject *Pass_type;
135static PyTypeObject *Break_type;
136static PyTypeObject *Continue_type;
137static PyTypeObject *expr_type;
138static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000139 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000140 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000141};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000142static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000143static PyTypeObject *BoolOp_type;
144static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000145 "op",
146 "values",
147};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000148static PyTypeObject *BinOp_type;
149static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000150 "left",
151 "op",
152 "right",
153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *UnaryOp_type;
155static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "op",
157 "operand",
158};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000159static PyTypeObject *Lambda_type;
160static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000161 "args",
162 "body",
163};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000164static PyTypeObject *IfExp_type;
165static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000166 "test",
167 "body",
168 "orelse",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *Dict_type;
171static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000172 "keys",
173 "values",
174};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000175static PyTypeObject *Set_type;
176static char *Set_fields[]={
177 "elts",
178};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000179static PyTypeObject *ListComp_type;
180static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000181 "elt",
182 "generators",
183};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000184static PyTypeObject *GeneratorExp_type;
185static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000186 "elt",
187 "generators",
188};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000189static PyTypeObject *Yield_type;
190static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000191 "value",
192};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000193static PyTypeObject *Compare_type;
194static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000195 "left",
196 "ops",
197 "comparators",
198};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000199static PyTypeObject *Call_type;
200static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000201 "func",
202 "args",
203 "keywords",
204 "starargs",
205 "kwargs",
206};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000207static PyTypeObject *Num_type;
208static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000209 "n",
210};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000211static PyTypeObject *Str_type;
212static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213 "s",
214};
Georg Brandl52318d62006-09-06 07:06:08 +0000215static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000216static PyTypeObject *Attribute_type;
217static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000218 "value",
219 "attr",
220 "ctx",
221};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000222static PyTypeObject *Subscript_type;
223static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000224 "value",
225 "slice",
226 "ctx",
227};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000228static PyTypeObject *Name_type;
229static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000230 "id",
231 "ctx",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *List_type;
234static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "elts",
236 "ctx",
237};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000238static PyTypeObject *Tuple_type;
239static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000240 "elts",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
245*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
246static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000247static PyTypeObject *Load_type;
248static PyTypeObject *Store_type;
249static PyTypeObject *Del_type;
250static PyTypeObject *AugLoad_type;
251static PyTypeObject *AugStore_type;
252static PyTypeObject *Param_type;
253static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000254static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000255static PyTypeObject *Slice_type;
256static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000257 "lower",
258 "upper",
259 "step",
260};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000261static PyTypeObject *ExtSlice_type;
262static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000263 "dims",
264};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000265static PyTypeObject *Index_type;
266static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000267 "value",
268};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000270static PyObject *And_singleton, *Or_singleton;
271static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000272static PyTypeObject *And_type;
273static PyTypeObject *Or_type;
274static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000275static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
276*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
277*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
278*FloorDiv_singleton;
279static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *Add_type;
281static PyTypeObject *Sub_type;
282static PyTypeObject *Mult_type;
283static PyTypeObject *Div_type;
284static PyTypeObject *Mod_type;
285static PyTypeObject *Pow_type;
286static PyTypeObject *LShift_type;
287static PyTypeObject *RShift_type;
288static PyTypeObject *BitOr_type;
289static PyTypeObject *BitXor_type;
290static PyTypeObject *BitAnd_type;
291static PyTypeObject *FloorDiv_type;
292static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000293static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
294*USub_singleton;
295static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000296static PyTypeObject *Invert_type;
297static PyTypeObject *Not_type;
298static PyTypeObject *UAdd_type;
299static PyTypeObject *USub_type;
300static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000301static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
302*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
303*NotIn_singleton;
304static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000305static PyTypeObject *Eq_type;
306static PyTypeObject *NotEq_type;
307static PyTypeObject *Lt_type;
308static PyTypeObject *LtE_type;
309static PyTypeObject *Gt_type;
310static PyTypeObject *GtE_type;
311static PyTypeObject *Is_type;
312static PyTypeObject *IsNot_type;
313static PyTypeObject *In_type;
314static PyTypeObject *NotIn_type;
315static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000316static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000317static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000318 "target",
319 "iter",
320 "ifs",
321};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000322static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000323static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000324static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000325 "type",
326 "name",
327 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000328 "lineno",
329 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000330};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000331static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000332static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000333static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000334 "args",
335 "vararg",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000336 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000337 "kwarg",
338 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000339 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000341static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000343static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344 "arg",
345 "value",
346};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000347static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350 "name",
351 "asname",
352};
353
354
355static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
356{
357 PyObject *fnames, *result;
358 int i;
359 if (num_fields) {
360 fnames = PyTuple_New(num_fields);
361 if (!fnames) return NULL;
362 } else {
363 fnames = Py_None;
364 Py_INCREF(Py_None);
365 }
366 for(i=0; i < num_fields; i++) {
367 PyObject *field = PyString_FromString(fields[i]);
368 if (!field) {
369 Py_DECREF(fnames);
370 return NULL;
371 }
372 PyTuple_SET_ITEM(fnames, i, field);
373 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000374 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000375 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000376 Py_DECREF(fnames);
377 return (PyTypeObject*)result;
378}
379
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000380static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
381{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000382 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000383 PyObject *s, *l = PyList_New(num_fields);
384 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000385 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000386 s = PyString_FromString(attrs[i]);
387 if (!s) {
388 Py_DECREF(l);
389 return 0;
390 }
391 PyList_SET_ITEM(l, i, s);
392 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000393 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
394 Py_DECREF(l);
395 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000396}
397
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000398static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
399{
400 int i, n = asdl_seq_LEN(seq);
401 PyObject *result = PyList_New(n);
402 PyObject *value;
403 if (!result)
404 return NULL;
405 for (i = 0; i < n; i++) {
406 value = func(asdl_seq_GET(seq, i));
407 if (!value) {
408 Py_DECREF(result);
409 return NULL;
410 }
411 PyList_SET_ITEM(result, i, value);
412 }
413 return result;
414}
415
416static PyObject* ast2obj_object(void *o)
417{
418 if (!o)
419 o = Py_None;
420 Py_INCREF((PyObject*)o);
421 return (PyObject*)o;
422}
423#define ast2obj_identifier ast2obj_object
424#define ast2obj_string ast2obj_object
425static PyObject* ast2obj_bool(bool b)
426{
427 return PyBool_FromLong(b);
428}
429
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000430static PyObject* ast2obj_int(bool b)
431{
432 return PyInt_FromLong(b);
433}
434
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000435static int init_types(void)
436{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000437 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000438 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000439 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
440 mod_type = make_type("mod", AST_type, NULL, 0);
441 if (!mod_type) return 0;
442 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000444 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000445 Interactive_type = make_type("Interactive", mod_type,
446 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000447 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000448 Expression_type = make_type("Expression", mod_type, Expression_fields,
449 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000450 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000451 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 if (!Suite_type) return 0;
453 stmt_type = make_type("stmt", AST_type, NULL, 0);
454 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000455 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 FunctionDef_type = make_type("FunctionDef", stmt_type,
457 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000477 With_type = make_type("With", stmt_type, With_fields, 3);
478 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
484 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000491 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000497 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000499 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000501 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Continue_type) return 0;
503 expr_type = make_type("expr", AST_type, NULL, 0);
504 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000505 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000514 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000518 Set_type = make_type("Set", expr_type, Set_fields, 1);
519 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 GeneratorExp_type = make_type("GeneratorExp", expr_type,
523 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Str_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000535 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
536 if (!Ellipsis_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öwisbd260da2006-02-26 19:42:26 +0000577 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Index_type) return 0;
583 boolop_type = make_type("boolop", AST_type, NULL, 0);
584 if (!boolop_type) return 0;
585 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000586 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000588 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Or_singleton) return 0;
594 operator_type = make_type("operator", AST_type, NULL, 0);
595 if (!operator_type) return 0;
596 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000597 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000599 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000609 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000611 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000613 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000617 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000619 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000621 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000625 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000627 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000629 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000631 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000633 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000635 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000637 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000639 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!FloorDiv_singleton) return 0;
645 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
646 if (!unaryop_type) return 0;
647 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!USub_singleton) return 0;
664 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
665 if (!cmpop_type) return 0;
666 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000667 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000669 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000671 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000673 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000675 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000677 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000679 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000681 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000683 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000687 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000689 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000691 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000693 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000695 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000697 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000699 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000701 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000703 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!NotIn_singleton) return 0;
707 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000708 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!comprehension_type) return 0;
710 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000711 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!excepthandler_type) return 0;
Guido van Rossum4f72a782006-10-27 23:31:49 +0000713 arguments_type = make_type("arguments", AST_type, arguments_fields, 6);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!arguments_type) return 0;
715 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
716 if (!keyword_type) return 0;
717 alias_type = make_type("alias", AST_type, alias_fields, 2);
718 if (!alias_type) return 0;
719 initialized = 1;
720 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000721}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000722
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000723mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000724Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000725{
726 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000727 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000728 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000729 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000730 return NULL;
731 }
732 p->kind = Module_kind;
733 p->v.Module.body = body;
734 return p;
735}
736
737mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000738Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000739{
740 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000741 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000742 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000743 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000744 return NULL;
745 }
746 p->kind = Interactive_kind;
747 p->v.Interactive.body = body;
748 return p;
749}
750
751mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000752Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000753{
754 mod_ty p;
755 if (!body) {
756 PyErr_SetString(PyExc_ValueError,
757 "field body is required for Expression");
758 return NULL;
759 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000760 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000762 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763 return NULL;
764 }
765 p->kind = Expression_kind;
766 p->v.Expression.body = body;
767 return p;
768}
769
770mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000771Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000772{
773 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000774 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000776 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000777 return NULL;
778 }
779 p->kind = Suite_kind;
780 p->v.Suite.body = body;
781 return p;
782}
783
784stmt_ty
785FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000786 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787{
788 stmt_ty p;
789 if (!name) {
790 PyErr_SetString(PyExc_ValueError,
791 "field name is required for FunctionDef");
792 return NULL;
793 }
794 if (!args) {
795 PyErr_SetString(PyExc_ValueError,
796 "field args is required for FunctionDef");
797 return NULL;
798 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000799 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000801 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802 return NULL;
803 }
804 p->kind = FunctionDef_kind;
805 p->v.FunctionDef.name = name;
806 p->v.FunctionDef.args = args;
807 p->v.FunctionDef.body = body;
808 p->v.FunctionDef.decorators = decorators;
809 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000810 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811 return p;
812}
813
814stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000815ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
816 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817{
818 stmt_ty p;
819 if (!name) {
820 PyErr_SetString(PyExc_ValueError,
821 "field name is required for ClassDef");
822 return NULL;
823 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000824 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000826 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000827 return NULL;
828 }
829 p->kind = ClassDef_kind;
830 p->v.ClassDef.name = name;
831 p->v.ClassDef.bases = bases;
832 p->v.ClassDef.body = body;
833 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835 return p;
836}
837
838stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000839Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840{
841 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000842 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000844 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000845 return NULL;
846 }
847 p->kind = Return_kind;
848 p->v.Return.value = value;
849 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000850 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851 return p;
852}
853
854stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000855Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856{
857 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000858 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000860 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861 return NULL;
862 }
863 p->kind = Delete_kind;
864 p->v.Delete.targets = targets;
865 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000866 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 return p;
868}
869
870stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000871Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
872 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873{
874 stmt_ty p;
875 if (!value) {
876 PyErr_SetString(PyExc_ValueError,
877 "field value is required for Assign");
878 return NULL;
879 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000880 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000882 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000883 return NULL;
884 }
885 p->kind = Assign_kind;
886 p->v.Assign.targets = targets;
887 p->v.Assign.value = value;
888 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000889 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890 return p;
891}
892
893stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000894AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
895 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896{
897 stmt_ty p;
898 if (!target) {
899 PyErr_SetString(PyExc_ValueError,
900 "field target is required for AugAssign");
901 return NULL;
902 }
903 if (!op) {
904 PyErr_SetString(PyExc_ValueError,
905 "field op is required for AugAssign");
906 return NULL;
907 }
908 if (!value) {
909 PyErr_SetString(PyExc_ValueError,
910 "field value is required for AugAssign");
911 return NULL;
912 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000913 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000915 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000916 return NULL;
917 }
918 p->kind = AugAssign_kind;
919 p->v.AugAssign.target = target;
920 p->v.AugAssign.op = op;
921 p->v.AugAssign.value = value;
922 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000923 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000924 return p;
925}
926
927stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000928Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
929 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930{
931 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000932 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000933 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000934 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000935 return NULL;
936 }
937 p->kind = Print_kind;
938 p->v.Print.dest = dest;
939 p->v.Print.values = values;
940 p->v.Print.nl = nl;
941 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000942 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000943 return p;
944}
945
946stmt_ty
947For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000948 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949{
950 stmt_ty p;
951 if (!target) {
952 PyErr_SetString(PyExc_ValueError,
953 "field target is required for For");
954 return NULL;
955 }
956 if (!iter) {
957 PyErr_SetString(PyExc_ValueError,
958 "field iter is required for For");
959 return NULL;
960 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000961 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000962 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000963 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964 return NULL;
965 }
966 p->kind = For_kind;
967 p->v.For.target = target;
968 p->v.For.iter = iter;
969 p->v.For.body = body;
970 p->v.For.orelse = orelse;
971 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000972 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000973 return p;
974}
975
976stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000977While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
978 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979{
980 stmt_ty p;
981 if (!test) {
982 PyErr_SetString(PyExc_ValueError,
983 "field test is required for While");
984 return NULL;
985 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000986 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000988 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000989 return NULL;
990 }
991 p->kind = While_kind;
992 p->v.While.test = test;
993 p->v.While.body = body;
994 p->v.While.orelse = orelse;
995 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000996 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000997 return p;
998}
999
1000stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001001If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1002 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003{
1004 stmt_ty p;
1005 if (!test) {
1006 PyErr_SetString(PyExc_ValueError,
1007 "field test is required for If");
1008 return NULL;
1009 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001010 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001011 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001012 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013 return NULL;
1014 }
1015 p->kind = If_kind;
1016 p->v.If.test = test;
1017 p->v.If.body = body;
1018 p->v.If.orelse = orelse;
1019 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001020 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001021 return p;
1022}
1023
1024stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001026 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001027{
1028 stmt_ty p;
1029 if (!context_expr) {
1030 PyErr_SetString(PyExc_ValueError,
1031 "field context_expr is required for With");
1032 return NULL;
1033 }
1034 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1035 if (!p) {
1036 PyErr_NoMemory();
1037 return NULL;
1038 }
1039 p->kind = With_kind;
1040 p->v.With.context_expr = context_expr;
1041 p->v.With.optional_vars = optional_vars;
1042 p->v.With.body = body;
1043 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001044 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001045 return p;
1046}
1047
1048stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001049Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1050 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001051{
1052 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001053 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001055 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001056 return NULL;
1057 }
1058 p->kind = Raise_kind;
1059 p->v.Raise.type = type;
1060 p->v.Raise.inst = inst;
1061 p->v.Raise.tback = tback;
1062 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001063 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001064 return p;
1065}
1066
1067stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001068TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001069 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070{
1071 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001072 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001074 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return NULL;
1076 }
1077 p->kind = TryExcept_kind;
1078 p->v.TryExcept.body = body;
1079 p->v.TryExcept.handlers = handlers;
1080 p->v.TryExcept.orelse = orelse;
1081 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001082 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001083 return p;
1084}
1085
1086stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001087TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1088 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089{
1090 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001091 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001093 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001094 return NULL;
1095 }
1096 p->kind = TryFinally_kind;
1097 p->v.TryFinally.body = body;
1098 p->v.TryFinally.finalbody = finalbody;
1099 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001100 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101 return p;
1102}
1103
1104stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001105Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106{
1107 stmt_ty p;
1108 if (!test) {
1109 PyErr_SetString(PyExc_ValueError,
1110 "field test is required for Assert");
1111 return NULL;
1112 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001113 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001114 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001115 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 return NULL;
1117 }
1118 p->kind = Assert_kind;
1119 p->v.Assert.test = test;
1120 p->v.Assert.msg = msg;
1121 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001122 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001123 return p;
1124}
1125
1126stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001127Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128{
1129 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001130 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001132 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001133 return NULL;
1134 }
1135 p->kind = Import_kind;
1136 p->v.Import.names = names;
1137 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001138 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001139 return p;
1140}
1141
1142stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001143ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1144 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145{
1146 stmt_ty p;
1147 if (!module) {
1148 PyErr_SetString(PyExc_ValueError,
1149 "field module is required for ImportFrom");
1150 return NULL;
1151 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001152 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001153 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001154 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001155 return NULL;
1156 }
1157 p->kind = ImportFrom_kind;
1158 p->v.ImportFrom.module = module;
1159 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001160 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001162 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 return p;
1164}
1165
1166stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001167Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168{
1169 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001170 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001171 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001172 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173 return NULL;
1174 }
1175 p->kind = Global_kind;
1176 p->v.Global.names = names;
1177 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001178 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 return p;
1180}
1181
1182stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001183Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001184{
1185 stmt_ty p;
1186 if (!value) {
1187 PyErr_SetString(PyExc_ValueError,
1188 "field value is required for Expr");
1189 return NULL;
1190 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001191 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001193 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194 return NULL;
1195 }
1196 p->kind = Expr_kind;
1197 p->v.Expr.value = value;
1198 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001199 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 return p;
1201}
1202
1203stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001204Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001205{
1206 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001207 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001209 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210 return NULL;
1211 }
1212 p->kind = Pass_kind;
1213 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001214 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001215 return p;
1216}
1217
1218stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001219Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220{
1221 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001222 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001224 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001225 return NULL;
1226 }
1227 p->kind = Break_kind;
1228 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001229 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230 return p;
1231}
1232
1233stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001234Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235{
1236 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001237 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001238 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001239 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001240 return NULL;
1241 }
1242 p->kind = Continue_kind;
1243 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001244 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001245 return p;
1246}
1247
1248expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001249BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1250 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001251{
1252 expr_ty p;
1253 if (!op) {
1254 PyErr_SetString(PyExc_ValueError,
1255 "field op is required for BoolOp");
1256 return NULL;
1257 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001258 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001260 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001261 return NULL;
1262 }
1263 p->kind = BoolOp_kind;
1264 p->v.BoolOp.op = op;
1265 p->v.BoolOp.values = values;
1266 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001267 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001268 return p;
1269}
1270
1271expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001272BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1273 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001274{
1275 expr_ty p;
1276 if (!left) {
1277 PyErr_SetString(PyExc_ValueError,
1278 "field left is required for BinOp");
1279 return NULL;
1280 }
1281 if (!op) {
1282 PyErr_SetString(PyExc_ValueError,
1283 "field op is required for BinOp");
1284 return NULL;
1285 }
1286 if (!right) {
1287 PyErr_SetString(PyExc_ValueError,
1288 "field right is required for BinOp");
1289 return NULL;
1290 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001291 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001293 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001294 return NULL;
1295 }
1296 p->kind = BinOp_kind;
1297 p->v.BinOp.left = left;
1298 p->v.BinOp.op = op;
1299 p->v.BinOp.right = right;
1300 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001301 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302 return p;
1303}
1304
1305expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001306UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1307 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001308{
1309 expr_ty p;
1310 if (!op) {
1311 PyErr_SetString(PyExc_ValueError,
1312 "field op is required for UnaryOp");
1313 return NULL;
1314 }
1315 if (!operand) {
1316 PyErr_SetString(PyExc_ValueError,
1317 "field operand is required for UnaryOp");
1318 return NULL;
1319 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001320 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001321 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001322 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001323 return NULL;
1324 }
1325 p->kind = UnaryOp_kind;
1326 p->v.UnaryOp.op = op;
1327 p->v.UnaryOp.operand = operand;
1328 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001329 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001330 return p;
1331}
1332
1333expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001334Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1335 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001336{
1337 expr_ty p;
1338 if (!args) {
1339 PyErr_SetString(PyExc_ValueError,
1340 "field args is required for Lambda");
1341 return NULL;
1342 }
1343 if (!body) {
1344 PyErr_SetString(PyExc_ValueError,
1345 "field body is required for Lambda");
1346 return NULL;
1347 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001348 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001350 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 return NULL;
1352 }
1353 p->kind = Lambda_kind;
1354 p->v.Lambda.args = args;
1355 p->v.Lambda.body = body;
1356 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001357 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001358 return p;
1359}
1360
1361expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001362IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1363 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001364{
1365 expr_ty p;
1366 if (!test) {
1367 PyErr_SetString(PyExc_ValueError,
1368 "field test is required for IfExp");
1369 return NULL;
1370 }
1371 if (!body) {
1372 PyErr_SetString(PyExc_ValueError,
1373 "field body is required for IfExp");
1374 return NULL;
1375 }
1376 if (!orelse) {
1377 PyErr_SetString(PyExc_ValueError,
1378 "field orelse is required for IfExp");
1379 return NULL;
1380 }
1381 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1382 if (!p) {
1383 PyErr_NoMemory();
1384 return NULL;
1385 }
1386 p->kind = IfExp_kind;
1387 p->v.IfExp.test = test;
1388 p->v.IfExp.body = body;
1389 p->v.IfExp.orelse = orelse;
1390 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001391 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001392 return p;
1393}
1394
1395expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001396Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1397 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001398{
1399 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001400 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001401 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001402 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001403 return NULL;
1404 }
1405 p->kind = Dict_kind;
1406 p->v.Dict.keys = keys;
1407 p->v.Dict.values = values;
1408 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001409 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001410 return p;
1411}
1412
1413expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001414Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1415{
1416 expr_ty p;
1417 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1418 if (!p) {
1419 PyErr_NoMemory();
1420 return NULL;
1421 }
1422 p->kind = Set_kind;
1423 p->v.Set.elts = elts;
1424 p->lineno = lineno;
1425 p->col_offset = col_offset;
1426 return p;
1427}
1428
1429expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001430ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1431 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001432{
1433 expr_ty p;
1434 if (!elt) {
1435 PyErr_SetString(PyExc_ValueError,
1436 "field elt is required for ListComp");
1437 return NULL;
1438 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001439 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001441 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001442 return NULL;
1443 }
1444 p->kind = ListComp_kind;
1445 p->v.ListComp.elt = elt;
1446 p->v.ListComp.generators = generators;
1447 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001448 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001449 return p;
1450}
1451
1452expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001453GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1454 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001455{
1456 expr_ty p;
1457 if (!elt) {
1458 PyErr_SetString(PyExc_ValueError,
1459 "field elt is required for GeneratorExp");
1460 return NULL;
1461 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001462 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001464 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001465 return NULL;
1466 }
1467 p->kind = GeneratorExp_kind;
1468 p->v.GeneratorExp.elt = elt;
1469 p->v.GeneratorExp.generators = generators;
1470 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001471 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472 return p;
1473}
1474
1475expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001476Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477{
1478 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001479 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001480 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001481 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001482 return NULL;
1483 }
1484 p->kind = Yield_kind;
1485 p->v.Yield.value = value;
1486 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001487 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001488 return p;
1489}
1490
1491expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001492Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1493 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494{
1495 expr_ty p;
1496 if (!left) {
1497 PyErr_SetString(PyExc_ValueError,
1498 "field left is required for Compare");
1499 return NULL;
1500 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001501 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001502 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001503 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001504 return NULL;
1505 }
1506 p->kind = Compare_kind;
1507 p->v.Compare.left = left;
1508 p->v.Compare.ops = ops;
1509 p->v.Compare.comparators = comparators;
1510 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001511 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001512 return p;
1513}
1514
1515expr_ty
1516Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001517 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518{
1519 expr_ty p;
1520 if (!func) {
1521 PyErr_SetString(PyExc_ValueError,
1522 "field func is required for Call");
1523 return NULL;
1524 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001525 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001527 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001528 return NULL;
1529 }
1530 p->kind = Call_kind;
1531 p->v.Call.func = func;
1532 p->v.Call.args = args;
1533 p->v.Call.keywords = keywords;
1534 p->v.Call.starargs = starargs;
1535 p->v.Call.kwargs = kwargs;
1536 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001537 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 return p;
1539}
1540
1541expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001542Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001543{
1544 expr_ty p;
1545 if (!n) {
1546 PyErr_SetString(PyExc_ValueError,
1547 "field n is required for Num");
1548 return NULL;
1549 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001550 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001552 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001553 return NULL;
1554 }
1555 p->kind = Num_kind;
1556 p->v.Num.n = n;
1557 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001558 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001559 return p;
1560}
1561
1562expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001563Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001564{
1565 expr_ty p;
1566 if (!s) {
1567 PyErr_SetString(PyExc_ValueError,
1568 "field s is required for Str");
1569 return NULL;
1570 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001571 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001573 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001574 return NULL;
1575 }
1576 p->kind = Str_kind;
1577 p->v.Str.s = s;
1578 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001579 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001580 return p;
1581}
1582
1583expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001584Ellipsis(int lineno, int col_offset, PyArena *arena)
1585{
1586 expr_ty p;
1587 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1588 if (!p) {
1589 PyErr_NoMemory();
1590 return NULL;
1591 }
1592 p->kind = Ellipsis_kind;
1593 p->lineno = lineno;
1594 p->col_offset = col_offset;
1595 return p;
1596}
1597
1598expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001599Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1600 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001601{
1602 expr_ty p;
1603 if (!value) {
1604 PyErr_SetString(PyExc_ValueError,
1605 "field value is required for Attribute");
1606 return NULL;
1607 }
1608 if (!attr) {
1609 PyErr_SetString(PyExc_ValueError,
1610 "field attr is required for Attribute");
1611 return NULL;
1612 }
1613 if (!ctx) {
1614 PyErr_SetString(PyExc_ValueError,
1615 "field ctx is required for Attribute");
1616 return NULL;
1617 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001618 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001619 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001620 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001621 return NULL;
1622 }
1623 p->kind = Attribute_kind;
1624 p->v.Attribute.value = value;
1625 p->v.Attribute.attr = attr;
1626 p->v.Attribute.ctx = ctx;
1627 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001628 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001629 return p;
1630}
1631
1632expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001633Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1634 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001635{
1636 expr_ty p;
1637 if (!value) {
1638 PyErr_SetString(PyExc_ValueError,
1639 "field value is required for Subscript");
1640 return NULL;
1641 }
1642 if (!slice) {
1643 PyErr_SetString(PyExc_ValueError,
1644 "field slice is required for Subscript");
1645 return NULL;
1646 }
1647 if (!ctx) {
1648 PyErr_SetString(PyExc_ValueError,
1649 "field ctx is required for Subscript");
1650 return NULL;
1651 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001652 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001654 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001655 return NULL;
1656 }
1657 p->kind = Subscript_kind;
1658 p->v.Subscript.value = value;
1659 p->v.Subscript.slice = slice;
1660 p->v.Subscript.ctx = ctx;
1661 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001662 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001663 return p;
1664}
1665
1666expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001667Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1668 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669{
1670 expr_ty p;
1671 if (!id) {
1672 PyErr_SetString(PyExc_ValueError,
1673 "field id is required for Name");
1674 return NULL;
1675 }
1676 if (!ctx) {
1677 PyErr_SetString(PyExc_ValueError,
1678 "field ctx is required for Name");
1679 return NULL;
1680 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001681 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001682 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001683 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 return NULL;
1685 }
1686 p->kind = Name_kind;
1687 p->v.Name.id = id;
1688 p->v.Name.ctx = ctx;
1689 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001690 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001691 return p;
1692}
1693
1694expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001695List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1696 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697{
1698 expr_ty p;
1699 if (!ctx) {
1700 PyErr_SetString(PyExc_ValueError,
1701 "field ctx is required for List");
1702 return NULL;
1703 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001704 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001705 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001706 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001707 return NULL;
1708 }
1709 p->kind = List_kind;
1710 p->v.List.elts = elts;
1711 p->v.List.ctx = ctx;
1712 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001713 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001714 return p;
1715}
1716
1717expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001718Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1719 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720{
1721 expr_ty p;
1722 if (!ctx) {
1723 PyErr_SetString(PyExc_ValueError,
1724 "field ctx is required for Tuple");
1725 return NULL;
1726 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001727 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001728 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001729 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730 return NULL;
1731 }
1732 p->kind = Tuple_kind;
1733 p->v.Tuple.elts = elts;
1734 p->v.Tuple.ctx = ctx;
1735 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001736 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001737 return p;
1738}
1739
1740slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001741Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742{
1743 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001744 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001745 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001746 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001747 return NULL;
1748 }
1749 p->kind = Slice_kind;
1750 p->v.Slice.lower = lower;
1751 p->v.Slice.upper = upper;
1752 p->v.Slice.step = step;
1753 return p;
1754}
1755
1756slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001757ExtSlice(asdl_seq * dims, 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 = ExtSlice_kind;
1766 p->v.ExtSlice.dims = dims;
1767 return p;
1768}
1769
1770slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001771Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772{
1773 slice_ty p;
1774 if (!value) {
1775 PyErr_SetString(PyExc_ValueError,
1776 "field value is required for Index");
1777 return NULL;
1778 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001779 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001781 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001782 return NULL;
1783 }
1784 p->kind = Index_kind;
1785 p->v.Index.value = value;
1786 return p;
1787}
1788
1789comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001790comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791{
1792 comprehension_ty p;
1793 if (!target) {
1794 PyErr_SetString(PyExc_ValueError,
1795 "field target is required for comprehension");
1796 return NULL;
1797 }
1798 if (!iter) {
1799 PyErr_SetString(PyExc_ValueError,
1800 "field iter is required for comprehension");
1801 return NULL;
1802 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001803 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001804 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001805 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001806 return NULL;
1807 }
1808 p->target = target;
1809 p->iter = iter;
1810 p->ifs = ifs;
1811 return p;
1812}
1813
1814excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001815excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1816 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001817{
1818 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001819 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001820 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001821 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001822 return NULL;
1823 }
1824 p->type = type;
1825 p->name = name;
1826 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001827 p->lineno = lineno;
1828 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 return p;
1830}
1831
1832arguments_ty
Guido van Rossum4f72a782006-10-27 23:31:49 +00001833arguments(asdl_seq * args, identifier vararg, asdl_seq * kwonlyargs, identifier
1834 kwarg, asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835{
1836 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001837 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001838 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001839 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001840 return NULL;
1841 }
1842 p->args = args;
1843 p->vararg = vararg;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001844 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845 p->kwarg = kwarg;
1846 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001847 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 return p;
1849}
1850
1851keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001852keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853{
1854 keyword_ty p;
1855 if (!arg) {
1856 PyErr_SetString(PyExc_ValueError,
1857 "field arg is required for keyword");
1858 return NULL;
1859 }
1860 if (!value) {
1861 PyErr_SetString(PyExc_ValueError,
1862 "field value is required for keyword");
1863 return NULL;
1864 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001865 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001867 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868 return NULL;
1869 }
1870 p->arg = arg;
1871 p->value = value;
1872 return p;
1873}
1874
1875alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001876alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877{
1878 alias_ty p;
1879 if (!name) {
1880 PyErr_SetString(PyExc_ValueError,
1881 "field name is required for alias");
1882 return NULL;
1883 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001884 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001885 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001886 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001887 return NULL;
1888 }
1889 p->name = name;
1890 p->asname = asname;
1891 return p;
1892}
1893
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001894
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001895PyObject*
1896ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001897{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001898 mod_ty o = (mod_ty)_o;
1899 PyObject *result = NULL, *value = NULL;
1900 if (!o) {
1901 Py_INCREF(Py_None);
1902 return Py_None;
1903 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001904
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001905 switch (o->kind) {
1906 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001907 result = PyType_GenericNew(Module_type, NULL, NULL);
1908 if (!result) goto failed;
1909 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1910 if (!value) goto failed;
1911 if (PyObject_SetAttrString(result, "body", value) == -1)
1912 goto failed;
1913 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001914 break;
1915 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001916 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1917 if (!result) goto failed;
1918 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1919 if (!value) goto failed;
1920 if (PyObject_SetAttrString(result, "body", value) == -1)
1921 goto failed;
1922 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923 break;
1924 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001925 result = PyType_GenericNew(Expression_type, NULL, NULL);
1926 if (!result) goto failed;
1927 value = ast2obj_expr(o->v.Expression.body);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "body", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001932 break;
1933 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001934 result = PyType_GenericNew(Suite_type, NULL, NULL);
1935 if (!result) goto failed;
1936 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1937 if (!value) goto failed;
1938 if (PyObject_SetAttrString(result, "body", value) == -1)
1939 goto failed;
1940 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 break;
1942 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001943 return result;
1944failed:
1945 Py_XDECREF(value);
1946 Py_XDECREF(result);
1947 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948}
1949
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001950PyObject*
1951ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001952{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001953 stmt_ty o = (stmt_ty)_o;
1954 PyObject *result = NULL, *value = NULL;
1955 if (!o) {
1956 Py_INCREF(Py_None);
1957 return Py_None;
1958 }
1959
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001960 switch (o->kind) {
1961 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001962 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1963 if (!result) goto failed;
1964 value = ast2obj_identifier(o->v.FunctionDef.name);
1965 if (!value) goto failed;
1966 if (PyObject_SetAttrString(result, "name", value) == -1)
1967 goto failed;
1968 Py_DECREF(value);
1969 value = ast2obj_arguments(o->v.FunctionDef.args);
1970 if (!value) goto failed;
1971 if (PyObject_SetAttrString(result, "args", value) == -1)
1972 goto failed;
1973 Py_DECREF(value);
1974 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1975 if (!value) goto failed;
1976 if (PyObject_SetAttrString(result, "body", value) == -1)
1977 goto failed;
1978 Py_DECREF(value);
1979 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_identifier(o->v.ClassDef.name);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "name", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "bases", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
1998 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "body", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002003 break;
2004 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002005 result = PyType_GenericNew(Return_type, NULL, NULL);
2006 if (!result) goto failed;
2007 value = ast2obj_expr(o->v.Return.value);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "value", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002012 break;
2013 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002014 result = PyType_GenericNew(Delete_type, NULL, NULL);
2015 if (!result) goto failed;
2016 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2017 if (!value) goto failed;
2018 if (PyObject_SetAttrString(result, "targets", value) == -1)
2019 goto failed;
2020 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002021 break;
2022 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002023 result = PyType_GenericNew(Assign_type, NULL, NULL);
2024 if (!result) goto failed;
2025 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2026 if (!value) goto failed;
2027 if (PyObject_SetAttrString(result, "targets", value) == -1)
2028 goto failed;
2029 Py_DECREF(value);
2030 value = ast2obj_expr(o->v.Assign.value);
2031 if (!value) goto failed;
2032 if (PyObject_SetAttrString(result, "value", value) == -1)
2033 goto failed;
2034 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002035 break;
2036 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002037 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2038 if (!result) goto failed;
2039 value = ast2obj_expr(o->v.AugAssign.target);
2040 if (!value) goto failed;
2041 if (PyObject_SetAttrString(result, "target", value) == -1)
2042 goto failed;
2043 Py_DECREF(value);
2044 value = ast2obj_operator(o->v.AugAssign.op);
2045 if (!value) goto failed;
2046 if (PyObject_SetAttrString(result, "op", value) == -1)
2047 goto failed;
2048 Py_DECREF(value);
2049 value = ast2obj_expr(o->v.AugAssign.value);
2050 if (!value) goto failed;
2051 if (PyObject_SetAttrString(result, "value", value) == -1)
2052 goto failed;
2053 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002054 break;
2055 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002056 result = PyType_GenericNew(Print_type, NULL, NULL);
2057 if (!result) goto failed;
2058 value = ast2obj_expr(o->v.Print.dest);
2059 if (!value) goto failed;
2060 if (PyObject_SetAttrString(result, "dest", value) == -1)
2061 goto failed;
2062 Py_DECREF(value);
2063 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2064 if (!value) goto failed;
2065 if (PyObject_SetAttrString(result, "values", value) == -1)
2066 goto failed;
2067 Py_DECREF(value);
2068 value = ast2obj_bool(o->v.Print.nl);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "nl", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002073 break;
2074 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002075 result = PyType_GenericNew(For_type, NULL, NULL);
2076 if (!result) goto failed;
2077 value = ast2obj_expr(o->v.For.target);
2078 if (!value) goto failed;
2079 if (PyObject_SetAttrString(result, "target", value) == -1)
2080 goto failed;
2081 Py_DECREF(value);
2082 value = ast2obj_expr(o->v.For.iter);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "iter", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
2087 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "body", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002097 break;
2098 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002099 result = PyType_GenericNew(While_type, NULL, NULL);
2100 if (!result) goto failed;
2101 value = ast2obj_expr(o->v.While.test);
2102 if (!value) goto failed;
2103 if (PyObject_SetAttrString(result, "test", value) == -1)
2104 goto failed;
2105 Py_DECREF(value);
2106 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "body", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002116 break;
2117 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002118 result = PyType_GenericNew(If_type, NULL, NULL);
2119 if (!result) goto failed;
2120 value = ast2obj_expr(o->v.If.test);
2121 if (!value) goto failed;
2122 if (PyObject_SetAttrString(result, "test", value) == -1)
2123 goto failed;
2124 Py_DECREF(value);
2125 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "body", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002135 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002136 case With_kind:
2137 result = PyType_GenericNew(With_type, NULL, NULL);
2138 if (!result) goto failed;
2139 value = ast2obj_expr(o->v.With.context_expr);
2140 if (!value) goto failed;
2141 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2142 goto failed;
2143 Py_DECREF(value);
2144 value = ast2obj_expr(o->v.With.optional_vars);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2147 -1)
2148 goto failed;
2149 Py_DECREF(value);
2150 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2151 if (!value) goto failed;
2152 if (PyObject_SetAttrString(result, "body", value) == -1)
2153 goto failed;
2154 Py_DECREF(value);
2155 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002156 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002157 result = PyType_GenericNew(Raise_type, NULL, NULL);
2158 if (!result) goto failed;
2159 value = ast2obj_expr(o->v.Raise.type);
2160 if (!value) goto failed;
2161 if (PyObject_SetAttrString(result, "type", value) == -1)
2162 goto failed;
2163 Py_DECREF(value);
2164 value = ast2obj_expr(o->v.Raise.inst);
2165 if (!value) goto failed;
2166 if (PyObject_SetAttrString(result, "inst", value) == -1)
2167 goto failed;
2168 Py_DECREF(value);
2169 value = ast2obj_expr(o->v.Raise.tback);
2170 if (!value) goto failed;
2171 if (PyObject_SetAttrString(result, "tback", value) == -1)
2172 goto failed;
2173 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002174 break;
2175 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002176 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2177 if (!result) goto failed;
2178 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2179 if (!value) goto failed;
2180 if (PyObject_SetAttrString(result, "body", value) == -1)
2181 goto failed;
2182 Py_DECREF(value);
2183 value = ast2obj_list(o->v.TryExcept.handlers,
2184 ast2obj_excepthandler);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2187 goto failed;
2188 Py_DECREF(value);
2189 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002194 break;
2195 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002196 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2197 if (!result) goto failed;
2198 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2199 if (!value) goto failed;
2200 if (PyObject_SetAttrString(result, "body", value) == -1)
2201 goto failed;
2202 Py_DECREF(value);
2203 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2204 if (!value) goto failed;
2205 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2206 goto failed;
2207 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002208 break;
2209 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002210 result = PyType_GenericNew(Assert_type, NULL, NULL);
2211 if (!result) goto failed;
2212 value = ast2obj_expr(o->v.Assert.test);
2213 if (!value) goto failed;
2214 if (PyObject_SetAttrString(result, "test", value) == -1)
2215 goto failed;
2216 Py_DECREF(value);
2217 value = ast2obj_expr(o->v.Assert.msg);
2218 if (!value) goto failed;
2219 if (PyObject_SetAttrString(result, "msg", value) == -1)
2220 goto failed;
2221 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002222 break;
2223 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002224 result = PyType_GenericNew(Import_type, NULL, NULL);
2225 if (!result) goto failed;
2226 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2227 if (!value) goto failed;
2228 if (PyObject_SetAttrString(result, "names", value) == -1)
2229 goto failed;
2230 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002231 break;
2232 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002233 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2234 if (!result) goto failed;
2235 value = ast2obj_identifier(o->v.ImportFrom.module);
2236 if (!value) goto failed;
2237 if (PyObject_SetAttrString(result, "module", value) == -1)
2238 goto failed;
2239 Py_DECREF(value);
2240 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2241 if (!value) goto failed;
2242 if (PyObject_SetAttrString(result, "names", value) == -1)
2243 goto failed;
2244 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002245 value = ast2obj_int(o->v.ImportFrom.level);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "level", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002250 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002252 result = PyType_GenericNew(Global_type, NULL, NULL);
2253 if (!result) goto failed;
2254 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "names", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259 break;
2260 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002261 result = PyType_GenericNew(Expr_type, NULL, NULL);
2262 if (!result) goto failed;
2263 value = ast2obj_expr(o->v.Expr.value);
2264 if (!value) goto failed;
2265 if (PyObject_SetAttrString(result, "value", value) == -1)
2266 goto failed;
2267 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002268 break;
2269 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002270 result = PyType_GenericNew(Pass_type, NULL, NULL);
2271 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002272 break;
2273 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002274 result = PyType_GenericNew(Break_type, NULL, NULL);
2275 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276 break;
2277 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002278 result = PyType_GenericNew(Continue_type, NULL, NULL);
2279 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002280 break;
2281 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002282 value = ast2obj_int(o->lineno);
2283 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002284 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2285 goto failed;
2286 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002287 value = ast2obj_int(o->col_offset);
2288 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002289 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2290 goto failed;
2291 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002292 return result;
2293failed:
2294 Py_XDECREF(value);
2295 Py_XDECREF(result);
2296 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002297}
2298
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002299PyObject*
2300ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002301{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002302 expr_ty o = (expr_ty)_o;
2303 PyObject *result = NULL, *value = NULL;
2304 if (!o) {
2305 Py_INCREF(Py_None);
2306 return Py_None;
2307 }
2308
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002309 switch (o->kind) {
2310 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002311 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2312 if (!result) goto failed;
2313 value = ast2obj_boolop(o->v.BoolOp.op);
2314 if (!value) goto failed;
2315 if (PyObject_SetAttrString(result, "op", value) == -1)
2316 goto failed;
2317 Py_DECREF(value);
2318 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2319 if (!value) goto failed;
2320 if (PyObject_SetAttrString(result, "values", value) == -1)
2321 goto failed;
2322 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002323 break;
2324 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002325 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2326 if (!result) goto failed;
2327 value = ast2obj_expr(o->v.BinOp.left);
2328 if (!value) goto failed;
2329 if (PyObject_SetAttrString(result, "left", value) == -1)
2330 goto failed;
2331 Py_DECREF(value);
2332 value = ast2obj_operator(o->v.BinOp.op);
2333 if (!value) goto failed;
2334 if (PyObject_SetAttrString(result, "op", value) == -1)
2335 goto failed;
2336 Py_DECREF(value);
2337 value = ast2obj_expr(o->v.BinOp.right);
2338 if (!value) goto failed;
2339 if (PyObject_SetAttrString(result, "right", value) == -1)
2340 goto failed;
2341 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342 break;
2343 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2345 if (!result) goto failed;
2346 value = ast2obj_unaryop(o->v.UnaryOp.op);
2347 if (!value) goto failed;
2348 if (PyObject_SetAttrString(result, "op", value) == -1)
2349 goto failed;
2350 Py_DECREF(value);
2351 value = ast2obj_expr(o->v.UnaryOp.operand);
2352 if (!value) goto failed;
2353 if (PyObject_SetAttrString(result, "operand", value) == -1)
2354 goto failed;
2355 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002356 break;
2357 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2359 if (!result) goto failed;
2360 value = ast2obj_arguments(o->v.Lambda.args);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "args", value) == -1)
2363 goto failed;
2364 Py_DECREF(value);
2365 value = ast2obj_expr(o->v.Lambda.body);
2366 if (!value) goto failed;
2367 if (PyObject_SetAttrString(result, "body", value) == -1)
2368 goto failed;
2369 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002370 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002371 case IfExp_kind:
2372 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2373 if (!result) goto failed;
2374 value = ast2obj_expr(o->v.IfExp.test);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "test", value) == -1)
2377 goto failed;
2378 Py_DECREF(value);
2379 value = ast2obj_expr(o->v.IfExp.body);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "body", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 value = ast2obj_expr(o->v.IfExp.orelse);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
2389 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002390 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002391 result = PyType_GenericNew(Dict_type, NULL, NULL);
2392 if (!result) goto failed;
2393 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "keys", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
2398 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "values", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002403 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002404 case Set_kind:
2405 result = PyType_GenericNew(Set_type, NULL, NULL);
2406 if (!result) goto failed;
2407 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "elts", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
2412 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002413 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002414 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2415 if (!result) goto failed;
2416 value = ast2obj_expr(o->v.ListComp.elt);
2417 if (!value) goto failed;
2418 if (PyObject_SetAttrString(result, "elt", value) == -1)
2419 goto failed;
2420 Py_DECREF(value);
2421 value = ast2obj_list(o->v.ListComp.generators,
2422 ast2obj_comprehension);
2423 if (!value) goto failed;
2424 if (PyObject_SetAttrString(result, "generators", value) == -1)
2425 goto failed;
2426 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002427 break;
2428 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002429 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2430 if (!result) goto failed;
2431 value = ast2obj_expr(o->v.GeneratorExp.elt);
2432 if (!value) goto failed;
2433 if (PyObject_SetAttrString(result, "elt", value) == -1)
2434 goto failed;
2435 Py_DECREF(value);
2436 value = ast2obj_list(o->v.GeneratorExp.generators,
2437 ast2obj_comprehension);
2438 if (!value) goto failed;
2439 if (PyObject_SetAttrString(result, "generators", value) == -1)
2440 goto failed;
2441 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 break;
2443 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002444 result = PyType_GenericNew(Yield_type, NULL, NULL);
2445 if (!result) goto failed;
2446 value = ast2obj_expr(o->v.Yield.value);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "value", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002451 break;
2452 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002453 result = PyType_GenericNew(Compare_type, NULL, NULL);
2454 if (!result) goto failed;
2455 value = ast2obj_expr(o->v.Compare.left);
2456 if (!value) goto failed;
2457 if (PyObject_SetAttrString(result, "left", value) == -1)
2458 goto failed;
2459 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002460 {
2461 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2462 value = PyList_New(n);
2463 if (!value) goto failed;
2464 for(i = 0; i < n; i++)
2465 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2466 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002467 if (!value) goto failed;
2468 if (PyObject_SetAttrString(result, "ops", value) == -1)
2469 goto failed;
2470 Py_DECREF(value);
2471 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002476 break;
2477 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002478 result = PyType_GenericNew(Call_type, NULL, NULL);
2479 if (!result) goto failed;
2480 value = ast2obj_expr(o->v.Call.func);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "func", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
2485 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2486 if (!value) goto failed;
2487 if (PyObject_SetAttrString(result, "args", value) == -1)
2488 goto failed;
2489 Py_DECREF(value);
2490 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2491 if (!value) goto failed;
2492 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2493 goto failed;
2494 Py_DECREF(value);
2495 value = ast2obj_expr(o->v.Call.starargs);
2496 if (!value) goto failed;
2497 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2498 goto failed;
2499 Py_DECREF(value);
2500 value = ast2obj_expr(o->v.Call.kwargs);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002506 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Num_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_object(o->v.Num.n);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "n", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002514 break;
2515 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002516 result = PyType_GenericNew(Str_type, NULL, NULL);
2517 if (!result) goto failed;
2518 value = ast2obj_string(o->v.Str.s);
2519 if (!value) goto failed;
2520 if (PyObject_SetAttrString(result, "s", value) == -1)
2521 goto failed;
2522 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002523 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002524 case Ellipsis_kind:
2525 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2526 if (!result) goto failed;
2527 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002529 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2530 if (!result) goto failed;
2531 value = ast2obj_expr(o->v.Attribute.value);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "value", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_identifier(o->v.Attribute.attr);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "attr", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 value = ast2obj_expr_context(o->v.Attribute.ctx);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002546 break;
2547 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002548 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2549 if (!result) goto failed;
2550 value = ast2obj_expr(o->v.Subscript.value);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "value", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
2555 value = ast2obj_slice(o->v.Subscript.slice);
2556 if (!value) goto failed;
2557 if (PyObject_SetAttrString(result, "slice", value) == -1)
2558 goto failed;
2559 Py_DECREF(value);
2560 value = ast2obj_expr_context(o->v.Subscript.ctx);
2561 if (!value) goto failed;
2562 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2563 goto failed;
2564 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002565 break;
2566 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002567 result = PyType_GenericNew(Name_type, NULL, NULL);
2568 if (!result) goto failed;
2569 value = ast2obj_identifier(o->v.Name.id);
2570 if (!value) goto failed;
2571 if (PyObject_SetAttrString(result, "id", value) == -1)
2572 goto failed;
2573 Py_DECREF(value);
2574 value = ast2obj_expr_context(o->v.Name.ctx);
2575 if (!value) goto failed;
2576 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2577 goto failed;
2578 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002579 break;
2580 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002581 result = PyType_GenericNew(List_type, NULL, NULL);
2582 if (!result) goto failed;
2583 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2584 if (!value) goto failed;
2585 if (PyObject_SetAttrString(result, "elts", value) == -1)
2586 goto failed;
2587 Py_DECREF(value);
2588 value = ast2obj_expr_context(o->v.List.ctx);
2589 if (!value) goto failed;
2590 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2591 goto failed;
2592 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002593 break;
2594 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002595 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2596 if (!result) goto failed;
2597 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2598 if (!value) goto failed;
2599 if (PyObject_SetAttrString(result, "elts", value) == -1)
2600 goto failed;
2601 Py_DECREF(value);
2602 value = ast2obj_expr_context(o->v.Tuple.ctx);
2603 if (!value) goto failed;
2604 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2605 goto failed;
2606 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002607 break;
2608 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002609 value = ast2obj_int(o->lineno);
2610 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002611 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2612 goto failed;
2613 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002614 value = ast2obj_int(o->col_offset);
2615 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002616 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2617 goto failed;
2618 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002619 return result;
2620failed:
2621 Py_XDECREF(value);
2622 Py_XDECREF(result);
2623 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002624}
2625
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002626PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002627{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002628 switch(o) {
2629 case Load:
2630 Py_INCREF(Load_singleton);
2631 return Load_singleton;
2632 case Store:
2633 Py_INCREF(Store_singleton);
2634 return Store_singleton;
2635 case Del:
2636 Py_INCREF(Del_singleton);
2637 return Del_singleton;
2638 case AugLoad:
2639 Py_INCREF(AugLoad_singleton);
2640 return AugLoad_singleton;
2641 case AugStore:
2642 Py_INCREF(AugStore_singleton);
2643 return AugStore_singleton;
2644 case Param:
2645 Py_INCREF(Param_singleton);
2646 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002649}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002650PyObject*
2651ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002652{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002653 slice_ty o = (slice_ty)_o;
2654 PyObject *result = NULL, *value = NULL;
2655 if (!o) {
2656 Py_INCREF(Py_None);
2657 return Py_None;
2658 }
2659
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002660 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002661 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002662 result = PyType_GenericNew(Slice_type, NULL, NULL);
2663 if (!result) goto failed;
2664 value = ast2obj_expr(o->v.Slice.lower);
2665 if (!value) goto failed;
2666 if (PyObject_SetAttrString(result, "lower", value) == -1)
2667 goto failed;
2668 Py_DECREF(value);
2669 value = ast2obj_expr(o->v.Slice.upper);
2670 if (!value) goto failed;
2671 if (PyObject_SetAttrString(result, "upper", value) == -1)
2672 goto failed;
2673 Py_DECREF(value);
2674 value = ast2obj_expr(o->v.Slice.step);
2675 if (!value) goto failed;
2676 if (PyObject_SetAttrString(result, "step", value) == -1)
2677 goto failed;
2678 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002679 break;
2680 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002681 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2682 if (!result) goto failed;
2683 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2684 if (!value) goto failed;
2685 if (PyObject_SetAttrString(result, "dims", value) == -1)
2686 goto failed;
2687 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688 break;
2689 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002690 result = PyType_GenericNew(Index_type, NULL, NULL);
2691 if (!result) goto failed;
2692 value = ast2obj_expr(o->v.Index.value);
2693 if (!value) goto failed;
2694 if (PyObject_SetAttrString(result, "value", value) == -1)
2695 goto failed;
2696 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002697 break;
2698 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002699 return result;
2700failed:
2701 Py_XDECREF(value);
2702 Py_XDECREF(result);
2703 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002704}
2705
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002706PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002707{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002708 switch(o) {
2709 case And:
2710 Py_INCREF(And_singleton);
2711 return And_singleton;
2712 case Or:
2713 Py_INCREF(Or_singleton);
2714 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002716 return NULL; /* cannot happen */
2717}
2718PyObject* ast2obj_operator(operator_ty o)
2719{
2720 switch(o) {
2721 case Add:
2722 Py_INCREF(Add_singleton);
2723 return Add_singleton;
2724 case Sub:
2725 Py_INCREF(Sub_singleton);
2726 return Sub_singleton;
2727 case Mult:
2728 Py_INCREF(Mult_singleton);
2729 return Mult_singleton;
2730 case Div:
2731 Py_INCREF(Div_singleton);
2732 return Div_singleton;
2733 case Mod:
2734 Py_INCREF(Mod_singleton);
2735 return Mod_singleton;
2736 case Pow:
2737 Py_INCREF(Pow_singleton);
2738 return Pow_singleton;
2739 case LShift:
2740 Py_INCREF(LShift_singleton);
2741 return LShift_singleton;
2742 case RShift:
2743 Py_INCREF(RShift_singleton);
2744 return RShift_singleton;
2745 case BitOr:
2746 Py_INCREF(BitOr_singleton);
2747 return BitOr_singleton;
2748 case BitXor:
2749 Py_INCREF(BitXor_singleton);
2750 return BitXor_singleton;
2751 case BitAnd:
2752 Py_INCREF(BitAnd_singleton);
2753 return BitAnd_singleton;
2754 case FloorDiv:
2755 Py_INCREF(FloorDiv_singleton);
2756 return FloorDiv_singleton;
2757 }
2758 return NULL; /* cannot happen */
2759}
2760PyObject* ast2obj_unaryop(unaryop_ty o)
2761{
2762 switch(o) {
2763 case Invert:
2764 Py_INCREF(Invert_singleton);
2765 return Invert_singleton;
2766 case Not:
2767 Py_INCREF(Not_singleton);
2768 return Not_singleton;
2769 case UAdd:
2770 Py_INCREF(UAdd_singleton);
2771 return UAdd_singleton;
2772 case USub:
2773 Py_INCREF(USub_singleton);
2774 return USub_singleton;
2775 }
2776 return NULL; /* cannot happen */
2777}
2778PyObject* ast2obj_cmpop(cmpop_ty o)
2779{
2780 switch(o) {
2781 case Eq:
2782 Py_INCREF(Eq_singleton);
2783 return Eq_singleton;
2784 case NotEq:
2785 Py_INCREF(NotEq_singleton);
2786 return NotEq_singleton;
2787 case Lt:
2788 Py_INCREF(Lt_singleton);
2789 return Lt_singleton;
2790 case LtE:
2791 Py_INCREF(LtE_singleton);
2792 return LtE_singleton;
2793 case Gt:
2794 Py_INCREF(Gt_singleton);
2795 return Gt_singleton;
2796 case GtE:
2797 Py_INCREF(GtE_singleton);
2798 return GtE_singleton;
2799 case Is:
2800 Py_INCREF(Is_singleton);
2801 return Is_singleton;
2802 case IsNot:
2803 Py_INCREF(IsNot_singleton);
2804 return IsNot_singleton;
2805 case In:
2806 Py_INCREF(In_singleton);
2807 return In_singleton;
2808 case NotIn:
2809 Py_INCREF(NotIn_singleton);
2810 return NotIn_singleton;
2811 }
2812 return NULL; /* cannot happen */
2813}
2814PyObject*
2815ast2obj_comprehension(void* _o)
2816{
2817 comprehension_ty o = (comprehension_ty)_o;
2818 PyObject *result = NULL, *value = NULL;
2819 if (!o) {
2820 Py_INCREF(Py_None);
2821 return Py_None;
2822 }
2823
2824 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2825 if (!result) return NULL;
2826 value = ast2obj_expr(o->target);
2827 if (!value) goto failed;
2828 if (PyObject_SetAttrString(result, "target", value) == -1)
2829 goto failed;
2830 Py_DECREF(value);
2831 value = ast2obj_expr(o->iter);
2832 if (!value) goto failed;
2833 if (PyObject_SetAttrString(result, "iter", value) == -1)
2834 goto failed;
2835 Py_DECREF(value);
2836 value = ast2obj_list(o->ifs, ast2obj_expr);
2837 if (!value) goto failed;
2838 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2839 goto failed;
2840 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002841 return result;
2842failed:
2843 Py_XDECREF(value);
2844 Py_XDECREF(result);
2845 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002846}
2847
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002848PyObject*
2849ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002850{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002851 excepthandler_ty o = (excepthandler_ty)_o;
2852 PyObject *result = NULL, *value = NULL;
2853 if (!o) {
2854 Py_INCREF(Py_None);
2855 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002856 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002857
2858 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2859 if (!result) return NULL;
2860 value = ast2obj_expr(o->type);
2861 if (!value) goto failed;
2862 if (PyObject_SetAttrString(result, "type", value) == -1)
2863 goto failed;
2864 Py_DECREF(value);
2865 value = ast2obj_expr(o->name);
2866 if (!value) goto failed;
2867 if (PyObject_SetAttrString(result, "name", value) == -1)
2868 goto failed;
2869 Py_DECREF(value);
2870 value = ast2obj_list(o->body, ast2obj_stmt);
2871 if (!value) goto failed;
2872 if (PyObject_SetAttrString(result, "body", value) == -1)
2873 goto failed;
2874 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002875 value = ast2obj_int(o->lineno);
2876 if (!value) goto failed;
2877 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2878 goto failed;
2879 Py_DECREF(value);
2880 value = ast2obj_int(o->col_offset);
2881 if (!value) goto failed;
2882 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2883 goto failed;
2884 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002885 return result;
2886failed:
2887 Py_XDECREF(value);
2888 Py_XDECREF(result);
2889 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002890}
2891
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002892PyObject*
2893ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002894{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002895 arguments_ty o = (arguments_ty)_o;
2896 PyObject *result = NULL, *value = NULL;
2897 if (!o) {
2898 Py_INCREF(Py_None);
2899 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002900 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002901
2902 result = PyType_GenericNew(arguments_type, NULL, NULL);
2903 if (!result) return NULL;
2904 value = ast2obj_list(o->args, ast2obj_expr);
2905 if (!value) goto failed;
2906 if (PyObject_SetAttrString(result, "args", value) == -1)
2907 goto failed;
2908 Py_DECREF(value);
2909 value = ast2obj_identifier(o->vararg);
2910 if (!value) goto failed;
2911 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2912 goto failed;
2913 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002914 value = ast2obj_list(o->kwonlyargs, ast2obj_expr);
2915 if (!value) goto failed;
2916 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2917 goto failed;
2918 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002919 value = ast2obj_identifier(o->kwarg);
2920 if (!value) goto failed;
2921 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2922 goto failed;
2923 Py_DECREF(value);
2924 value = ast2obj_list(o->defaults, ast2obj_expr);
2925 if (!value) goto failed;
2926 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2927 goto failed;
2928 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002929 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2930 if (!value) goto failed;
2931 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2932 goto failed;
2933 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934 return result;
2935failed:
2936 Py_XDECREF(value);
2937 Py_XDECREF(result);
2938 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002939}
2940
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002941PyObject*
2942ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002943{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002944 keyword_ty o = (keyword_ty)_o;
2945 PyObject *result = NULL, *value = NULL;
2946 if (!o) {
2947 Py_INCREF(Py_None);
2948 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002949 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002950
2951 result = PyType_GenericNew(keyword_type, NULL, NULL);
2952 if (!result) return NULL;
2953 value = ast2obj_identifier(o->arg);
2954 if (!value) goto failed;
2955 if (PyObject_SetAttrString(result, "arg", value) == -1)
2956 goto failed;
2957 Py_DECREF(value);
2958 value = ast2obj_expr(o->value);
2959 if (!value) goto failed;
2960 if (PyObject_SetAttrString(result, "value", value) == -1)
2961 goto failed;
2962 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002963 return result;
2964failed:
2965 Py_XDECREF(value);
2966 Py_XDECREF(result);
2967 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002968}
2969
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002970PyObject*
2971ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002972{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002973 alias_ty o = (alias_ty)_o;
2974 PyObject *result = NULL, *value = NULL;
2975 if (!o) {
2976 Py_INCREF(Py_None);
2977 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002978 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002979
2980 result = PyType_GenericNew(alias_type, NULL, NULL);
2981 if (!result) return NULL;
2982 value = ast2obj_identifier(o->name);
2983 if (!value) goto failed;
2984 if (PyObject_SetAttrString(result, "name", value) == -1)
2985 goto failed;
2986 Py_DECREF(value);
2987 value = ast2obj_identifier(o->asname);
2988 if (!value) goto failed;
2989 if (PyObject_SetAttrString(result, "asname", value) == -1)
2990 goto failed;
2991 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002992 return result;
2993failed:
2994 Py_XDECREF(value);
2995 Py_XDECREF(result);
2996 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002997}
2998
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002999
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003000PyMODINIT_FUNC
3001init_ast(void)
3002{
3003 PyObject *m, *d;
3004 if (!init_types()) return;
3005 m = Py_InitModule3("_ast", NULL, NULL);
3006 if (!m) return;
3007 d = PyModule_GetDict(m);
3008 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3009 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3010 return;
Guido van Rossum4f72a782006-10-27 23:31:49 +00003011 if (PyModule_AddStringConstant(m, "__version__", "51773") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003012 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003013 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3014 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3015 return;
3016 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3017 < 0) return;
3018 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3019 0) return;
3020 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3021 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3022 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3023 < 0) return;
3024 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3025 return;
3026 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3027 return;
3028 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3029 return;
3030 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3031 return;
3032 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3033 0) return;
3034 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3035 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3036 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3037 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3038 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3040 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3041 0) return;
3042 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3043 0) return;
3044 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3045 return;
3046 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3047 return;
3048 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3049 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003050 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3051 return;
3052 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3053 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3054 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3055 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3056 return;
3057 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3058 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3059 return;
3060 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3061 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3062 return;
3063 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3066 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003067 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003068 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3069 return;
3070 if (PyDict_SetItemString(d, "GeneratorExp",
3071 (PyObject*)GeneratorExp_type) < 0) return;
3072 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3073 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3074 return;
3075 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003076 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003078 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3079 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003080 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3081 0) return;
3082 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3083 0) return;
3084 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3085 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3086 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3087 if (PyDict_SetItemString(d, "expr_context",
3088 (PyObject*)expr_context_type) < 0) return;
3089 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3090 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3092 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3093 return;
3094 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3095 return;
3096 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3097 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003098 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3099 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3100 return;
3101 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3102 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3103 return;
3104 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3105 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3106 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3107 return;
3108 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3109 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3110 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3111 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3112 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3114 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3115 return;
3116 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3117 return;
3118 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3119 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3120 return;
3121 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3122 return;
3123 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3124 return;
3125 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3126 return;
3127 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3128 return;
3129 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3130 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3131 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3132 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3133 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3134 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3135 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3136 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3138 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3139 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3140 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3141 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3142 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3143 if (PyDict_SetItemString(d, "comprehension",
3144 (PyObject*)comprehension_type) < 0) return;
3145 if (PyDict_SetItemString(d, "excepthandler",
3146 (PyObject*)excepthandler_type) < 0) return;
3147 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3148 0) return;
3149 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3150 return;
3151 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003152}
3153
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003154
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003155PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003156{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003157 init_types();
3158 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003159}
3160
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003161