blob: 0ecddb74c8f5a066feff38b76b4d72e3fa203025 [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",
336 "kwarg",
337 "defaults",
338};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000339static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000341static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342 "arg",
343 "value",
344};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000345static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000347static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348 "name",
349 "asname",
350};
351
352
353static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
354{
355 PyObject *fnames, *result;
356 int i;
357 if (num_fields) {
358 fnames = PyTuple_New(num_fields);
359 if (!fnames) return NULL;
360 } else {
361 fnames = Py_None;
362 Py_INCREF(Py_None);
363 }
364 for(i=0; i < num_fields; i++) {
365 PyObject *field = PyString_FromString(fields[i]);
366 if (!field) {
367 Py_DECREF(fnames);
368 return NULL;
369 }
370 PyTuple_SET_ITEM(fnames, i, field);
371 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000372 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000373 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000374 Py_DECREF(fnames);
375 return (PyTypeObject*)result;
376}
377
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000378static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
379{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000380 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000381 PyObject *s, *l = PyList_New(num_fields);
382 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000383 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000384 s = PyString_FromString(attrs[i]);
385 if (!s) {
386 Py_DECREF(l);
387 return 0;
388 }
389 PyList_SET_ITEM(l, i, s);
390 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000391 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
392 Py_DECREF(l);
393 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000394}
395
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000396static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
397{
398 int i, n = asdl_seq_LEN(seq);
399 PyObject *result = PyList_New(n);
400 PyObject *value;
401 if (!result)
402 return NULL;
403 for (i = 0; i < n; i++) {
404 value = func(asdl_seq_GET(seq, i));
405 if (!value) {
406 Py_DECREF(result);
407 return NULL;
408 }
409 PyList_SET_ITEM(result, i, value);
410 }
411 return result;
412}
413
414static PyObject* ast2obj_object(void *o)
415{
416 if (!o)
417 o = Py_None;
418 Py_INCREF((PyObject*)o);
419 return (PyObject*)o;
420}
421#define ast2obj_identifier ast2obj_object
422#define ast2obj_string ast2obj_object
423static PyObject* ast2obj_bool(bool b)
424{
425 return PyBool_FromLong(b);
426}
427
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000428static PyObject* ast2obj_int(bool b)
429{
430 return PyInt_FromLong(b);
431}
432
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000433static int init_types(void)
434{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000435 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000436 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000437 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
438 mod_type = make_type("mod", AST_type, NULL, 0);
439 if (!mod_type) return 0;
440 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000441 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000442 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443 Interactive_type = make_type("Interactive", mod_type,
444 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000445 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000446 Expression_type = make_type("Expression", mod_type, Expression_fields,
447 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000448 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000449 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000450 if (!Suite_type) return 0;
451 stmt_type = make_type("stmt", AST_type, NULL, 0);
452 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000453 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000454 FunctionDef_type = make_type("FunctionDef", stmt_type,
455 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000456 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000457 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000475 With_type = make_type("With", stmt_type, With_fields, 3);
476 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
482 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000489 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000490 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000495 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000497 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000499 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Continue_type) return 0;
501 expr_type = make_type("expr", AST_type, NULL, 0);
502 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000503 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000504 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000505 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000512 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000516 Set_type = make_type("Set", expr_type, Set_fields, 1);
517 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 GeneratorExp_type = make_type("GeneratorExp", expr_type,
521 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000523 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Str_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000533 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
534 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Tuple_type) return 0;
545 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
546 if (!expr_context_type) return 0;
547 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000548 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000552 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000556 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000560 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000564 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000568 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Param_singleton) return 0;
572 slice_type = make_type("slice", AST_type, NULL, 0);
573 if (!slice_type) return 0;
574 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000575 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Index_type) return 0;
581 boolop_type = make_type("boolop", AST_type, NULL, 0);
582 if (!boolop_type) return 0;
583 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000584 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000585 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000586 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000588 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000590 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Or_singleton) return 0;
592 operator_type = make_type("operator", AST_type, NULL, 0);
593 if (!operator_type) return 0;
594 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000595 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000597 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000599 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000601 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000615 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!FloorDiv_singleton) return 0;
643 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
644 if (!unaryop_type) return 0;
645 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000646 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000648 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000650 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!USub_singleton) return 0;
662 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
663 if (!cmpop_type) return 0;
664 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000665 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000667 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!NotIn_singleton) return 0;
705 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000706 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!comprehension_type) return 0;
708 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000709 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!excepthandler_type) return 0;
711 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
712 if (!arguments_type) return 0;
713 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
714 if (!keyword_type) return 0;
715 alias_type = make_type("alias", AST_type, alias_fields, 2);
716 if (!alias_type) return 0;
717 initialized = 1;
718 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000719}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000720
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000721mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000722Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000723{
724 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000725 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000726 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000727 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000728 return NULL;
729 }
730 p->kind = Module_kind;
731 p->v.Module.body = body;
732 return p;
733}
734
735mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000736Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000737{
738 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000739 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000740 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000741 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000742 return NULL;
743 }
744 p->kind = Interactive_kind;
745 p->v.Interactive.body = body;
746 return p;
747}
748
749mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000750Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000751{
752 mod_ty p;
753 if (!body) {
754 PyErr_SetString(PyExc_ValueError,
755 "field body is required for Expression");
756 return NULL;
757 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000758 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000760 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761 return NULL;
762 }
763 p->kind = Expression_kind;
764 p->v.Expression.body = body;
765 return p;
766}
767
768mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000769Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000770{
771 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000772 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000773 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000774 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 return NULL;
776 }
777 p->kind = Suite_kind;
778 p->v.Suite.body = body;
779 return p;
780}
781
782stmt_ty
783FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000784 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000785{
786 stmt_ty p;
787 if (!name) {
788 PyErr_SetString(PyExc_ValueError,
789 "field name is required for FunctionDef");
790 return NULL;
791 }
792 if (!args) {
793 PyErr_SetString(PyExc_ValueError,
794 "field args is required for FunctionDef");
795 return NULL;
796 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000797 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000798 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000799 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 return NULL;
801 }
802 p->kind = FunctionDef_kind;
803 p->v.FunctionDef.name = name;
804 p->v.FunctionDef.args = args;
805 p->v.FunctionDef.body = body;
806 p->v.FunctionDef.decorators = decorators;
807 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000808 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000809 return p;
810}
811
812stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000813ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
814 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000815{
816 stmt_ty p;
817 if (!name) {
818 PyErr_SetString(PyExc_ValueError,
819 "field name is required for ClassDef");
820 return NULL;
821 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000822 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000823 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000824 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 return NULL;
826 }
827 p->kind = ClassDef_kind;
828 p->v.ClassDef.name = name;
829 p->v.ClassDef.bases = bases;
830 p->v.ClassDef.body = body;
831 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000832 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000833 return p;
834}
835
836stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000837Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000838{
839 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000840 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000842 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 return NULL;
844 }
845 p->kind = Return_kind;
846 p->v.Return.value = value;
847 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000848 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 return p;
850}
851
852stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000853Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000854{
855 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000856 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000857 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000858 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 return NULL;
860 }
861 p->kind = Delete_kind;
862 p->v.Delete.targets = targets;
863 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000864 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 return p;
866}
867
868stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000869Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
870 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871{
872 stmt_ty p;
873 if (!value) {
874 PyErr_SetString(PyExc_ValueError,
875 "field value is required for Assign");
876 return NULL;
877 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000878 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000879 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000880 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881 return NULL;
882 }
883 p->kind = Assign_kind;
884 p->v.Assign.targets = targets;
885 p->v.Assign.value = value;
886 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000887 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000888 return p;
889}
890
891stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000892AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
893 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894{
895 stmt_ty p;
896 if (!target) {
897 PyErr_SetString(PyExc_ValueError,
898 "field target is required for AugAssign");
899 return NULL;
900 }
901 if (!op) {
902 PyErr_SetString(PyExc_ValueError,
903 "field op is required for AugAssign");
904 return NULL;
905 }
906 if (!value) {
907 PyErr_SetString(PyExc_ValueError,
908 "field value is required for AugAssign");
909 return NULL;
910 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000911 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000912 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000913 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 return NULL;
915 }
916 p->kind = AugAssign_kind;
917 p->v.AugAssign.target = target;
918 p->v.AugAssign.op = op;
919 p->v.AugAssign.value = value;
920 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000921 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000922 return p;
923}
924
925stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000926Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
927 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000928{
929 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000930 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000932 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000933 return NULL;
934 }
935 p->kind = Print_kind;
936 p->v.Print.dest = dest;
937 p->v.Print.values = values;
938 p->v.Print.nl = nl;
939 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000940 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941 return p;
942}
943
944stmt_ty
945For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000946 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000947{
948 stmt_ty p;
949 if (!target) {
950 PyErr_SetString(PyExc_ValueError,
951 "field target is required for For");
952 return NULL;
953 }
954 if (!iter) {
955 PyErr_SetString(PyExc_ValueError,
956 "field iter is required for For");
957 return NULL;
958 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000959 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000960 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000961 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000962 return NULL;
963 }
964 p->kind = For_kind;
965 p->v.For.target = target;
966 p->v.For.iter = iter;
967 p->v.For.body = body;
968 p->v.For.orelse = orelse;
969 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000970 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000971 return p;
972}
973
974stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000975While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
976 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977{
978 stmt_ty p;
979 if (!test) {
980 PyErr_SetString(PyExc_ValueError,
981 "field test is required for While");
982 return NULL;
983 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000984 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000986 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987 return NULL;
988 }
989 p->kind = While_kind;
990 p->v.While.test = test;
991 p->v.While.body = body;
992 p->v.While.orelse = orelse;
993 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000994 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000995 return p;
996}
997
998stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000999If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1000 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001{
1002 stmt_ty p;
1003 if (!test) {
1004 PyErr_SetString(PyExc_ValueError,
1005 "field test is required for If");
1006 return NULL;
1007 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001008 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001010 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001011 return NULL;
1012 }
1013 p->kind = If_kind;
1014 p->v.If.test = test;
1015 p->v.If.body = body;
1016 p->v.If.orelse = orelse;
1017 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001018 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001019 return p;
1020}
1021
1022stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001023With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001024 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025{
1026 stmt_ty p;
1027 if (!context_expr) {
1028 PyErr_SetString(PyExc_ValueError,
1029 "field context_expr is required for With");
1030 return NULL;
1031 }
1032 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1033 if (!p) {
1034 PyErr_NoMemory();
1035 return NULL;
1036 }
1037 p->kind = With_kind;
1038 p->v.With.context_expr = context_expr;
1039 p->v.With.optional_vars = optional_vars;
1040 p->v.With.body = body;
1041 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001042 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001043 return p;
1044}
1045
1046stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001047Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1048 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001049{
1050 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001051 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001052 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001053 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054 return NULL;
1055 }
1056 p->kind = Raise_kind;
1057 p->v.Raise.type = type;
1058 p->v.Raise.inst = inst;
1059 p->v.Raise.tback = tback;
1060 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001061 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 return p;
1063}
1064
1065stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001066TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001067 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068{
1069 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001070 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001072 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073 return NULL;
1074 }
1075 p->kind = TryExcept_kind;
1076 p->v.TryExcept.body = body;
1077 p->v.TryExcept.handlers = handlers;
1078 p->v.TryExcept.orelse = orelse;
1079 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001080 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081 return p;
1082}
1083
1084stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001085TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1086 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087{
1088 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001089 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001090 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001091 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092 return NULL;
1093 }
1094 p->kind = TryFinally_kind;
1095 p->v.TryFinally.body = body;
1096 p->v.TryFinally.finalbody = finalbody;
1097 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001098 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001099 return p;
1100}
1101
1102stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001103Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104{
1105 stmt_ty p;
1106 if (!test) {
1107 PyErr_SetString(PyExc_ValueError,
1108 "field test is required for Assert");
1109 return NULL;
1110 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001111 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001112 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001113 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001114 return NULL;
1115 }
1116 p->kind = Assert_kind;
1117 p->v.Assert.test = test;
1118 p->v.Assert.msg = msg;
1119 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001120 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001121 return p;
1122}
1123
1124stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001125Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001126{
1127 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001128 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001130 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 return NULL;
1132 }
1133 p->kind = Import_kind;
1134 p->v.Import.names = names;
1135 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001136 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 return p;
1138}
1139
1140stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001141ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1142 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001143{
1144 stmt_ty p;
1145 if (!module) {
1146 PyErr_SetString(PyExc_ValueError,
1147 "field module is required for ImportFrom");
1148 return NULL;
1149 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001150 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001152 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001153 return NULL;
1154 }
1155 p->kind = ImportFrom_kind;
1156 p->v.ImportFrom.module = module;
1157 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001158 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001160 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 return p;
1162}
1163
1164stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001165Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001166{
1167 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001168 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001170 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001171 return NULL;
1172 }
1173 p->kind = Global_kind;
1174 p->v.Global.names = names;
1175 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001176 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 return p;
1178}
1179
1180stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001181Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001182{
1183 stmt_ty p;
1184 if (!value) {
1185 PyErr_SetString(PyExc_ValueError,
1186 "field value is required for Expr");
1187 return NULL;
1188 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001189 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001191 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192 return NULL;
1193 }
1194 p->kind = Expr_kind;
1195 p->v.Expr.value = value;
1196 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001197 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001198 return p;
1199}
1200
1201stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001202Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203{
1204 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001205 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001207 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208 return NULL;
1209 }
1210 p->kind = Pass_kind;
1211 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001212 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001213 return p;
1214}
1215
1216stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001217Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218{
1219 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001220 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001221 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001222 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 return NULL;
1224 }
1225 p->kind = Break_kind;
1226 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001227 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001228 return p;
1229}
1230
1231stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001232Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001233{
1234 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001235 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001237 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001238 return NULL;
1239 }
1240 p->kind = Continue_kind;
1241 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001242 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001243 return p;
1244}
1245
1246expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001247BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1248 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249{
1250 expr_ty p;
1251 if (!op) {
1252 PyErr_SetString(PyExc_ValueError,
1253 "field op is required for BoolOp");
1254 return NULL;
1255 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001256 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001257 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001258 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259 return NULL;
1260 }
1261 p->kind = BoolOp_kind;
1262 p->v.BoolOp.op = op;
1263 p->v.BoolOp.values = values;
1264 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001265 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001266 return p;
1267}
1268
1269expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001270BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1271 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001272{
1273 expr_ty p;
1274 if (!left) {
1275 PyErr_SetString(PyExc_ValueError,
1276 "field left is required for BinOp");
1277 return NULL;
1278 }
1279 if (!op) {
1280 PyErr_SetString(PyExc_ValueError,
1281 "field op is required for BinOp");
1282 return NULL;
1283 }
1284 if (!right) {
1285 PyErr_SetString(PyExc_ValueError,
1286 "field right is required for BinOp");
1287 return NULL;
1288 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001289 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001291 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292 return NULL;
1293 }
1294 p->kind = BinOp_kind;
1295 p->v.BinOp.left = left;
1296 p->v.BinOp.op = op;
1297 p->v.BinOp.right = right;
1298 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001299 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001300 return p;
1301}
1302
1303expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001304UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1305 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001306{
1307 expr_ty p;
1308 if (!op) {
1309 PyErr_SetString(PyExc_ValueError,
1310 "field op is required for UnaryOp");
1311 return NULL;
1312 }
1313 if (!operand) {
1314 PyErr_SetString(PyExc_ValueError,
1315 "field operand is required for UnaryOp");
1316 return NULL;
1317 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001318 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001319 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001320 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001321 return NULL;
1322 }
1323 p->kind = UnaryOp_kind;
1324 p->v.UnaryOp.op = op;
1325 p->v.UnaryOp.operand = operand;
1326 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001327 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001328 return p;
1329}
1330
1331expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001332Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1333 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001334{
1335 expr_ty p;
1336 if (!args) {
1337 PyErr_SetString(PyExc_ValueError,
1338 "field args is required for Lambda");
1339 return NULL;
1340 }
1341 if (!body) {
1342 PyErr_SetString(PyExc_ValueError,
1343 "field body is required for Lambda");
1344 return NULL;
1345 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001346 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001347 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001348 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 return NULL;
1350 }
1351 p->kind = Lambda_kind;
1352 p->v.Lambda.args = args;
1353 p->v.Lambda.body = body;
1354 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001355 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001356 return p;
1357}
1358
1359expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001360IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1361 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001362{
1363 expr_ty p;
1364 if (!test) {
1365 PyErr_SetString(PyExc_ValueError,
1366 "field test is required for IfExp");
1367 return NULL;
1368 }
1369 if (!body) {
1370 PyErr_SetString(PyExc_ValueError,
1371 "field body is required for IfExp");
1372 return NULL;
1373 }
1374 if (!orelse) {
1375 PyErr_SetString(PyExc_ValueError,
1376 "field orelse is required for IfExp");
1377 return NULL;
1378 }
1379 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1380 if (!p) {
1381 PyErr_NoMemory();
1382 return NULL;
1383 }
1384 p->kind = IfExp_kind;
1385 p->v.IfExp.test = test;
1386 p->v.IfExp.body = body;
1387 p->v.IfExp.orelse = orelse;
1388 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001389 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001390 return p;
1391}
1392
1393expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001394Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1395 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001396{
1397 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001398 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001399 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001400 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001401 return NULL;
1402 }
1403 p->kind = Dict_kind;
1404 p->v.Dict.keys = keys;
1405 p->v.Dict.values = values;
1406 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001407 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001408 return p;
1409}
1410
1411expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001412Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1413{
1414 expr_ty p;
1415 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1416 if (!p) {
1417 PyErr_NoMemory();
1418 return NULL;
1419 }
1420 p->kind = Set_kind;
1421 p->v.Set.elts = elts;
1422 p->lineno = lineno;
1423 p->col_offset = col_offset;
1424 return p;
1425}
1426
1427expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001428ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1429 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001430{
1431 expr_ty p;
1432 if (!elt) {
1433 PyErr_SetString(PyExc_ValueError,
1434 "field elt is required for ListComp");
1435 return NULL;
1436 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001437 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001438 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001439 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440 return NULL;
1441 }
1442 p->kind = ListComp_kind;
1443 p->v.ListComp.elt = elt;
1444 p->v.ListComp.generators = generators;
1445 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001446 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001447 return p;
1448}
1449
1450expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001451GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1452 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001453{
1454 expr_ty p;
1455 if (!elt) {
1456 PyErr_SetString(PyExc_ValueError,
1457 "field elt is required for GeneratorExp");
1458 return NULL;
1459 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001460 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001461 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001462 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 return NULL;
1464 }
1465 p->kind = GeneratorExp_kind;
1466 p->v.GeneratorExp.elt = elt;
1467 p->v.GeneratorExp.generators = generators;
1468 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001469 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001470 return p;
1471}
1472
1473expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001474Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475{
1476 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001477 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001478 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001479 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001480 return NULL;
1481 }
1482 p->kind = Yield_kind;
1483 p->v.Yield.value = value;
1484 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001485 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001486 return p;
1487}
1488
1489expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001490Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1491 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492{
1493 expr_ty p;
1494 if (!left) {
1495 PyErr_SetString(PyExc_ValueError,
1496 "field left is required for Compare");
1497 return NULL;
1498 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001499 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001501 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001502 return NULL;
1503 }
1504 p->kind = Compare_kind;
1505 p->v.Compare.left = left;
1506 p->v.Compare.ops = ops;
1507 p->v.Compare.comparators = comparators;
1508 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001509 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 return p;
1511}
1512
1513expr_ty
1514Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001515 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516{
1517 expr_ty p;
1518 if (!func) {
1519 PyErr_SetString(PyExc_ValueError,
1520 "field func is required for Call");
1521 return NULL;
1522 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001523 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001525 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 return NULL;
1527 }
1528 p->kind = Call_kind;
1529 p->v.Call.func = func;
1530 p->v.Call.args = args;
1531 p->v.Call.keywords = keywords;
1532 p->v.Call.starargs = starargs;
1533 p->v.Call.kwargs = kwargs;
1534 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001535 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001536 return p;
1537}
1538
1539expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001540Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001541{
1542 expr_ty p;
1543 if (!n) {
1544 PyErr_SetString(PyExc_ValueError,
1545 "field n is required for Num");
1546 return NULL;
1547 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001548 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001550 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551 return NULL;
1552 }
1553 p->kind = Num_kind;
1554 p->v.Num.n = n;
1555 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001556 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001557 return p;
1558}
1559
1560expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001561Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001562{
1563 expr_ty p;
1564 if (!s) {
1565 PyErr_SetString(PyExc_ValueError,
1566 "field s is required for Str");
1567 return NULL;
1568 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001569 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001570 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001571 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572 return NULL;
1573 }
1574 p->kind = Str_kind;
1575 p->v.Str.s = s;
1576 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001577 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001578 return p;
1579}
1580
1581expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001582Ellipsis(int lineno, int col_offset, PyArena *arena)
1583{
1584 expr_ty p;
1585 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1586 if (!p) {
1587 PyErr_NoMemory();
1588 return NULL;
1589 }
1590 p->kind = Ellipsis_kind;
1591 p->lineno = lineno;
1592 p->col_offset = col_offset;
1593 return p;
1594}
1595
1596expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001597Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1598 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001599{
1600 expr_ty p;
1601 if (!value) {
1602 PyErr_SetString(PyExc_ValueError,
1603 "field value is required for Attribute");
1604 return NULL;
1605 }
1606 if (!attr) {
1607 PyErr_SetString(PyExc_ValueError,
1608 "field attr is required for Attribute");
1609 return NULL;
1610 }
1611 if (!ctx) {
1612 PyErr_SetString(PyExc_ValueError,
1613 "field ctx is required for Attribute");
1614 return NULL;
1615 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001616 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001617 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001618 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001619 return NULL;
1620 }
1621 p->kind = Attribute_kind;
1622 p->v.Attribute.value = value;
1623 p->v.Attribute.attr = attr;
1624 p->v.Attribute.ctx = ctx;
1625 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001626 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 return p;
1628}
1629
1630expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001631Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1632 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001633{
1634 expr_ty p;
1635 if (!value) {
1636 PyErr_SetString(PyExc_ValueError,
1637 "field value is required for Subscript");
1638 return NULL;
1639 }
1640 if (!slice) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field slice is required for Subscript");
1643 return NULL;
1644 }
1645 if (!ctx) {
1646 PyErr_SetString(PyExc_ValueError,
1647 "field ctx is required for Subscript");
1648 return NULL;
1649 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001650 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001651 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001652 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 return NULL;
1654 }
1655 p->kind = Subscript_kind;
1656 p->v.Subscript.value = value;
1657 p->v.Subscript.slice = slice;
1658 p->v.Subscript.ctx = ctx;
1659 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001660 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001661 return p;
1662}
1663
1664expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001665Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1666 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001667{
1668 expr_ty p;
1669 if (!id) {
1670 PyErr_SetString(PyExc_ValueError,
1671 "field id is required for Name");
1672 return NULL;
1673 }
1674 if (!ctx) {
1675 PyErr_SetString(PyExc_ValueError,
1676 "field ctx is required for Name");
1677 return NULL;
1678 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001679 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001680 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001681 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001682 return NULL;
1683 }
1684 p->kind = Name_kind;
1685 p->v.Name.id = id;
1686 p->v.Name.ctx = ctx;
1687 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001688 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001689 return p;
1690}
1691
1692expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001693List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1694 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001695{
1696 expr_ty p;
1697 if (!ctx) {
1698 PyErr_SetString(PyExc_ValueError,
1699 "field ctx is required for List");
1700 return NULL;
1701 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001702 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001704 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001705 return NULL;
1706 }
1707 p->kind = List_kind;
1708 p->v.List.elts = elts;
1709 p->v.List.ctx = ctx;
1710 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001711 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001712 return p;
1713}
1714
1715expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001716Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1717 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001718{
1719 expr_ty p;
1720 if (!ctx) {
1721 PyErr_SetString(PyExc_ValueError,
1722 "field ctx is required for Tuple");
1723 return NULL;
1724 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001725 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001727 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001728 return NULL;
1729 }
1730 p->kind = Tuple_kind;
1731 p->v.Tuple.elts = elts;
1732 p->v.Tuple.ctx = ctx;
1733 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001734 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001735 return p;
1736}
1737
1738slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001739Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740{
1741 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001742 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001743 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001744 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001745 return NULL;
1746 }
1747 p->kind = Slice_kind;
1748 p->v.Slice.lower = lower;
1749 p->v.Slice.upper = upper;
1750 p->v.Slice.step = step;
1751 return p;
1752}
1753
1754slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001755ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756{
1757 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001758 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001759 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001760 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 return NULL;
1762 }
1763 p->kind = ExtSlice_kind;
1764 p->v.ExtSlice.dims = dims;
1765 return p;
1766}
1767
1768slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001769Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770{
1771 slice_ty p;
1772 if (!value) {
1773 PyErr_SetString(PyExc_ValueError,
1774 "field value is required for Index");
1775 return NULL;
1776 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001779 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 return NULL;
1781 }
1782 p->kind = Index_kind;
1783 p->v.Index.value = value;
1784 return p;
1785}
1786
1787comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001788comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001789{
1790 comprehension_ty p;
1791 if (!target) {
1792 PyErr_SetString(PyExc_ValueError,
1793 "field target is required for comprehension");
1794 return NULL;
1795 }
1796 if (!iter) {
1797 PyErr_SetString(PyExc_ValueError,
1798 "field iter is required for comprehension");
1799 return NULL;
1800 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001801 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001802 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001803 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001804 return NULL;
1805 }
1806 p->target = target;
1807 p->iter = iter;
1808 p->ifs = ifs;
1809 return p;
1810}
1811
1812excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001813excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1814 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815{
1816 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001817 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001818 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001819 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001820 return NULL;
1821 }
1822 p->type = type;
1823 p->name = name;
1824 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001825 p->lineno = lineno;
1826 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001827 return p;
1828}
1829
1830arguments_ty
1831arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001832 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833{
1834 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001835 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001836 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001837 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001838 return NULL;
1839 }
1840 p->args = args;
1841 p->vararg = vararg;
1842 p->kwarg = kwarg;
1843 p->defaults = defaults;
1844 return p;
1845}
1846
1847keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001848keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001849{
1850 keyword_ty p;
1851 if (!arg) {
1852 PyErr_SetString(PyExc_ValueError,
1853 "field arg is required for keyword");
1854 return NULL;
1855 }
1856 if (!value) {
1857 PyErr_SetString(PyExc_ValueError,
1858 "field value is required for keyword");
1859 return NULL;
1860 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001861 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001863 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864 return NULL;
1865 }
1866 p->arg = arg;
1867 p->value = value;
1868 return p;
1869}
1870
1871alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001872alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001873{
1874 alias_ty p;
1875 if (!name) {
1876 PyErr_SetString(PyExc_ValueError,
1877 "field name is required for alias");
1878 return NULL;
1879 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001880 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001882 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001883 return NULL;
1884 }
1885 p->name = name;
1886 p->asname = asname;
1887 return p;
1888}
1889
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001890
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001891PyObject*
1892ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001893{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001894 mod_ty o = (mod_ty)_o;
1895 PyObject *result = NULL, *value = NULL;
1896 if (!o) {
1897 Py_INCREF(Py_None);
1898 return Py_None;
1899 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001900
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001901 switch (o->kind) {
1902 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001903 result = PyType_GenericNew(Module_type, NULL, NULL);
1904 if (!result) goto failed;
1905 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1906 if (!value) goto failed;
1907 if (PyObject_SetAttrString(result, "body", value) == -1)
1908 goto failed;
1909 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001910 break;
1911 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001912 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1913 if (!result) goto failed;
1914 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1915 if (!value) goto failed;
1916 if (PyObject_SetAttrString(result, "body", value) == -1)
1917 goto failed;
1918 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001919 break;
1920 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001921 result = PyType_GenericNew(Expression_type, NULL, NULL);
1922 if (!result) goto failed;
1923 value = ast2obj_expr(o->v.Expression.body);
1924 if (!value) goto failed;
1925 if (PyObject_SetAttrString(result, "body", value) == -1)
1926 goto failed;
1927 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001928 break;
1929 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001930 result = PyType_GenericNew(Suite_type, NULL, NULL);
1931 if (!result) goto failed;
1932 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1933 if (!value) goto failed;
1934 if (PyObject_SetAttrString(result, "body", value) == -1)
1935 goto failed;
1936 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001937 break;
1938 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001939 return result;
1940failed:
1941 Py_XDECREF(value);
1942 Py_XDECREF(result);
1943 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001944}
1945
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001946PyObject*
1947ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001949 stmt_ty o = (stmt_ty)_o;
1950 PyObject *result = NULL, *value = NULL;
1951 if (!o) {
1952 Py_INCREF(Py_None);
1953 return Py_None;
1954 }
1955
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001956 switch (o->kind) {
1957 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001958 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1959 if (!result) goto failed;
1960 value = ast2obj_identifier(o->v.FunctionDef.name);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "name", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
1965 value = ast2obj_arguments(o->v.FunctionDef.args);
1966 if (!value) goto failed;
1967 if (PyObject_SetAttrString(result, "args", value) == -1)
1968 goto failed;
1969 Py_DECREF(value);
1970 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "body", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
1975 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1976 if (!value) goto failed;
1977 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1978 goto failed;
1979 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001980 break;
1981 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001982 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1983 if (!result) goto failed;
1984 value = ast2obj_identifier(o->v.ClassDef.name);
1985 if (!value) goto failed;
1986 if (PyObject_SetAttrString(result, "name", value) == -1)
1987 goto failed;
1988 Py_DECREF(value);
1989 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1990 if (!value) goto failed;
1991 if (PyObject_SetAttrString(result, "bases", value) == -1)
1992 goto failed;
1993 Py_DECREF(value);
1994 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1995 if (!value) goto failed;
1996 if (PyObject_SetAttrString(result, "body", value) == -1)
1997 goto failed;
1998 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001999 break;
2000 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002001 result = PyType_GenericNew(Return_type, NULL, NULL);
2002 if (!result) goto failed;
2003 value = ast2obj_expr(o->v.Return.value);
2004 if (!value) goto failed;
2005 if (PyObject_SetAttrString(result, "value", value) == -1)
2006 goto failed;
2007 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002008 break;
2009 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002010 result = PyType_GenericNew(Delete_type, NULL, NULL);
2011 if (!result) goto failed;
2012 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "targets", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002017 break;
2018 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002019 result = PyType_GenericNew(Assign_type, NULL, NULL);
2020 if (!result) goto failed;
2021 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "targets", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
2026 value = ast2obj_expr(o->v.Assign.value);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "value", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002031 break;
2032 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002033 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2034 if (!result) goto failed;
2035 value = ast2obj_expr(o->v.AugAssign.target);
2036 if (!value) goto failed;
2037 if (PyObject_SetAttrString(result, "target", value) == -1)
2038 goto failed;
2039 Py_DECREF(value);
2040 value = ast2obj_operator(o->v.AugAssign.op);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "op", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
2045 value = ast2obj_expr(o->v.AugAssign.value);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "value", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002050 break;
2051 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002052 result = PyType_GenericNew(Print_type, NULL, NULL);
2053 if (!result) goto failed;
2054 value = ast2obj_expr(o->v.Print.dest);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "dest", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
2059 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "values", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
2064 value = ast2obj_bool(o->v.Print.nl);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "nl", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002069 break;
2070 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002071 result = PyType_GenericNew(For_type, NULL, NULL);
2072 if (!result) goto failed;
2073 value = ast2obj_expr(o->v.For.target);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "target", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
2078 value = ast2obj_expr(o->v.For.iter);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "iter", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
2083 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2084 if (!value) goto failed;
2085 if (PyObject_SetAttrString(result, "body", value) == -1)
2086 goto failed;
2087 Py_DECREF(value);
2088 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002093 break;
2094 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002095 result = PyType_GenericNew(While_type, NULL, NULL);
2096 if (!result) goto failed;
2097 value = ast2obj_expr(o->v.While.test);
2098 if (!value) goto failed;
2099 if (PyObject_SetAttrString(result, "test", value) == -1)
2100 goto failed;
2101 Py_DECREF(value);
2102 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2103 if (!value) goto failed;
2104 if (PyObject_SetAttrString(result, "body", value) == -1)
2105 goto failed;
2106 Py_DECREF(value);
2107 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2110 goto failed;
2111 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002112 break;
2113 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002114 result = PyType_GenericNew(If_type, NULL, NULL);
2115 if (!result) goto failed;
2116 value = ast2obj_expr(o->v.If.test);
2117 if (!value) goto failed;
2118 if (PyObject_SetAttrString(result, "test", value) == -1)
2119 goto failed;
2120 Py_DECREF(value);
2121 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "body", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
2126 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2127 if (!value) goto failed;
2128 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2129 goto failed;
2130 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002131 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002132 case With_kind:
2133 result = PyType_GenericNew(With_type, NULL, NULL);
2134 if (!result) goto failed;
2135 value = ast2obj_expr(o->v.With.context_expr);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
2140 value = ast2obj_expr(o->v.With.optional_vars);
2141 if (!value) goto failed;
2142 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2143 -1)
2144 goto failed;
2145 Py_DECREF(value);
2146 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2147 if (!value) goto failed;
2148 if (PyObject_SetAttrString(result, "body", value) == -1)
2149 goto failed;
2150 Py_DECREF(value);
2151 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002152 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002153 result = PyType_GenericNew(Raise_type, NULL, NULL);
2154 if (!result) goto failed;
2155 value = ast2obj_expr(o->v.Raise.type);
2156 if (!value) goto failed;
2157 if (PyObject_SetAttrString(result, "type", value) == -1)
2158 goto failed;
2159 Py_DECREF(value);
2160 value = ast2obj_expr(o->v.Raise.inst);
2161 if (!value) goto failed;
2162 if (PyObject_SetAttrString(result, "inst", value) == -1)
2163 goto failed;
2164 Py_DECREF(value);
2165 value = ast2obj_expr(o->v.Raise.tback);
2166 if (!value) goto failed;
2167 if (PyObject_SetAttrString(result, "tback", value) == -1)
2168 goto failed;
2169 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002170 break;
2171 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002172 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2173 if (!result) goto failed;
2174 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2175 if (!value) goto failed;
2176 if (PyObject_SetAttrString(result, "body", value) == -1)
2177 goto failed;
2178 Py_DECREF(value);
2179 value = ast2obj_list(o->v.TryExcept.handlers,
2180 ast2obj_excepthandler);
2181 if (!value) goto failed;
2182 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2183 goto failed;
2184 Py_DECREF(value);
2185 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002190 break;
2191 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002192 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2193 if (!result) goto failed;
2194 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "body", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2200 if (!value) goto failed;
2201 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2202 goto failed;
2203 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002204 break;
2205 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002206 result = PyType_GenericNew(Assert_type, NULL, NULL);
2207 if (!result) goto failed;
2208 value = ast2obj_expr(o->v.Assert.test);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "test", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
2213 value = ast2obj_expr(o->v.Assert.msg);
2214 if (!value) goto failed;
2215 if (PyObject_SetAttrString(result, "msg", value) == -1)
2216 goto failed;
2217 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218 break;
2219 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002220 result = PyType_GenericNew(Import_type, NULL, NULL);
2221 if (!result) goto failed;
2222 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "names", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002227 break;
2228 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002229 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2230 if (!result) goto failed;
2231 value = ast2obj_identifier(o->v.ImportFrom.module);
2232 if (!value) goto failed;
2233 if (PyObject_SetAttrString(result, "module", value) == -1)
2234 goto failed;
2235 Py_DECREF(value);
2236 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "names", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002241 value = ast2obj_int(o->v.ImportFrom.level);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "level", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002246 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002247 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002248 result = PyType_GenericNew(Global_type, NULL, NULL);
2249 if (!result) goto failed;
2250 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2251 if (!value) goto failed;
2252 if (PyObject_SetAttrString(result, "names", value) == -1)
2253 goto failed;
2254 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002255 break;
2256 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002257 result = PyType_GenericNew(Expr_type, NULL, NULL);
2258 if (!result) goto failed;
2259 value = ast2obj_expr(o->v.Expr.value);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "value", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002264 break;
2265 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002266 result = PyType_GenericNew(Pass_type, NULL, NULL);
2267 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002268 break;
2269 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002270 result = PyType_GenericNew(Break_type, NULL, NULL);
2271 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002272 break;
2273 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002274 result = PyType_GenericNew(Continue_type, NULL, NULL);
2275 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276 break;
2277 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002278 value = ast2obj_int(o->lineno);
2279 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002280 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2281 goto failed;
2282 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002283 value = ast2obj_int(o->col_offset);
2284 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002285 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2286 goto failed;
2287 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002288 return result;
2289failed:
2290 Py_XDECREF(value);
2291 Py_XDECREF(result);
2292 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002293}
2294
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002295PyObject*
2296ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002297{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002298 expr_ty o = (expr_ty)_o;
2299 PyObject *result = NULL, *value = NULL;
2300 if (!o) {
2301 Py_INCREF(Py_None);
2302 return Py_None;
2303 }
2304
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002305 switch (o->kind) {
2306 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002307 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2308 if (!result) goto failed;
2309 value = ast2obj_boolop(o->v.BoolOp.op);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "op", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
2314 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2315 if (!value) goto failed;
2316 if (PyObject_SetAttrString(result, "values", value) == -1)
2317 goto failed;
2318 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319 break;
2320 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002321 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2322 if (!result) goto failed;
2323 value = ast2obj_expr(o->v.BinOp.left);
2324 if (!value) goto failed;
2325 if (PyObject_SetAttrString(result, "left", value) == -1)
2326 goto failed;
2327 Py_DECREF(value);
2328 value = ast2obj_operator(o->v.BinOp.op);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "op", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
2333 value = ast2obj_expr(o->v.BinOp.right);
2334 if (!value) goto failed;
2335 if (PyObject_SetAttrString(result, "right", value) == -1)
2336 goto failed;
2337 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002338 break;
2339 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002340 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2341 if (!result) goto failed;
2342 value = ast2obj_unaryop(o->v.UnaryOp.op);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "op", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
2347 value = ast2obj_expr(o->v.UnaryOp.operand);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "operand", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002352 break;
2353 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_arguments(o->v.Lambda.args);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "args", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_expr(o->v.Lambda.body);
2362 if (!value) goto failed;
2363 if (PyObject_SetAttrString(result, "body", value) == -1)
2364 goto failed;
2365 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002366 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002367 case IfExp_kind:
2368 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2369 if (!result) goto failed;
2370 value = ast2obj_expr(o->v.IfExp.test);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "test", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
2375 value = ast2obj_expr(o->v.IfExp.body);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "body", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_expr(o->v.IfExp.orelse);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
2385 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002386 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002387 result = PyType_GenericNew(Dict_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "keys", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
2394 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "values", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002400 case Set_kind:
2401 result = PyType_GenericNew(Set_type, NULL, NULL);
2402 if (!result) goto failed;
2403 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "elts", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
2408 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002409 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_expr(o->v.ListComp.elt);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "elt", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 value = ast2obj_list(o->v.ListComp.generators,
2418 ast2obj_comprehension);
2419 if (!value) goto failed;
2420 if (PyObject_SetAttrString(result, "generators", value) == -1)
2421 goto failed;
2422 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002423 break;
2424 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002425 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2426 if (!result) goto failed;
2427 value = ast2obj_expr(o->v.GeneratorExp.elt);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "elt", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
2432 value = ast2obj_list(o->v.GeneratorExp.generators,
2433 ast2obj_comprehension);
2434 if (!value) goto failed;
2435 if (PyObject_SetAttrString(result, "generators", value) == -1)
2436 goto failed;
2437 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002438 break;
2439 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002440 result = PyType_GenericNew(Yield_type, NULL, NULL);
2441 if (!result) goto failed;
2442 value = ast2obj_expr(o->v.Yield.value);
2443 if (!value) goto failed;
2444 if (PyObject_SetAttrString(result, "value", value) == -1)
2445 goto failed;
2446 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002447 break;
2448 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002449 result = PyType_GenericNew(Compare_type, NULL, NULL);
2450 if (!result) goto failed;
2451 value = ast2obj_expr(o->v.Compare.left);
2452 if (!value) goto failed;
2453 if (PyObject_SetAttrString(result, "left", value) == -1)
2454 goto failed;
2455 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002456 {
2457 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2458 value = PyList_New(n);
2459 if (!value) goto failed;
2460 for(i = 0; i < n; i++)
2461 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2462 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002463 if (!value) goto failed;
2464 if (PyObject_SetAttrString(result, "ops", value) == -1)
2465 goto failed;
2466 Py_DECREF(value);
2467 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002472 break;
2473 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002474 result = PyType_GenericNew(Call_type, NULL, NULL);
2475 if (!result) goto failed;
2476 value = ast2obj_expr(o->v.Call.func);
2477 if (!value) goto failed;
2478 if (PyObject_SetAttrString(result, "func", value) == -1)
2479 goto failed;
2480 Py_DECREF(value);
2481 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "args", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2487 if (!value) goto failed;
2488 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2489 goto failed;
2490 Py_DECREF(value);
2491 value = ast2obj_expr(o->v.Call.starargs);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
2496 value = ast2obj_expr(o->v.Call.kwargs);
2497 if (!value) goto failed;
2498 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2499 goto failed;
2500 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002501 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002502 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002503 result = PyType_GenericNew(Num_type, NULL, NULL);
2504 if (!result) goto failed;
2505 value = ast2obj_object(o->v.Num.n);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "n", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002510 break;
2511 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002512 result = PyType_GenericNew(Str_type, NULL, NULL);
2513 if (!result) goto failed;
2514 value = ast2obj_string(o->v.Str.s);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "s", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002519 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002520 case Ellipsis_kind:
2521 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2522 if (!result) goto failed;
2523 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002524 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002525 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2526 if (!result) goto failed;
2527 value = ast2obj_expr(o->v.Attribute.value);
2528 if (!value) goto failed;
2529 if (PyObject_SetAttrString(result, "value", value) == -1)
2530 goto failed;
2531 Py_DECREF(value);
2532 value = ast2obj_identifier(o->v.Attribute.attr);
2533 if (!value) goto failed;
2534 if (PyObject_SetAttrString(result, "attr", value) == -1)
2535 goto failed;
2536 Py_DECREF(value);
2537 value = ast2obj_expr_context(o->v.Attribute.ctx);
2538 if (!value) goto failed;
2539 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2540 goto failed;
2541 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002542 break;
2543 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002544 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2545 if (!result) goto failed;
2546 value = ast2obj_expr(o->v.Subscript.value);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "value", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
2551 value = ast2obj_slice(o->v.Subscript.slice);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "slice", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
2556 value = ast2obj_expr_context(o->v.Subscript.ctx);
2557 if (!value) goto failed;
2558 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2559 goto failed;
2560 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002561 break;
2562 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002563 result = PyType_GenericNew(Name_type, NULL, NULL);
2564 if (!result) goto failed;
2565 value = ast2obj_identifier(o->v.Name.id);
2566 if (!value) goto failed;
2567 if (PyObject_SetAttrString(result, "id", value) == -1)
2568 goto failed;
2569 Py_DECREF(value);
2570 value = ast2obj_expr_context(o->v.Name.ctx);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002575 break;
2576 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002577 result = PyType_GenericNew(List_type, NULL, NULL);
2578 if (!result) goto failed;
2579 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2580 if (!value) goto failed;
2581 if (PyObject_SetAttrString(result, "elts", value) == -1)
2582 goto failed;
2583 Py_DECREF(value);
2584 value = ast2obj_expr_context(o->v.List.ctx);
2585 if (!value) goto failed;
2586 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2587 goto failed;
2588 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589 break;
2590 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002591 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2592 if (!result) goto failed;
2593 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2594 if (!value) goto failed;
2595 if (PyObject_SetAttrString(result, "elts", value) == -1)
2596 goto failed;
2597 Py_DECREF(value);
2598 value = ast2obj_expr_context(o->v.Tuple.ctx);
2599 if (!value) goto failed;
2600 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2601 goto failed;
2602 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002603 break;
2604 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002605 value = ast2obj_int(o->lineno);
2606 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002607 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2608 goto failed;
2609 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002610 value = ast2obj_int(o->col_offset);
2611 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002612 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2613 goto failed;
2614 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002615 return result;
2616failed:
2617 Py_XDECREF(value);
2618 Py_XDECREF(result);
2619 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002620}
2621
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002622PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002623{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002624 switch(o) {
2625 case Load:
2626 Py_INCREF(Load_singleton);
2627 return Load_singleton;
2628 case Store:
2629 Py_INCREF(Store_singleton);
2630 return Store_singleton;
2631 case Del:
2632 Py_INCREF(Del_singleton);
2633 return Del_singleton;
2634 case AugLoad:
2635 Py_INCREF(AugLoad_singleton);
2636 return AugLoad_singleton;
2637 case AugStore:
2638 Py_INCREF(AugStore_singleton);
2639 return AugStore_singleton;
2640 case Param:
2641 Py_INCREF(Param_singleton);
2642 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002643 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002644 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002645}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002646PyObject*
2647ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002648{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002649 slice_ty o = (slice_ty)_o;
2650 PyObject *result = NULL, *value = NULL;
2651 if (!o) {
2652 Py_INCREF(Py_None);
2653 return Py_None;
2654 }
2655
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002657 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 result = PyType_GenericNew(Slice_type, NULL, NULL);
2659 if (!result) goto failed;
2660 value = ast2obj_expr(o->v.Slice.lower);
2661 if (!value) goto failed;
2662 if (PyObject_SetAttrString(result, "lower", value) == -1)
2663 goto failed;
2664 Py_DECREF(value);
2665 value = ast2obj_expr(o->v.Slice.upper);
2666 if (!value) goto failed;
2667 if (PyObject_SetAttrString(result, "upper", value) == -1)
2668 goto failed;
2669 Py_DECREF(value);
2670 value = ast2obj_expr(o->v.Slice.step);
2671 if (!value) goto failed;
2672 if (PyObject_SetAttrString(result, "step", value) == -1)
2673 goto failed;
2674 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002675 break;
2676 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002677 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2678 if (!result) goto failed;
2679 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2680 if (!value) goto failed;
2681 if (PyObject_SetAttrString(result, "dims", value) == -1)
2682 goto failed;
2683 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002684 break;
2685 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002686 result = PyType_GenericNew(Index_type, NULL, NULL);
2687 if (!result) goto failed;
2688 value = ast2obj_expr(o->v.Index.value);
2689 if (!value) goto failed;
2690 if (PyObject_SetAttrString(result, "value", value) == -1)
2691 goto failed;
2692 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693 break;
2694 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002695 return result;
2696failed:
2697 Py_XDECREF(value);
2698 Py_XDECREF(result);
2699 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002700}
2701
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002702PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002703{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002704 switch(o) {
2705 case And:
2706 Py_INCREF(And_singleton);
2707 return And_singleton;
2708 case Or:
2709 Py_INCREF(Or_singleton);
2710 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002711 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002712 return NULL; /* cannot happen */
2713}
2714PyObject* ast2obj_operator(operator_ty o)
2715{
2716 switch(o) {
2717 case Add:
2718 Py_INCREF(Add_singleton);
2719 return Add_singleton;
2720 case Sub:
2721 Py_INCREF(Sub_singleton);
2722 return Sub_singleton;
2723 case Mult:
2724 Py_INCREF(Mult_singleton);
2725 return Mult_singleton;
2726 case Div:
2727 Py_INCREF(Div_singleton);
2728 return Div_singleton;
2729 case Mod:
2730 Py_INCREF(Mod_singleton);
2731 return Mod_singleton;
2732 case Pow:
2733 Py_INCREF(Pow_singleton);
2734 return Pow_singleton;
2735 case LShift:
2736 Py_INCREF(LShift_singleton);
2737 return LShift_singleton;
2738 case RShift:
2739 Py_INCREF(RShift_singleton);
2740 return RShift_singleton;
2741 case BitOr:
2742 Py_INCREF(BitOr_singleton);
2743 return BitOr_singleton;
2744 case BitXor:
2745 Py_INCREF(BitXor_singleton);
2746 return BitXor_singleton;
2747 case BitAnd:
2748 Py_INCREF(BitAnd_singleton);
2749 return BitAnd_singleton;
2750 case FloorDiv:
2751 Py_INCREF(FloorDiv_singleton);
2752 return FloorDiv_singleton;
2753 }
2754 return NULL; /* cannot happen */
2755}
2756PyObject* ast2obj_unaryop(unaryop_ty o)
2757{
2758 switch(o) {
2759 case Invert:
2760 Py_INCREF(Invert_singleton);
2761 return Invert_singleton;
2762 case Not:
2763 Py_INCREF(Not_singleton);
2764 return Not_singleton;
2765 case UAdd:
2766 Py_INCREF(UAdd_singleton);
2767 return UAdd_singleton;
2768 case USub:
2769 Py_INCREF(USub_singleton);
2770 return USub_singleton;
2771 }
2772 return NULL; /* cannot happen */
2773}
2774PyObject* ast2obj_cmpop(cmpop_ty o)
2775{
2776 switch(o) {
2777 case Eq:
2778 Py_INCREF(Eq_singleton);
2779 return Eq_singleton;
2780 case NotEq:
2781 Py_INCREF(NotEq_singleton);
2782 return NotEq_singleton;
2783 case Lt:
2784 Py_INCREF(Lt_singleton);
2785 return Lt_singleton;
2786 case LtE:
2787 Py_INCREF(LtE_singleton);
2788 return LtE_singleton;
2789 case Gt:
2790 Py_INCREF(Gt_singleton);
2791 return Gt_singleton;
2792 case GtE:
2793 Py_INCREF(GtE_singleton);
2794 return GtE_singleton;
2795 case Is:
2796 Py_INCREF(Is_singleton);
2797 return Is_singleton;
2798 case IsNot:
2799 Py_INCREF(IsNot_singleton);
2800 return IsNot_singleton;
2801 case In:
2802 Py_INCREF(In_singleton);
2803 return In_singleton;
2804 case NotIn:
2805 Py_INCREF(NotIn_singleton);
2806 return NotIn_singleton;
2807 }
2808 return NULL; /* cannot happen */
2809}
2810PyObject*
2811ast2obj_comprehension(void* _o)
2812{
2813 comprehension_ty o = (comprehension_ty)_o;
2814 PyObject *result = NULL, *value = NULL;
2815 if (!o) {
2816 Py_INCREF(Py_None);
2817 return Py_None;
2818 }
2819
2820 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2821 if (!result) return NULL;
2822 value = ast2obj_expr(o->target);
2823 if (!value) goto failed;
2824 if (PyObject_SetAttrString(result, "target", value) == -1)
2825 goto failed;
2826 Py_DECREF(value);
2827 value = ast2obj_expr(o->iter);
2828 if (!value) goto failed;
2829 if (PyObject_SetAttrString(result, "iter", value) == -1)
2830 goto failed;
2831 Py_DECREF(value);
2832 value = ast2obj_list(o->ifs, ast2obj_expr);
2833 if (!value) goto failed;
2834 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2835 goto failed;
2836 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002837 return result;
2838failed:
2839 Py_XDECREF(value);
2840 Py_XDECREF(result);
2841 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002842}
2843
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002844PyObject*
2845ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002846{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002847 excepthandler_ty o = (excepthandler_ty)_o;
2848 PyObject *result = NULL, *value = NULL;
2849 if (!o) {
2850 Py_INCREF(Py_None);
2851 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002852 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002853
2854 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2855 if (!result) return NULL;
2856 value = ast2obj_expr(o->type);
2857 if (!value) goto failed;
2858 if (PyObject_SetAttrString(result, "type", value) == -1)
2859 goto failed;
2860 Py_DECREF(value);
2861 value = ast2obj_expr(o->name);
2862 if (!value) goto failed;
2863 if (PyObject_SetAttrString(result, "name", value) == -1)
2864 goto failed;
2865 Py_DECREF(value);
2866 value = ast2obj_list(o->body, ast2obj_stmt);
2867 if (!value) goto failed;
2868 if (PyObject_SetAttrString(result, "body", value) == -1)
2869 goto failed;
2870 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002871 value = ast2obj_int(o->lineno);
2872 if (!value) goto failed;
2873 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2874 goto failed;
2875 Py_DECREF(value);
2876 value = ast2obj_int(o->col_offset);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002881 return result;
2882failed:
2883 Py_XDECREF(value);
2884 Py_XDECREF(result);
2885 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002886}
2887
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002888PyObject*
2889ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002890{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002891 arguments_ty o = (arguments_ty)_o;
2892 PyObject *result = NULL, *value = NULL;
2893 if (!o) {
2894 Py_INCREF(Py_None);
2895 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002896 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002897
2898 result = PyType_GenericNew(arguments_type, NULL, NULL);
2899 if (!result) return NULL;
2900 value = ast2obj_list(o->args, ast2obj_expr);
2901 if (!value) goto failed;
2902 if (PyObject_SetAttrString(result, "args", value) == -1)
2903 goto failed;
2904 Py_DECREF(value);
2905 value = ast2obj_identifier(o->vararg);
2906 if (!value) goto failed;
2907 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2908 goto failed;
2909 Py_DECREF(value);
2910 value = ast2obj_identifier(o->kwarg);
2911 if (!value) goto failed;
2912 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2913 goto failed;
2914 Py_DECREF(value);
2915 value = ast2obj_list(o->defaults, ast2obj_expr);
2916 if (!value) goto failed;
2917 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2918 goto failed;
2919 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002920 return result;
2921failed:
2922 Py_XDECREF(value);
2923 Py_XDECREF(result);
2924 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002925}
2926
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002927PyObject*
2928ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002929{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002930 keyword_ty o = (keyword_ty)_o;
2931 PyObject *result = NULL, *value = NULL;
2932 if (!o) {
2933 Py_INCREF(Py_None);
2934 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002935 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002936
2937 result = PyType_GenericNew(keyword_type, NULL, NULL);
2938 if (!result) return NULL;
2939 value = ast2obj_identifier(o->arg);
2940 if (!value) goto failed;
2941 if (PyObject_SetAttrString(result, "arg", value) == -1)
2942 goto failed;
2943 Py_DECREF(value);
2944 value = ast2obj_expr(o->value);
2945 if (!value) goto failed;
2946 if (PyObject_SetAttrString(result, "value", value) == -1)
2947 goto failed;
2948 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002949 return result;
2950failed:
2951 Py_XDECREF(value);
2952 Py_XDECREF(result);
2953 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002954}
2955
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002956PyObject*
2957ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002958{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002959 alias_ty o = (alias_ty)_o;
2960 PyObject *result = NULL, *value = NULL;
2961 if (!o) {
2962 Py_INCREF(Py_None);
2963 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002964 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002965
2966 result = PyType_GenericNew(alias_type, NULL, NULL);
2967 if (!result) return NULL;
2968 value = ast2obj_identifier(o->name);
2969 if (!value) goto failed;
2970 if (PyObject_SetAttrString(result, "name", value) == -1)
2971 goto failed;
2972 Py_DECREF(value);
2973 value = ast2obj_identifier(o->asname);
2974 if (!value) goto failed;
2975 if (PyObject_SetAttrString(result, "asname", value) == -1)
2976 goto failed;
2977 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002978 return result;
2979failed:
2980 Py_XDECREF(value);
2981 Py_XDECREF(result);
2982 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002983}
2984
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002985
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002986PyMODINIT_FUNC
2987init_ast(void)
2988{
2989 PyObject *m, *d;
2990 if (!init_types()) return;
2991 m = Py_InitModule3("_ast", NULL, NULL);
2992 if (!m) return;
2993 d = PyModule_GetDict(m);
2994 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
2995 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
2996 return;
Georg Brandl17ab9a02006-08-28 16:38:22 +00002997 if (PyModule_AddStringConstant(m, "__version__", "51631") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00002998 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002999 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3000 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3001 return;
3002 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3003 < 0) return;
3004 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3005 0) return;
3006 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3007 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3008 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3009 < 0) return;
3010 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3011 return;
3012 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3013 return;
3014 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3015 return;
3016 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3017 return;
3018 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3019 0) return;
3020 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3021 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3022 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3023 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3024 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3025 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3026 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3027 0) return;
3028 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3029 0) return;
3030 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3031 return;
3032 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3033 return;
3034 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3035 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003036 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3037 return;
3038 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3040 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3041 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3042 return;
3043 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3044 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3045 return;
3046 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3047 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3048 return;
3049 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3050 return;
3051 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3052 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003053 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003054 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3055 return;
3056 if (PyDict_SetItemString(d, "GeneratorExp",
3057 (PyObject*)GeneratorExp_type) < 0) return;
3058 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3059 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3060 return;
3061 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003062 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3063 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003064 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3065 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003066 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3067 0) return;
3068 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3069 0) return;
3070 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3071 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3072 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3073 if (PyDict_SetItemString(d, "expr_context",
3074 (PyObject*)expr_context_type) < 0) return;
3075 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3076 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3078 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3079 return;
3080 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3081 return;
3082 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3083 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003084 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3085 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3086 return;
3087 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3088 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3089 return;
3090 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3092 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3093 return;
3094 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3095 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3096 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3097 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3098 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3099 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3100 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3103 return;
3104 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3105 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3106 return;
3107 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3108 return;
3109 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3110 return;
3111 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3114 return;
3115 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3116 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3117 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3118 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3120 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3121 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3122 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3123 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3124 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3126 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3127 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3128 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3129 if (PyDict_SetItemString(d, "comprehension",
3130 (PyObject*)comprehension_type) < 0) return;
3131 if (PyDict_SetItemString(d, "excepthandler",
3132 (PyObject*)excepthandler_type) < 0) return;
3133 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3134 0) return;
3135 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3136 return;
3137 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003138}
3139
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003140
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003141PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003142{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003143 init_types();
3144 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003145}
3146
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003147