blob: 6ba978b1aa86b80f18f6a2d15b723b44b557441e [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};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Attribute_type;
216static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "value",
218 "attr",
219 "ctx",
220};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000221static PyTypeObject *Subscript_type;
222static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000223 "value",
224 "slice",
225 "ctx",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Name_type;
228static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "id",
230 "ctx",
231};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000232static PyTypeObject *List_type;
233static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000234 "elts",
235 "ctx",
236};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000237static PyTypeObject *Tuple_type;
238static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000239 "elts",
240 "ctx",
241};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000243static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
244*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
245static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000246static PyTypeObject *Load_type;
247static PyTypeObject *Store_type;
248static PyTypeObject *Del_type;
249static PyTypeObject *AugLoad_type;
250static PyTypeObject *AugStore_type;
251static PyTypeObject *Param_type;
252static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000253static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000254static PyTypeObject *Ellipsis_type;
255static 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;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Tuple_type) return 0;
543 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
544 if (!expr_context_type) return 0;
545 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000546 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000550 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000554 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000558 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000562 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000566 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Param_singleton) return 0;
570 slice_type = make_type("slice", AST_type, NULL, 0);
571 if (!slice_type) return 0;
572 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000573 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Ellipsis_type) 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
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001582Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1583 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584{
1585 expr_ty p;
1586 if (!value) {
1587 PyErr_SetString(PyExc_ValueError,
1588 "field value is required for Attribute");
1589 return NULL;
1590 }
1591 if (!attr) {
1592 PyErr_SetString(PyExc_ValueError,
1593 "field attr is required for Attribute");
1594 return NULL;
1595 }
1596 if (!ctx) {
1597 PyErr_SetString(PyExc_ValueError,
1598 "field ctx is required for Attribute");
1599 return NULL;
1600 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001601 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001602 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001603 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001604 return NULL;
1605 }
1606 p->kind = Attribute_kind;
1607 p->v.Attribute.value = value;
1608 p->v.Attribute.attr = attr;
1609 p->v.Attribute.ctx = ctx;
1610 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001611 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001612 return p;
1613}
1614
1615expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001616Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1617 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001618{
1619 expr_ty p;
1620 if (!value) {
1621 PyErr_SetString(PyExc_ValueError,
1622 "field value is required for Subscript");
1623 return NULL;
1624 }
1625 if (!slice) {
1626 PyErr_SetString(PyExc_ValueError,
1627 "field slice is required for Subscript");
1628 return NULL;
1629 }
1630 if (!ctx) {
1631 PyErr_SetString(PyExc_ValueError,
1632 "field ctx is required for Subscript");
1633 return NULL;
1634 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001635 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001636 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001637 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001638 return NULL;
1639 }
1640 p->kind = Subscript_kind;
1641 p->v.Subscript.value = value;
1642 p->v.Subscript.slice = slice;
1643 p->v.Subscript.ctx = ctx;
1644 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001645 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001646 return p;
1647}
1648
1649expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001650Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1651 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652{
1653 expr_ty p;
1654 if (!id) {
1655 PyErr_SetString(PyExc_ValueError,
1656 "field id is required for Name");
1657 return NULL;
1658 }
1659 if (!ctx) {
1660 PyErr_SetString(PyExc_ValueError,
1661 "field ctx is required for Name");
1662 return NULL;
1663 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001664 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001665 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001666 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001667 return NULL;
1668 }
1669 p->kind = Name_kind;
1670 p->v.Name.id = id;
1671 p->v.Name.ctx = ctx;
1672 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001673 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001674 return p;
1675}
1676
1677expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001678List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1679 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001680{
1681 expr_ty p;
1682 if (!ctx) {
1683 PyErr_SetString(PyExc_ValueError,
1684 "field ctx is required for List");
1685 return NULL;
1686 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001687 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001689 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001690 return NULL;
1691 }
1692 p->kind = List_kind;
1693 p->v.List.elts = elts;
1694 p->v.List.ctx = ctx;
1695 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001696 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697 return p;
1698}
1699
1700expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001701Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1702 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703{
1704 expr_ty p;
1705 if (!ctx) {
1706 PyErr_SetString(PyExc_ValueError,
1707 "field ctx is required for Tuple");
1708 return NULL;
1709 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001710 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001711 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001712 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713 return NULL;
1714 }
1715 p->kind = Tuple_kind;
1716 p->v.Tuple.elts = elts;
1717 p->v.Tuple.ctx = ctx;
1718 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001719 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720 return p;
1721}
1722
1723slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001724Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725{
1726 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001727 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001728 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001729 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730 return NULL;
1731 }
1732 p->kind = Ellipsis_kind;
1733 return p;
1734}
1735
1736slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001737Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738{
1739 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001740 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001741 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001742 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001743 return NULL;
1744 }
1745 p->kind = Slice_kind;
1746 p->v.Slice.lower = lower;
1747 p->v.Slice.upper = upper;
1748 p->v.Slice.step = step;
1749 return p;
1750}
1751
1752slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001753ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001754{
1755 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001756 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001758 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001759 return NULL;
1760 }
1761 p->kind = ExtSlice_kind;
1762 p->v.ExtSlice.dims = dims;
1763 return p;
1764}
1765
1766slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001767Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001768{
1769 slice_ty p;
1770 if (!value) {
1771 PyErr_SetString(PyExc_ValueError,
1772 "field value is required for Index");
1773 return NULL;
1774 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001775 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001777 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 return NULL;
1779 }
1780 p->kind = Index_kind;
1781 p->v.Index.value = value;
1782 return p;
1783}
1784
1785comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001786comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787{
1788 comprehension_ty p;
1789 if (!target) {
1790 PyErr_SetString(PyExc_ValueError,
1791 "field target is required for comprehension");
1792 return NULL;
1793 }
1794 if (!iter) {
1795 PyErr_SetString(PyExc_ValueError,
1796 "field iter is required for comprehension");
1797 return NULL;
1798 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001799 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001800 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001801 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001802 return NULL;
1803 }
1804 p->target = target;
1805 p->iter = iter;
1806 p->ifs = ifs;
1807 return p;
1808}
1809
1810excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001811excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1812 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813{
1814 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001815 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001816 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001817 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001818 return NULL;
1819 }
1820 p->type = type;
1821 p->name = name;
1822 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001823 p->lineno = lineno;
1824 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001825 return p;
1826}
1827
1828arguments_ty
1829arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001830 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001831{
1832 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001833 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001834 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001835 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001836 return NULL;
1837 }
1838 p->args = args;
1839 p->vararg = vararg;
1840 p->kwarg = kwarg;
1841 p->defaults = defaults;
1842 return p;
1843}
1844
1845keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001846keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847{
1848 keyword_ty p;
1849 if (!arg) {
1850 PyErr_SetString(PyExc_ValueError,
1851 "field arg is required for keyword");
1852 return NULL;
1853 }
1854 if (!value) {
1855 PyErr_SetString(PyExc_ValueError,
1856 "field value is required for keyword");
1857 return NULL;
1858 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001859 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001860 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001861 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 return NULL;
1863 }
1864 p->arg = arg;
1865 p->value = value;
1866 return p;
1867}
1868
1869alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001870alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001871{
1872 alias_ty p;
1873 if (!name) {
1874 PyErr_SetString(PyExc_ValueError,
1875 "field name is required for alias");
1876 return NULL;
1877 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001878 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001880 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881 return NULL;
1882 }
1883 p->name = name;
1884 p->asname = asname;
1885 return p;
1886}
1887
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001888
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001889PyObject*
1890ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001891{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001892 mod_ty o = (mod_ty)_o;
1893 PyObject *result = NULL, *value = NULL;
1894 if (!o) {
1895 Py_INCREF(Py_None);
1896 return Py_None;
1897 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001898
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899 switch (o->kind) {
1900 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001901 result = PyType_GenericNew(Module_type, NULL, NULL);
1902 if (!result) goto failed;
1903 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1904 if (!value) goto failed;
1905 if (PyObject_SetAttrString(result, "body", value) == -1)
1906 goto failed;
1907 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001908 break;
1909 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001910 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1911 if (!result) goto failed;
1912 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1913 if (!value) goto failed;
1914 if (PyObject_SetAttrString(result, "body", value) == -1)
1915 goto failed;
1916 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001917 break;
1918 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001919 result = PyType_GenericNew(Expression_type, NULL, NULL);
1920 if (!result) goto failed;
1921 value = ast2obj_expr(o->v.Expression.body);
1922 if (!value) goto failed;
1923 if (PyObject_SetAttrString(result, "body", value) == -1)
1924 goto failed;
1925 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001926 break;
1927 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001928 result = PyType_GenericNew(Suite_type, NULL, NULL);
1929 if (!result) goto failed;
1930 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1931 if (!value) goto failed;
1932 if (PyObject_SetAttrString(result, "body", value) == -1)
1933 goto failed;
1934 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001935 break;
1936 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001937 return result;
1938failed:
1939 Py_XDECREF(value);
1940 Py_XDECREF(result);
1941 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001942}
1943
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001944PyObject*
1945ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001946{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001947 stmt_ty o = (stmt_ty)_o;
1948 PyObject *result = NULL, *value = NULL;
1949 if (!o) {
1950 Py_INCREF(Py_None);
1951 return Py_None;
1952 }
1953
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001954 switch (o->kind) {
1955 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001956 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1957 if (!result) goto failed;
1958 value = ast2obj_identifier(o->v.FunctionDef.name);
1959 if (!value) goto failed;
1960 if (PyObject_SetAttrString(result, "name", value) == -1)
1961 goto failed;
1962 Py_DECREF(value);
1963 value = ast2obj_arguments(o->v.FunctionDef.args);
1964 if (!value) goto failed;
1965 if (PyObject_SetAttrString(result, "args", value) == -1)
1966 goto failed;
1967 Py_DECREF(value);
1968 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1969 if (!value) goto failed;
1970 if (PyObject_SetAttrString(result, "body", value) == -1)
1971 goto failed;
1972 Py_DECREF(value);
1973 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1974 if (!value) goto failed;
1975 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1976 goto failed;
1977 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978 break;
1979 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001980 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1981 if (!result) goto failed;
1982 value = ast2obj_identifier(o->v.ClassDef.name);
1983 if (!value) goto failed;
1984 if (PyObject_SetAttrString(result, "name", value) == -1)
1985 goto failed;
1986 Py_DECREF(value);
1987 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1988 if (!value) goto failed;
1989 if (PyObject_SetAttrString(result, "bases", value) == -1)
1990 goto failed;
1991 Py_DECREF(value);
1992 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1993 if (!value) goto failed;
1994 if (PyObject_SetAttrString(result, "body", value) == -1)
1995 goto failed;
1996 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001997 break;
1998 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001999 result = PyType_GenericNew(Return_type, NULL, NULL);
2000 if (!result) goto failed;
2001 value = ast2obj_expr(o->v.Return.value);
2002 if (!value) goto failed;
2003 if (PyObject_SetAttrString(result, "value", value) == -1)
2004 goto failed;
2005 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002006 break;
2007 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002008 result = PyType_GenericNew(Delete_type, NULL, NULL);
2009 if (!result) goto failed;
2010 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2011 if (!value) goto failed;
2012 if (PyObject_SetAttrString(result, "targets", value) == -1)
2013 goto failed;
2014 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002015 break;
2016 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002017 result = PyType_GenericNew(Assign_type, NULL, NULL);
2018 if (!result) goto failed;
2019 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "targets", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
2024 value = ast2obj_expr(o->v.Assign.value);
2025 if (!value) goto failed;
2026 if (PyObject_SetAttrString(result, "value", value) == -1)
2027 goto failed;
2028 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002029 break;
2030 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002031 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2032 if (!result) goto failed;
2033 value = ast2obj_expr(o->v.AugAssign.target);
2034 if (!value) goto failed;
2035 if (PyObject_SetAttrString(result, "target", value) == -1)
2036 goto failed;
2037 Py_DECREF(value);
2038 value = ast2obj_operator(o->v.AugAssign.op);
2039 if (!value) goto failed;
2040 if (PyObject_SetAttrString(result, "op", value) == -1)
2041 goto failed;
2042 Py_DECREF(value);
2043 value = ast2obj_expr(o->v.AugAssign.value);
2044 if (!value) goto failed;
2045 if (PyObject_SetAttrString(result, "value", value) == -1)
2046 goto failed;
2047 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002048 break;
2049 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002050 result = PyType_GenericNew(Print_type, NULL, NULL);
2051 if (!result) goto failed;
2052 value = ast2obj_expr(o->v.Print.dest);
2053 if (!value) goto failed;
2054 if (PyObject_SetAttrString(result, "dest", value) == -1)
2055 goto failed;
2056 Py_DECREF(value);
2057 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2058 if (!value) goto failed;
2059 if (PyObject_SetAttrString(result, "values", value) == -1)
2060 goto failed;
2061 Py_DECREF(value);
2062 value = ast2obj_bool(o->v.Print.nl);
2063 if (!value) goto failed;
2064 if (PyObject_SetAttrString(result, "nl", value) == -1)
2065 goto failed;
2066 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002067 break;
2068 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002069 result = PyType_GenericNew(For_type, NULL, NULL);
2070 if (!result) goto failed;
2071 value = ast2obj_expr(o->v.For.target);
2072 if (!value) goto failed;
2073 if (PyObject_SetAttrString(result, "target", value) == -1)
2074 goto failed;
2075 Py_DECREF(value);
2076 value = ast2obj_expr(o->v.For.iter);
2077 if (!value) goto failed;
2078 if (PyObject_SetAttrString(result, "iter", value) == -1)
2079 goto failed;
2080 Py_DECREF(value);
2081 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2082 if (!value) goto failed;
2083 if (PyObject_SetAttrString(result, "body", value) == -1)
2084 goto failed;
2085 Py_DECREF(value);
2086 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2087 if (!value) goto failed;
2088 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2089 goto failed;
2090 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002091 break;
2092 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002093 result = PyType_GenericNew(While_type, NULL, NULL);
2094 if (!result) goto failed;
2095 value = ast2obj_expr(o->v.While.test);
2096 if (!value) goto failed;
2097 if (PyObject_SetAttrString(result, "test", value) == -1)
2098 goto failed;
2099 Py_DECREF(value);
2100 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2101 if (!value) goto failed;
2102 if (PyObject_SetAttrString(result, "body", value) == -1)
2103 goto failed;
2104 Py_DECREF(value);
2105 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2106 if (!value) goto failed;
2107 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2108 goto failed;
2109 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002110 break;
2111 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002112 result = PyType_GenericNew(If_type, NULL, NULL);
2113 if (!result) goto failed;
2114 value = ast2obj_expr(o->v.If.test);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "test", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
2119 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "body", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002129 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002130 case With_kind:
2131 result = PyType_GenericNew(With_type, NULL, NULL);
2132 if (!result) goto failed;
2133 value = ast2obj_expr(o->v.With.context_expr);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
2138 value = ast2obj_expr(o->v.With.optional_vars);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2141 -1)
2142 goto failed;
2143 Py_DECREF(value);
2144 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "body", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002150 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002151 result = PyType_GenericNew(Raise_type, NULL, NULL);
2152 if (!result) goto failed;
2153 value = ast2obj_expr(o->v.Raise.type);
2154 if (!value) goto failed;
2155 if (PyObject_SetAttrString(result, "type", value) == -1)
2156 goto failed;
2157 Py_DECREF(value);
2158 value = ast2obj_expr(o->v.Raise.inst);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "inst", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
2163 value = ast2obj_expr(o->v.Raise.tback);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "tback", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002168 break;
2169 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002170 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2171 if (!result) goto failed;
2172 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2173 if (!value) goto failed;
2174 if (PyObject_SetAttrString(result, "body", value) == -1)
2175 goto failed;
2176 Py_DECREF(value);
2177 value = ast2obj_list(o->v.TryExcept.handlers,
2178 ast2obj_excepthandler);
2179 if (!value) goto failed;
2180 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2181 goto failed;
2182 Py_DECREF(value);
2183 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2184 if (!value) goto failed;
2185 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2186 goto failed;
2187 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002188 break;
2189 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002190 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2191 if (!result) goto failed;
2192 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2193 if (!value) goto failed;
2194 if (PyObject_SetAttrString(result, "body", value) == -1)
2195 goto failed;
2196 Py_DECREF(value);
2197 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2198 if (!value) goto failed;
2199 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2200 goto failed;
2201 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002202 break;
2203 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002204 result = PyType_GenericNew(Assert_type, NULL, NULL);
2205 if (!result) goto failed;
2206 value = ast2obj_expr(o->v.Assert.test);
2207 if (!value) goto failed;
2208 if (PyObject_SetAttrString(result, "test", value) == -1)
2209 goto failed;
2210 Py_DECREF(value);
2211 value = ast2obj_expr(o->v.Assert.msg);
2212 if (!value) goto failed;
2213 if (PyObject_SetAttrString(result, "msg", value) == -1)
2214 goto failed;
2215 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002216 break;
2217 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002218 result = PyType_GenericNew(Import_type, NULL, NULL);
2219 if (!result) goto failed;
2220 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "names", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002225 break;
2226 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002227 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2228 if (!result) goto failed;
2229 value = ast2obj_identifier(o->v.ImportFrom.module);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "module", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
2234 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "names", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002239 value = ast2obj_int(o->v.ImportFrom.level);
2240 if (!value) goto failed;
2241 if (PyObject_SetAttrString(result, "level", value) == -1)
2242 goto failed;
2243 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002244 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002245 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002246 result = PyType_GenericNew(Global_type, NULL, NULL);
2247 if (!result) goto failed;
2248 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2249 if (!value) goto failed;
2250 if (PyObject_SetAttrString(result, "names", value) == -1)
2251 goto failed;
2252 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253 break;
2254 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002255 result = PyType_GenericNew(Expr_type, NULL, NULL);
2256 if (!result) goto failed;
2257 value = ast2obj_expr(o->v.Expr.value);
2258 if (!value) goto failed;
2259 if (PyObject_SetAttrString(result, "value", value) == -1)
2260 goto failed;
2261 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262 break;
2263 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002264 result = PyType_GenericNew(Pass_type, NULL, NULL);
2265 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002266 break;
2267 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002268 result = PyType_GenericNew(Break_type, NULL, NULL);
2269 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002270 break;
2271 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002272 result = PyType_GenericNew(Continue_type, NULL, NULL);
2273 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002274 break;
2275 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002276 value = ast2obj_int(o->lineno);
2277 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002278 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2279 goto failed;
2280 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002281 value = ast2obj_int(o->col_offset);
2282 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002283 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2284 goto failed;
2285 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002286 return result;
2287failed:
2288 Py_XDECREF(value);
2289 Py_XDECREF(result);
2290 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002291}
2292
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002293PyObject*
2294ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002295{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002296 expr_ty o = (expr_ty)_o;
2297 PyObject *result = NULL, *value = NULL;
2298 if (!o) {
2299 Py_INCREF(Py_None);
2300 return Py_None;
2301 }
2302
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002303 switch (o->kind) {
2304 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002305 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2306 if (!result) goto failed;
2307 value = ast2obj_boolop(o->v.BoolOp.op);
2308 if (!value) goto failed;
2309 if (PyObject_SetAttrString(result, "op", value) == -1)
2310 goto failed;
2311 Py_DECREF(value);
2312 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2313 if (!value) goto failed;
2314 if (PyObject_SetAttrString(result, "values", value) == -1)
2315 goto failed;
2316 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317 break;
2318 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002319 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2320 if (!result) goto failed;
2321 value = ast2obj_expr(o->v.BinOp.left);
2322 if (!value) goto failed;
2323 if (PyObject_SetAttrString(result, "left", value) == -1)
2324 goto failed;
2325 Py_DECREF(value);
2326 value = ast2obj_operator(o->v.BinOp.op);
2327 if (!value) goto failed;
2328 if (PyObject_SetAttrString(result, "op", value) == -1)
2329 goto failed;
2330 Py_DECREF(value);
2331 value = ast2obj_expr(o->v.BinOp.right);
2332 if (!value) goto failed;
2333 if (PyObject_SetAttrString(result, "right", value) == -1)
2334 goto failed;
2335 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002336 break;
2337 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002338 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2339 if (!result) goto failed;
2340 value = ast2obj_unaryop(o->v.UnaryOp.op);
2341 if (!value) goto failed;
2342 if (PyObject_SetAttrString(result, "op", value) == -1)
2343 goto failed;
2344 Py_DECREF(value);
2345 value = ast2obj_expr(o->v.UnaryOp.operand);
2346 if (!value) goto failed;
2347 if (PyObject_SetAttrString(result, "operand", value) == -1)
2348 goto failed;
2349 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002350 break;
2351 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002352 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2353 if (!result) goto failed;
2354 value = ast2obj_arguments(o->v.Lambda.args);
2355 if (!value) goto failed;
2356 if (PyObject_SetAttrString(result, "args", value) == -1)
2357 goto failed;
2358 Py_DECREF(value);
2359 value = ast2obj_expr(o->v.Lambda.body);
2360 if (!value) goto failed;
2361 if (PyObject_SetAttrString(result, "body", value) == -1)
2362 goto failed;
2363 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002364 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002365 case IfExp_kind:
2366 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2367 if (!result) goto failed;
2368 value = ast2obj_expr(o->v.IfExp.test);
2369 if (!value) goto failed;
2370 if (PyObject_SetAttrString(result, "test", value) == -1)
2371 goto failed;
2372 Py_DECREF(value);
2373 value = ast2obj_expr(o->v.IfExp.body);
2374 if (!value) goto failed;
2375 if (PyObject_SetAttrString(result, "body", value) == -1)
2376 goto failed;
2377 Py_DECREF(value);
2378 value = ast2obj_expr(o->v.IfExp.orelse);
2379 if (!value) goto failed;
2380 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2381 goto failed;
2382 Py_DECREF(value);
2383 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002384 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002385 result = PyType_GenericNew(Dict_type, NULL, NULL);
2386 if (!result) goto failed;
2387 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2388 if (!value) goto failed;
2389 if (PyObject_SetAttrString(result, "keys", value) == -1)
2390 goto failed;
2391 Py_DECREF(value);
2392 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2393 if (!value) goto failed;
2394 if (PyObject_SetAttrString(result, "values", value) == -1)
2395 goto failed;
2396 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002397 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002398 case Set_kind:
2399 result = PyType_GenericNew(Set_type, NULL, NULL);
2400 if (!result) goto failed;
2401 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2402 if (!value) goto failed;
2403 if (PyObject_SetAttrString(result, "elts", value) == -1)
2404 goto failed;
2405 Py_DECREF(value);
2406 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002407 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002408 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2409 if (!result) goto failed;
2410 value = ast2obj_expr(o->v.ListComp.elt);
2411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "elt", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
2415 value = ast2obj_list(o->v.ListComp.generators,
2416 ast2obj_comprehension);
2417 if (!value) goto failed;
2418 if (PyObject_SetAttrString(result, "generators", value) == -1)
2419 goto failed;
2420 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002421 break;
2422 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002423 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2424 if (!result) goto failed;
2425 value = ast2obj_expr(o->v.GeneratorExp.elt);
2426 if (!value) goto failed;
2427 if (PyObject_SetAttrString(result, "elt", value) == -1)
2428 goto failed;
2429 Py_DECREF(value);
2430 value = ast2obj_list(o->v.GeneratorExp.generators,
2431 ast2obj_comprehension);
2432 if (!value) goto failed;
2433 if (PyObject_SetAttrString(result, "generators", value) == -1)
2434 goto failed;
2435 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436 break;
2437 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002438 result = PyType_GenericNew(Yield_type, NULL, NULL);
2439 if (!result) goto failed;
2440 value = ast2obj_expr(o->v.Yield.value);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "value", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002445 break;
2446 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002447 result = PyType_GenericNew(Compare_type, NULL, NULL);
2448 if (!result) goto failed;
2449 value = ast2obj_expr(o->v.Compare.left);
2450 if (!value) goto failed;
2451 if (PyObject_SetAttrString(result, "left", value) == -1)
2452 goto failed;
2453 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002454 {
2455 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2456 value = PyList_New(n);
2457 if (!value) goto failed;
2458 for(i = 0; i < n; i++)
2459 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2460 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002461 if (!value) goto failed;
2462 if (PyObject_SetAttrString(result, "ops", value) == -1)
2463 goto failed;
2464 Py_DECREF(value);
2465 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002470 break;
2471 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002472 result = PyType_GenericNew(Call_type, NULL, NULL);
2473 if (!result) goto failed;
2474 value = ast2obj_expr(o->v.Call.func);
2475 if (!value) goto failed;
2476 if (PyObject_SetAttrString(result, "func", value) == -1)
2477 goto failed;
2478 Py_DECREF(value);
2479 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2480 if (!value) goto failed;
2481 if (PyObject_SetAttrString(result, "args", value) == -1)
2482 goto failed;
2483 Py_DECREF(value);
2484 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
2489 value = ast2obj_expr(o->v.Call.starargs);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2494 value = ast2obj_expr(o->v.Call.kwargs);
2495 if (!value) goto failed;
2496 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2497 goto failed;
2498 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002499 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002500 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002501 result = PyType_GenericNew(Num_type, NULL, NULL);
2502 if (!result) goto failed;
2503 value = ast2obj_object(o->v.Num.n);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "n", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002508 break;
2509 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002510 result = PyType_GenericNew(Str_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_string(o->v.Str.s);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "s", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517 break;
2518 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002519 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2520 if (!result) goto failed;
2521 value = ast2obj_expr(o->v.Attribute.value);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "value", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
2526 value = ast2obj_identifier(o->v.Attribute.attr);
2527 if (!value) goto failed;
2528 if (PyObject_SetAttrString(result, "attr", value) == -1)
2529 goto failed;
2530 Py_DECREF(value);
2531 value = ast2obj_expr_context(o->v.Attribute.ctx);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002536 break;
2537 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002538 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2539 if (!result) goto failed;
2540 value = ast2obj_expr(o->v.Subscript.value);
2541 if (!value) goto failed;
2542 if (PyObject_SetAttrString(result, "value", value) == -1)
2543 goto failed;
2544 Py_DECREF(value);
2545 value = ast2obj_slice(o->v.Subscript.slice);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "slice", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
2550 value = ast2obj_expr_context(o->v.Subscript.ctx);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002555 break;
2556 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002557 result = PyType_GenericNew(Name_type, NULL, NULL);
2558 if (!result) goto failed;
2559 value = ast2obj_identifier(o->v.Name.id);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "id", value) == -1)
2562 goto failed;
2563 Py_DECREF(value);
2564 value = ast2obj_expr_context(o->v.Name.ctx);
2565 if (!value) goto failed;
2566 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2567 goto failed;
2568 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002569 break;
2570 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002571 result = PyType_GenericNew(List_type, NULL, NULL);
2572 if (!result) goto failed;
2573 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2574 if (!value) goto failed;
2575 if (PyObject_SetAttrString(result, "elts", value) == -1)
2576 goto failed;
2577 Py_DECREF(value);
2578 value = ast2obj_expr_context(o->v.List.ctx);
2579 if (!value) goto failed;
2580 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2581 goto failed;
2582 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002583 break;
2584 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002585 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2586 if (!result) goto failed;
2587 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2588 if (!value) goto failed;
2589 if (PyObject_SetAttrString(result, "elts", value) == -1)
2590 goto failed;
2591 Py_DECREF(value);
2592 value = ast2obj_expr_context(o->v.Tuple.ctx);
2593 if (!value) goto failed;
2594 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2595 goto failed;
2596 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002597 break;
2598 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002599 value = ast2obj_int(o->lineno);
2600 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002601 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2602 goto failed;
2603 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002604 value = ast2obj_int(o->col_offset);
2605 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002606 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2607 goto failed;
2608 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002609 return result;
2610failed:
2611 Py_XDECREF(value);
2612 Py_XDECREF(result);
2613 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002614}
2615
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002616PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002617{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002618 switch(o) {
2619 case Load:
2620 Py_INCREF(Load_singleton);
2621 return Load_singleton;
2622 case Store:
2623 Py_INCREF(Store_singleton);
2624 return Store_singleton;
2625 case Del:
2626 Py_INCREF(Del_singleton);
2627 return Del_singleton;
2628 case AugLoad:
2629 Py_INCREF(AugLoad_singleton);
2630 return AugLoad_singleton;
2631 case AugStore:
2632 Py_INCREF(AugStore_singleton);
2633 return AugStore_singleton;
2634 case Param:
2635 Py_INCREF(Param_singleton);
2636 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002637 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002638 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002639}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002640PyObject*
2641ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002642{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002643 slice_ty o = (slice_ty)_o;
2644 PyObject *result = NULL, *value = NULL;
2645 if (!o) {
2646 Py_INCREF(Py_None);
2647 return Py_None;
2648 }
2649
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002650 switch (o->kind) {
2651 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002652 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2653 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002654 break;
2655 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002656 result = PyType_GenericNew(Slice_type, NULL, NULL);
2657 if (!result) goto failed;
2658 value = ast2obj_expr(o->v.Slice.lower);
2659 if (!value) goto failed;
2660 if (PyObject_SetAttrString(result, "lower", value) == -1)
2661 goto failed;
2662 Py_DECREF(value);
2663 value = ast2obj_expr(o->v.Slice.upper);
2664 if (!value) goto failed;
2665 if (PyObject_SetAttrString(result, "upper", value) == -1)
2666 goto failed;
2667 Py_DECREF(value);
2668 value = ast2obj_expr(o->v.Slice.step);
2669 if (!value) goto failed;
2670 if (PyObject_SetAttrString(result, "step", value) == -1)
2671 goto failed;
2672 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002673 break;
2674 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002675 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2676 if (!result) goto failed;
2677 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2678 if (!value) goto failed;
2679 if (PyObject_SetAttrString(result, "dims", value) == -1)
2680 goto failed;
2681 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682 break;
2683 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002684 result = PyType_GenericNew(Index_type, NULL, NULL);
2685 if (!result) goto failed;
2686 value = ast2obj_expr(o->v.Index.value);
2687 if (!value) goto failed;
2688 if (PyObject_SetAttrString(result, "value", value) == -1)
2689 goto failed;
2690 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002691 break;
2692 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002693 return result;
2694failed:
2695 Py_XDECREF(value);
2696 Py_XDECREF(result);
2697 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002698}
2699
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002700PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002701{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002702 switch(o) {
2703 case And:
2704 Py_INCREF(And_singleton);
2705 return And_singleton;
2706 case Or:
2707 Py_INCREF(Or_singleton);
2708 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002709 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002710 return NULL; /* cannot happen */
2711}
2712PyObject* ast2obj_operator(operator_ty o)
2713{
2714 switch(o) {
2715 case Add:
2716 Py_INCREF(Add_singleton);
2717 return Add_singleton;
2718 case Sub:
2719 Py_INCREF(Sub_singleton);
2720 return Sub_singleton;
2721 case Mult:
2722 Py_INCREF(Mult_singleton);
2723 return Mult_singleton;
2724 case Div:
2725 Py_INCREF(Div_singleton);
2726 return Div_singleton;
2727 case Mod:
2728 Py_INCREF(Mod_singleton);
2729 return Mod_singleton;
2730 case Pow:
2731 Py_INCREF(Pow_singleton);
2732 return Pow_singleton;
2733 case LShift:
2734 Py_INCREF(LShift_singleton);
2735 return LShift_singleton;
2736 case RShift:
2737 Py_INCREF(RShift_singleton);
2738 return RShift_singleton;
2739 case BitOr:
2740 Py_INCREF(BitOr_singleton);
2741 return BitOr_singleton;
2742 case BitXor:
2743 Py_INCREF(BitXor_singleton);
2744 return BitXor_singleton;
2745 case BitAnd:
2746 Py_INCREF(BitAnd_singleton);
2747 return BitAnd_singleton;
2748 case FloorDiv:
2749 Py_INCREF(FloorDiv_singleton);
2750 return FloorDiv_singleton;
2751 }
2752 return NULL; /* cannot happen */
2753}
2754PyObject* ast2obj_unaryop(unaryop_ty o)
2755{
2756 switch(o) {
2757 case Invert:
2758 Py_INCREF(Invert_singleton);
2759 return Invert_singleton;
2760 case Not:
2761 Py_INCREF(Not_singleton);
2762 return Not_singleton;
2763 case UAdd:
2764 Py_INCREF(UAdd_singleton);
2765 return UAdd_singleton;
2766 case USub:
2767 Py_INCREF(USub_singleton);
2768 return USub_singleton;
2769 }
2770 return NULL; /* cannot happen */
2771}
2772PyObject* ast2obj_cmpop(cmpop_ty o)
2773{
2774 switch(o) {
2775 case Eq:
2776 Py_INCREF(Eq_singleton);
2777 return Eq_singleton;
2778 case NotEq:
2779 Py_INCREF(NotEq_singleton);
2780 return NotEq_singleton;
2781 case Lt:
2782 Py_INCREF(Lt_singleton);
2783 return Lt_singleton;
2784 case LtE:
2785 Py_INCREF(LtE_singleton);
2786 return LtE_singleton;
2787 case Gt:
2788 Py_INCREF(Gt_singleton);
2789 return Gt_singleton;
2790 case GtE:
2791 Py_INCREF(GtE_singleton);
2792 return GtE_singleton;
2793 case Is:
2794 Py_INCREF(Is_singleton);
2795 return Is_singleton;
2796 case IsNot:
2797 Py_INCREF(IsNot_singleton);
2798 return IsNot_singleton;
2799 case In:
2800 Py_INCREF(In_singleton);
2801 return In_singleton;
2802 case NotIn:
2803 Py_INCREF(NotIn_singleton);
2804 return NotIn_singleton;
2805 }
2806 return NULL; /* cannot happen */
2807}
2808PyObject*
2809ast2obj_comprehension(void* _o)
2810{
2811 comprehension_ty o = (comprehension_ty)_o;
2812 PyObject *result = NULL, *value = NULL;
2813 if (!o) {
2814 Py_INCREF(Py_None);
2815 return Py_None;
2816 }
2817
2818 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2819 if (!result) return NULL;
2820 value = ast2obj_expr(o->target);
2821 if (!value) goto failed;
2822 if (PyObject_SetAttrString(result, "target", value) == -1)
2823 goto failed;
2824 Py_DECREF(value);
2825 value = ast2obj_expr(o->iter);
2826 if (!value) goto failed;
2827 if (PyObject_SetAttrString(result, "iter", value) == -1)
2828 goto failed;
2829 Py_DECREF(value);
2830 value = ast2obj_list(o->ifs, ast2obj_expr);
2831 if (!value) goto failed;
2832 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2833 goto failed;
2834 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002835 return result;
2836failed:
2837 Py_XDECREF(value);
2838 Py_XDECREF(result);
2839 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002840}
2841
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002842PyObject*
2843ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002844{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002845 excepthandler_ty o = (excepthandler_ty)_o;
2846 PyObject *result = NULL, *value = NULL;
2847 if (!o) {
2848 Py_INCREF(Py_None);
2849 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002850 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002851
2852 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2853 if (!result) return NULL;
2854 value = ast2obj_expr(o->type);
2855 if (!value) goto failed;
2856 if (PyObject_SetAttrString(result, "type", value) == -1)
2857 goto failed;
2858 Py_DECREF(value);
2859 value = ast2obj_expr(o->name);
2860 if (!value) goto failed;
2861 if (PyObject_SetAttrString(result, "name", value) == -1)
2862 goto failed;
2863 Py_DECREF(value);
2864 value = ast2obj_list(o->body, ast2obj_stmt);
2865 if (!value) goto failed;
2866 if (PyObject_SetAttrString(result, "body", value) == -1)
2867 goto failed;
2868 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002869 value = ast2obj_int(o->lineno);
2870 if (!value) goto failed;
2871 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2872 goto failed;
2873 Py_DECREF(value);
2874 value = ast2obj_int(o->col_offset);
2875 if (!value) goto failed;
2876 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2877 goto failed;
2878 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002879 return result;
2880failed:
2881 Py_XDECREF(value);
2882 Py_XDECREF(result);
2883 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002884}
2885
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002886PyObject*
2887ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002888{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002889 arguments_ty o = (arguments_ty)_o;
2890 PyObject *result = NULL, *value = NULL;
2891 if (!o) {
2892 Py_INCREF(Py_None);
2893 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002894 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002895
2896 result = PyType_GenericNew(arguments_type, NULL, NULL);
2897 if (!result) return NULL;
2898 value = ast2obj_list(o->args, ast2obj_expr);
2899 if (!value) goto failed;
2900 if (PyObject_SetAttrString(result, "args", value) == -1)
2901 goto failed;
2902 Py_DECREF(value);
2903 value = ast2obj_identifier(o->vararg);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2906 goto failed;
2907 Py_DECREF(value);
2908 value = ast2obj_identifier(o->kwarg);
2909 if (!value) goto failed;
2910 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2911 goto failed;
2912 Py_DECREF(value);
2913 value = ast2obj_list(o->defaults, ast2obj_expr);
2914 if (!value) goto failed;
2915 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2916 goto failed;
2917 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002918 return result;
2919failed:
2920 Py_XDECREF(value);
2921 Py_XDECREF(result);
2922 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923}
2924
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002925PyObject*
2926ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002927{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002928 keyword_ty o = (keyword_ty)_o;
2929 PyObject *result = NULL, *value = NULL;
2930 if (!o) {
2931 Py_INCREF(Py_None);
2932 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002933 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934
2935 result = PyType_GenericNew(keyword_type, NULL, NULL);
2936 if (!result) return NULL;
2937 value = ast2obj_identifier(o->arg);
2938 if (!value) goto failed;
2939 if (PyObject_SetAttrString(result, "arg", value) == -1)
2940 goto failed;
2941 Py_DECREF(value);
2942 value = ast2obj_expr(o->value);
2943 if (!value) goto failed;
2944 if (PyObject_SetAttrString(result, "value", value) == -1)
2945 goto failed;
2946 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002947 return result;
2948failed:
2949 Py_XDECREF(value);
2950 Py_XDECREF(result);
2951 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002952}
2953
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002954PyObject*
2955ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002956{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002957 alias_ty o = (alias_ty)_o;
2958 PyObject *result = NULL, *value = NULL;
2959 if (!o) {
2960 Py_INCREF(Py_None);
2961 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002962 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002963
2964 result = PyType_GenericNew(alias_type, NULL, NULL);
2965 if (!result) return NULL;
2966 value = ast2obj_identifier(o->name);
2967 if (!value) goto failed;
2968 if (PyObject_SetAttrString(result, "name", value) == -1)
2969 goto failed;
2970 Py_DECREF(value);
2971 value = ast2obj_identifier(o->asname);
2972 if (!value) goto failed;
2973 if (PyObject_SetAttrString(result, "asname", value) == -1)
2974 goto failed;
2975 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002976 return result;
2977failed:
2978 Py_XDECREF(value);
2979 Py_XDECREF(result);
2980 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002981}
2982
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002983
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002984PyMODINIT_FUNC
2985init_ast(void)
2986{
2987 PyObject *m, *d;
2988 if (!init_types()) return;
2989 m = Py_InitModule3("_ast", NULL, NULL);
2990 if (!m) return;
2991 d = PyModule_GetDict(m);
2992 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
2993 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
2994 return;
Georg Brandl17ab9a02006-08-28 16:38:22 +00002995 if (PyModule_AddStringConstant(m, "__version__", "51631") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00002996 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002997 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
2998 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
2999 return;
3000 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3001 < 0) return;
3002 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3003 0) return;
3004 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3005 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3006 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3007 < 0) return;
3008 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3009 return;
3010 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3011 return;
3012 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3013 return;
3014 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3015 return;
3016 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3017 0) return;
3018 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3019 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3020 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3021 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3022 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3023 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3024 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3025 0) return;
3026 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3027 0) return;
3028 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3029 return;
3030 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3031 return;
3032 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3033 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003034 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3035 return;
3036 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3037 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3038 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3040 return;
3041 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3042 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3043 return;
3044 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3045 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3046 return;
3047 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3048 return;
3049 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3050 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003051 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003052 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3053 return;
3054 if (PyDict_SetItemString(d, "GeneratorExp",
3055 (PyObject*)GeneratorExp_type) < 0) return;
3056 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3057 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3058 return;
3059 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003060 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3061 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3062 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3063 0) return;
3064 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3065 0) return;
3066 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3067 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3068 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3069 if (PyDict_SetItemString(d, "expr_context",
3070 (PyObject*)expr_context_type) < 0) return;
3071 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3072 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3073 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3074 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3075 return;
3076 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3077 return;
3078 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3079 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3080 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3081 return;
3082 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3083 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3084 return;
3085 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3086 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3087 return;
3088 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3089 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3090 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3091 return;
3092 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3093 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3094 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3095 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3096 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3097 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3098 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3099 return;
3100 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3103 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3104 return;
3105 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3106 return;
3107 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3108 return;
3109 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3110 return;
3111 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3114 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3115 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3116 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3117 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3118 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3120 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3121 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3122 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3123 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3124 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3125 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3126 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3127 if (PyDict_SetItemString(d, "comprehension",
3128 (PyObject*)comprehension_type) < 0) return;
3129 if (PyDict_SetItemString(d, "excepthandler",
3130 (PyObject*)excepthandler_type) < 0) return;
3131 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3132 0) return;
3133 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3134 return;
3135 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003136}
3137
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003138
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003139PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003140{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003141 init_types();
3142 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003143}
3144
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003145