blob: b322039a48c80a75c247adf5a72e8f9f41226b04 [file] [log] [blame]
Neal Norwitz897ff812005-12-11 21:18:22 +00001/* File automatically generated by Parser/asdl_c.py */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
3#include "Python.h"
4#include "Python-ast.h"
5
Neal Norwitz53d960c2006-02-28 22:47:29 +00006static PyTypeObject* AST_type;
7static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +00009static PyTypeObject *Module_type;
10static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000011 "body",
12};
Neal Norwitz53d960c2006-02-28 22:47:29 +000013static PyTypeObject *Interactive_type;
14static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000015 "body",
16};
Neal Norwitz53d960c2006-02-28 22:47:29 +000017static PyTypeObject *Expression_type;
18static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000019 "body",
20};
Neal Norwitz53d960c2006-02-28 22:47:29 +000021static PyTypeObject *Suite_type;
22static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000023 "body",
24};
Neal Norwitz53d960c2006-02-28 22:47:29 +000025static PyTypeObject *stmt_type;
26static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000027 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000028 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000029};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000030static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000031static PyTypeObject *FunctionDef_type;
32static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000033 "name",
34 "args",
35 "body",
36 "decorators",
37};
Neal Norwitz53d960c2006-02-28 22:47:29 +000038static PyTypeObject *ClassDef_type;
39static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000040 "name",
41 "bases",
42 "body",
43};
Neal Norwitz53d960c2006-02-28 22:47:29 +000044static PyTypeObject *Return_type;
45static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000046 "value",
47};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *Delete_type;
49static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "targets",
51};
Neal Norwitz53d960c2006-02-28 22:47:29 +000052static PyTypeObject *Assign_type;
53static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000054 "targets",
55 "value",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *AugAssign_type;
58static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "target",
60 "op",
61 "value",
62};
Neal Norwitz53d960c2006-02-28 22:47:29 +000063static PyTypeObject *Print_type;
64static char *Print_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000065 "dest",
66 "values",
67 "nl",
68};
Neal Norwitz53d960c2006-02-28 22:47:29 +000069static PyTypeObject *For_type;
70static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000071 "target",
72 "iter",
73 "body",
74 "orelse",
75};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *While_type;
77static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000078 "test",
79 "body",
80 "orelse",
81};
Neal Norwitz53d960c2006-02-28 22:47:29 +000082static PyTypeObject *If_type;
83static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000084 "test",
85 "body",
86 "orelse",
87};
Neal Norwitz53d960c2006-02-28 22:47:29 +000088static PyTypeObject *With_type;
89static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000090 "context_expr",
91 "optional_vars",
92 "body",
93};
Neal Norwitz53d960c2006-02-28 22:47:29 +000094static PyTypeObject *Raise_type;
95static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000096 "type",
97 "inst",
98 "tback",
99};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000100static PyTypeObject *TryExcept_type;
101static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000102 "body",
103 "handlers",
104 "orelse",
105};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000106static PyTypeObject *TryFinally_type;
107static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000108 "body",
109 "finalbody",
110};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000111static PyTypeObject *Assert_type;
112static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000113 "test",
114 "msg",
115};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000116static PyTypeObject *Import_type;
117static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000118 "names",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *ImportFrom_type;
121static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "module",
123 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000124 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000125};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000126static PyTypeObject *Exec_type;
127static char *Exec_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000128 "body",
129 "globals",
130 "locals",
131};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000132static PyTypeObject *Global_type;
133static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000134 "names",
135};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000136static PyTypeObject *Expr_type;
137static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000138 "value",
139};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000140static PyTypeObject *Pass_type;
141static PyTypeObject *Break_type;
142static PyTypeObject *Continue_type;
143static PyTypeObject *expr_type;
144static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000145 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000146 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000147};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000148static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *BoolOp_type;
150static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000151 "op",
152 "values",
153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *BinOp_type;
155static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "left",
157 "op",
158 "right",
159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *UnaryOp_type;
161static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000162 "op",
163 "operand",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *Lambda_type;
166static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "args",
168 "body",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *IfExp_type;
171static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000172 "test",
173 "body",
174 "orelse",
175};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000176static PyTypeObject *Dict_type;
177static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000178 "keys",
179 "values",
180};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000181static PyTypeObject *Set_type;
182static char *Set_fields[]={
183 "elts",
184};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000185static PyTypeObject *ListComp_type;
186static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000187 "elt",
188 "generators",
189};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000190static PyTypeObject *GeneratorExp_type;
191static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000192 "elt",
193 "generators",
194};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000195static PyTypeObject *Yield_type;
196static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000197 "value",
198};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000199static PyTypeObject *Compare_type;
200static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000201 "left",
202 "ops",
203 "comparators",
204};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000205static PyTypeObject *Call_type;
206static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000207 "func",
208 "args",
209 "keywords",
210 "starargs",
211 "kwargs",
212};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000213static PyTypeObject *Num_type;
214static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000215 "n",
216};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Str_type;
218static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "s",
220};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000221static PyTypeObject *Attribute_type;
222static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000223 "value",
224 "attr",
225 "ctx",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Subscript_type;
228static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "value",
230 "slice",
231 "ctx",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *Name_type;
234static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "id",
236 "ctx",
237};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000238static PyTypeObject *List_type;
239static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000240 "elts",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Tuple_type;
244static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "elts",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
250*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
251static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000252static PyTypeObject *Load_type;
253static PyTypeObject *Store_type;
254static PyTypeObject *Del_type;
255static PyTypeObject *AugLoad_type;
256static PyTypeObject *AugStore_type;
257static PyTypeObject *Param_type;
258static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000260static PyTypeObject *Ellipsis_type;
261static PyTypeObject *Slice_type;
262static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000263 "lower",
264 "upper",
265 "step",
266};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *ExtSlice_type;
268static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269 "dims",
270};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000271static PyTypeObject *Index_type;
272static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000273 "value",
274};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000276static PyObject *And_singleton, *Or_singleton;
277static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000278static PyTypeObject *And_type;
279static PyTypeObject *Or_type;
280static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000281static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
282*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
283*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
284*FloorDiv_singleton;
285static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000286static PyTypeObject *Add_type;
287static PyTypeObject *Sub_type;
288static PyTypeObject *Mult_type;
289static PyTypeObject *Div_type;
290static PyTypeObject *Mod_type;
291static PyTypeObject *Pow_type;
292static PyTypeObject *LShift_type;
293static PyTypeObject *RShift_type;
294static PyTypeObject *BitOr_type;
295static PyTypeObject *BitXor_type;
296static PyTypeObject *BitAnd_type;
297static PyTypeObject *FloorDiv_type;
298static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000299static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
300*USub_singleton;
301static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000302static PyTypeObject *Invert_type;
303static PyTypeObject *Not_type;
304static PyTypeObject *UAdd_type;
305static PyTypeObject *USub_type;
306static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000307static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
308*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
309*NotIn_singleton;
310static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Eq_type;
312static PyTypeObject *NotEq_type;
313static PyTypeObject *Lt_type;
314static PyTypeObject *LtE_type;
315static PyTypeObject *Gt_type;
316static PyTypeObject *GtE_type;
317static PyTypeObject *Is_type;
318static PyTypeObject *IsNot_type;
319static PyTypeObject *In_type;
320static PyTypeObject *NotIn_type;
321static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000322static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000323static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324 "target",
325 "iter",
326 "ifs",
327};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331 "type",
332 "name",
333 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000334 "lineno",
335 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000339static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340 "args",
341 "vararg",
342 "kwarg",
343 "defaults",
344};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000345static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000347static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348 "arg",
349 "value",
350};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000351static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000353static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000354 "name",
355 "asname",
356};
357
358
359static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
360{
361 PyObject *fnames, *result;
362 int i;
363 if (num_fields) {
364 fnames = PyTuple_New(num_fields);
365 if (!fnames) return NULL;
366 } else {
367 fnames = Py_None;
368 Py_INCREF(Py_None);
369 }
370 for(i=0; i < num_fields; i++) {
371 PyObject *field = PyString_FromString(fields[i]);
372 if (!field) {
373 Py_DECREF(fnames);
374 return NULL;
375 }
376 PyTuple_SET_ITEM(fnames, i, field);
377 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000378 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000379 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000380 Py_DECREF(fnames);
381 return (PyTypeObject*)result;
382}
383
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000384static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
385{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000386 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000387 PyObject *s, *l = PyList_New(num_fields);
388 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000389 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000390 s = PyString_FromString(attrs[i]);
391 if (!s) {
392 Py_DECREF(l);
393 return 0;
394 }
395 PyList_SET_ITEM(l, i, s);
396 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000397 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
398 Py_DECREF(l);
399 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000400}
401
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000402static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
403{
404 int i, n = asdl_seq_LEN(seq);
405 PyObject *result = PyList_New(n);
406 PyObject *value;
407 if (!result)
408 return NULL;
409 for (i = 0; i < n; i++) {
410 value = func(asdl_seq_GET(seq, i));
411 if (!value) {
412 Py_DECREF(result);
413 return NULL;
414 }
415 PyList_SET_ITEM(result, i, value);
416 }
417 return result;
418}
419
420static PyObject* ast2obj_object(void *o)
421{
422 if (!o)
423 o = Py_None;
424 Py_INCREF((PyObject*)o);
425 return (PyObject*)o;
426}
427#define ast2obj_identifier ast2obj_object
428#define ast2obj_string ast2obj_object
429static PyObject* ast2obj_bool(bool b)
430{
431 return PyBool_FromLong(b);
432}
433
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000434static PyObject* ast2obj_int(bool b)
435{
436 return PyInt_FromLong(b);
437}
438
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000439static int init_types(void)
440{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000441 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000442 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000443 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
444 mod_type = make_type("mod", AST_type, NULL, 0);
445 if (!mod_type) return 0;
446 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000447 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000448 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000449 Interactive_type = make_type("Interactive", mod_type,
450 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000451 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000452 Expression_type = make_type("Expression", mod_type, Expression_fields,
453 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000454 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000455 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000456 if (!Suite_type) return 0;
457 stmt_type = make_type("stmt", AST_type, NULL, 0);
458 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000459 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000460 FunctionDef_type = make_type("FunctionDef", stmt_type,
461 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000481 With_type = make_type("With", stmt_type, With_fields, 3);
482 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000484 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000487 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
488 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000495 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000503 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000505 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000507 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Continue_type) return 0;
509 expr_type = make_type("expr", AST_type, NULL, 0);
510 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000511 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000520 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000524 Set_type = make_type("Set", expr_type, Set_fields, 1);
525 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000528 GeneratorExp_type = make_type("GeneratorExp", expr_type,
529 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Str_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000547 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!Tuple_type) return 0;
551 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
552 if (!expr_context_type) return 0;
553 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000554 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000558 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000562 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000566 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000570 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000574 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000575 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000576 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!Param_singleton) return 0;
578 slice_type = make_type("slice", AST_type, NULL, 0);
579 if (!slice_type) return 0;
580 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000581 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Index_type) return 0;
589 boolop_type = make_type("boolop", AST_type, NULL, 0);
590 if (!boolop_type) return 0;
591 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000592 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000596 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Or_singleton) return 0;
600 operator_type = make_type("operator", AST_type, NULL, 0);
601 if (!operator_type) return 0;
602 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000615 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000647 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000649 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!FloorDiv_singleton) return 0;
651 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
652 if (!unaryop_type) return 0;
653 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000666 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!USub_singleton) return 0;
670 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
671 if (!cmpop_type) return 0;
672 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000705 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000707 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000709 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000711 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!NotIn_singleton) return 0;
713 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000714 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!comprehension_type) return 0;
716 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000717 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!excepthandler_type) return 0;
719 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
720 if (!arguments_type) return 0;
721 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
722 if (!keyword_type) return 0;
723 alias_type = make_type("alias", AST_type, alias_fields, 2);
724 if (!alias_type) return 0;
725 initialized = 1;
726 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000727}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000728
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000729mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000730Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000731{
732 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000733 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000734 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000735 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000736 return NULL;
737 }
738 p->kind = Module_kind;
739 p->v.Module.body = body;
740 return p;
741}
742
743mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000744Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000745{
746 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000747 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000748 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000749 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000750 return NULL;
751 }
752 p->kind = Interactive_kind;
753 p->v.Interactive.body = body;
754 return p;
755}
756
757mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000758Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759{
760 mod_ty p;
761 if (!body) {
762 PyErr_SetString(PyExc_ValueError,
763 "field body is required for Expression");
764 return NULL;
765 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000766 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000768 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000769 return NULL;
770 }
771 p->kind = Expression_kind;
772 p->v.Expression.body = body;
773 return p;
774}
775
776mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000777Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778{
779 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000780 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000781 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000782 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783 return NULL;
784 }
785 p->kind = Suite_kind;
786 p->v.Suite.body = body;
787 return p;
788}
789
790stmt_ty
791FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000792 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000793{
794 stmt_ty p;
795 if (!name) {
796 PyErr_SetString(PyExc_ValueError,
797 "field name is required for FunctionDef");
798 return NULL;
799 }
800 if (!args) {
801 PyErr_SetString(PyExc_ValueError,
802 "field args is required for FunctionDef");
803 return NULL;
804 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000805 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000806 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000807 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000808 return NULL;
809 }
810 p->kind = FunctionDef_kind;
811 p->v.FunctionDef.name = name;
812 p->v.FunctionDef.args = args;
813 p->v.FunctionDef.body = body;
814 p->v.FunctionDef.decorators = decorators;
815 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000816 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817 return p;
818}
819
820stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000821ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
822 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000823{
824 stmt_ty p;
825 if (!name) {
826 PyErr_SetString(PyExc_ValueError,
827 "field name is required for ClassDef");
828 return NULL;
829 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000830 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000831 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000832 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000833 return NULL;
834 }
835 p->kind = ClassDef_kind;
836 p->v.ClassDef.name = name;
837 p->v.ClassDef.bases = bases;
838 p->v.ClassDef.body = body;
839 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000840 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 return p;
842}
843
844stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000845Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000846{
847 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000848 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000850 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851 return NULL;
852 }
853 p->kind = Return_kind;
854 p->v.Return.value = value;
855 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000856 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000857 return p;
858}
859
860stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000861Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000862{
863 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000864 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000866 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 return NULL;
868 }
869 p->kind = Delete_kind;
870 p->v.Delete.targets = targets;
871 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000872 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873 return p;
874}
875
876stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000877Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
878 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000879{
880 stmt_ty p;
881 if (!value) {
882 PyErr_SetString(PyExc_ValueError,
883 "field value is required for Assign");
884 return NULL;
885 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000886 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000888 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000889 return NULL;
890 }
891 p->kind = Assign_kind;
892 p->v.Assign.targets = targets;
893 p->v.Assign.value = value;
894 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000895 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896 return p;
897}
898
899stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000900AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
901 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000902{
903 stmt_ty p;
904 if (!target) {
905 PyErr_SetString(PyExc_ValueError,
906 "field target is required for AugAssign");
907 return NULL;
908 }
909 if (!op) {
910 PyErr_SetString(PyExc_ValueError,
911 "field op is required for AugAssign");
912 return NULL;
913 }
914 if (!value) {
915 PyErr_SetString(PyExc_ValueError,
916 "field value is required for AugAssign");
917 return NULL;
918 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000919 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000920 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000921 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000922 return NULL;
923 }
924 p->kind = AugAssign_kind;
925 p->v.AugAssign.target = target;
926 p->v.AugAssign.op = op;
927 p->v.AugAssign.value = value;
928 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000929 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930 return p;
931}
932
933stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000934Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
935 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000936{
937 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000938 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000939 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000940 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941 return NULL;
942 }
943 p->kind = Print_kind;
944 p->v.Print.dest = dest;
945 p->v.Print.values = values;
946 p->v.Print.nl = nl;
947 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000948 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949 return p;
950}
951
952stmt_ty
953For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000954 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955{
956 stmt_ty p;
957 if (!target) {
958 PyErr_SetString(PyExc_ValueError,
959 "field target is required for For");
960 return NULL;
961 }
962 if (!iter) {
963 PyErr_SetString(PyExc_ValueError,
964 "field iter is required for For");
965 return NULL;
966 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000967 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000968 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000969 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000970 return NULL;
971 }
972 p->kind = For_kind;
973 p->v.For.target = target;
974 p->v.For.iter = iter;
975 p->v.For.body = body;
976 p->v.For.orelse = orelse;
977 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000978 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 return p;
980}
981
982stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000983While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
984 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985{
986 stmt_ty p;
987 if (!test) {
988 PyErr_SetString(PyExc_ValueError,
989 "field test is required for While");
990 return NULL;
991 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000992 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000993 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000994 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000995 return NULL;
996 }
997 p->kind = While_kind;
998 p->v.While.test = test;
999 p->v.While.body = body;
1000 p->v.While.orelse = orelse;
1001 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001002 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003 return p;
1004}
1005
1006stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001007If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1008 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009{
1010 stmt_ty p;
1011 if (!test) {
1012 PyErr_SetString(PyExc_ValueError,
1013 "field test is required for If");
1014 return NULL;
1015 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001016 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001017 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001018 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001019 return NULL;
1020 }
1021 p->kind = If_kind;
1022 p->v.If.test = test;
1023 p->v.If.body = body;
1024 p->v.If.orelse = orelse;
1025 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001026 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001027 return p;
1028}
1029
1030stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001031With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001032 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001033{
1034 stmt_ty p;
1035 if (!context_expr) {
1036 PyErr_SetString(PyExc_ValueError,
1037 "field context_expr is required for With");
1038 return NULL;
1039 }
1040 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1041 if (!p) {
1042 PyErr_NoMemory();
1043 return NULL;
1044 }
1045 p->kind = With_kind;
1046 p->v.With.context_expr = context_expr;
1047 p->v.With.optional_vars = optional_vars;
1048 p->v.With.body = body;
1049 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001050 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001051 return p;
1052}
1053
1054stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001055Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1056 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001057{
1058 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001059 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001060 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001061 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 return NULL;
1063 }
1064 p->kind = Raise_kind;
1065 p->v.Raise.type = type;
1066 p->v.Raise.inst = inst;
1067 p->v.Raise.tback = tback;
1068 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001069 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070 return p;
1071}
1072
1073stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001074TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001075 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076{
1077 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001078 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001080 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081 return NULL;
1082 }
1083 p->kind = TryExcept_kind;
1084 p->v.TryExcept.body = body;
1085 p->v.TryExcept.handlers = handlers;
1086 p->v.TryExcept.orelse = orelse;
1087 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001088 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089 return p;
1090}
1091
1092stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001093TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1094 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095{
1096 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001097 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001099 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001100 return NULL;
1101 }
1102 p->kind = TryFinally_kind;
1103 p->v.TryFinally.body = body;
1104 p->v.TryFinally.finalbody = finalbody;
1105 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001106 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107 return p;
1108}
1109
1110stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001111Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001112{
1113 stmt_ty p;
1114 if (!test) {
1115 PyErr_SetString(PyExc_ValueError,
1116 "field test is required for Assert");
1117 return NULL;
1118 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001119 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001121 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return NULL;
1123 }
1124 p->kind = Assert_kind;
1125 p->v.Assert.test = test;
1126 p->v.Assert.msg = msg;
1127 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001128 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 return p;
1130}
1131
1132stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001133Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001134{
1135 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001136 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001138 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001139 return NULL;
1140 }
1141 p->kind = Import_kind;
1142 p->v.Import.names = names;
1143 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001144 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 return p;
1146}
1147
1148stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001149ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1150 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151{
1152 stmt_ty p;
1153 if (!module) {
1154 PyErr_SetString(PyExc_ValueError,
1155 "field module is required for ImportFrom");
1156 return NULL;
1157 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001158 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001160 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 return NULL;
1162 }
1163 p->kind = ImportFrom_kind;
1164 p->v.ImportFrom.module = module;
1165 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001166 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001168 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169 return p;
1170}
1171
1172stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001173Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1174 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001175{
1176 stmt_ty p;
1177 if (!body) {
1178 PyErr_SetString(PyExc_ValueError,
1179 "field body is required for Exec");
1180 return NULL;
1181 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001182 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001184 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001185 return NULL;
1186 }
1187 p->kind = Exec_kind;
1188 p->v.Exec.body = body;
1189 p->v.Exec.globals = globals;
1190 p->v.Exec.locals = locals;
1191 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001192 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001193 return p;
1194}
1195
1196stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001197Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001198{
1199 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001200 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001202 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203 return NULL;
1204 }
1205 p->kind = Global_kind;
1206 p->v.Global.names = names;
1207 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001208 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209 return p;
1210}
1211
1212stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001213Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214{
1215 stmt_ty p;
1216 if (!value) {
1217 PyErr_SetString(PyExc_ValueError,
1218 "field value is required for Expr");
1219 return NULL;
1220 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001221 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001223 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001224 return NULL;
1225 }
1226 p->kind = Expr_kind;
1227 p->v.Expr.value = value;
1228 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001229 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230 return p;
1231}
1232
1233stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001234Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235{
1236 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001237 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001238 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001239 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001240 return NULL;
1241 }
1242 p->kind = Pass_kind;
1243 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001244 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001245 return p;
1246}
1247
1248stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001249Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250{
1251 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001252 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001253 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001254 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001255 return NULL;
1256 }
1257 p->kind = Break_kind;
1258 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001259 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001260 return p;
1261}
1262
1263stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001264Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001265{
1266 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001267 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001268 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001269 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001270 return NULL;
1271 }
1272 p->kind = Continue_kind;
1273 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001274 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001275 return p;
1276}
1277
1278expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001279BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1280 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001281{
1282 expr_ty p;
1283 if (!op) {
1284 PyErr_SetString(PyExc_ValueError,
1285 "field op is required for BoolOp");
1286 return NULL;
1287 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001288 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001289 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001290 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001291 return NULL;
1292 }
1293 p->kind = BoolOp_kind;
1294 p->v.BoolOp.op = op;
1295 p->v.BoolOp.values = values;
1296 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001297 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001298 return p;
1299}
1300
1301expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001302BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1303 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001304{
1305 expr_ty p;
1306 if (!left) {
1307 PyErr_SetString(PyExc_ValueError,
1308 "field left is required for BinOp");
1309 return NULL;
1310 }
1311 if (!op) {
1312 PyErr_SetString(PyExc_ValueError,
1313 "field op is required for BinOp");
1314 return NULL;
1315 }
1316 if (!right) {
1317 PyErr_SetString(PyExc_ValueError,
1318 "field right is required for BinOp");
1319 return NULL;
1320 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001321 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001322 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001323 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001324 return NULL;
1325 }
1326 p->kind = BinOp_kind;
1327 p->v.BinOp.left = left;
1328 p->v.BinOp.op = op;
1329 p->v.BinOp.right = right;
1330 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001331 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001332 return p;
1333}
1334
1335expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001336UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1337 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001338{
1339 expr_ty p;
1340 if (!op) {
1341 PyErr_SetString(PyExc_ValueError,
1342 "field op is required for UnaryOp");
1343 return NULL;
1344 }
1345 if (!operand) {
1346 PyErr_SetString(PyExc_ValueError,
1347 "field operand is required for UnaryOp");
1348 return NULL;
1349 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001350 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001352 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001353 return NULL;
1354 }
1355 p->kind = UnaryOp_kind;
1356 p->v.UnaryOp.op = op;
1357 p->v.UnaryOp.operand = operand;
1358 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001359 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001360 return p;
1361}
1362
1363expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001364Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1365 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001366{
1367 expr_ty p;
1368 if (!args) {
1369 PyErr_SetString(PyExc_ValueError,
1370 "field args is required for Lambda");
1371 return NULL;
1372 }
1373 if (!body) {
1374 PyErr_SetString(PyExc_ValueError,
1375 "field body is required for Lambda");
1376 return NULL;
1377 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001378 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001379 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001380 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001381 return NULL;
1382 }
1383 p->kind = Lambda_kind;
1384 p->v.Lambda.args = args;
1385 p->v.Lambda.body = body;
1386 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001387 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001388 return p;
1389}
1390
1391expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001392IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1393 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001394{
1395 expr_ty p;
1396 if (!test) {
1397 PyErr_SetString(PyExc_ValueError,
1398 "field test is required for IfExp");
1399 return NULL;
1400 }
1401 if (!body) {
1402 PyErr_SetString(PyExc_ValueError,
1403 "field body is required for IfExp");
1404 return NULL;
1405 }
1406 if (!orelse) {
1407 PyErr_SetString(PyExc_ValueError,
1408 "field orelse is required for IfExp");
1409 return NULL;
1410 }
1411 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1412 if (!p) {
1413 PyErr_NoMemory();
1414 return NULL;
1415 }
1416 p->kind = IfExp_kind;
1417 p->v.IfExp.test = test;
1418 p->v.IfExp.body = body;
1419 p->v.IfExp.orelse = orelse;
1420 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001421 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001422 return p;
1423}
1424
1425expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001426Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1427 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001428{
1429 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001430 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001431 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001432 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001433 return NULL;
1434 }
1435 p->kind = Dict_kind;
1436 p->v.Dict.keys = keys;
1437 p->v.Dict.values = values;
1438 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001439 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440 return p;
1441}
1442
1443expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001444Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1445{
1446 expr_ty p;
1447 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1448 if (!p) {
1449 PyErr_NoMemory();
1450 return NULL;
1451 }
1452 p->kind = Set_kind;
1453 p->v.Set.elts = elts;
1454 p->lineno = lineno;
1455 p->col_offset = col_offset;
1456 return p;
1457}
1458
1459expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001460ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1461 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001462{
1463 expr_ty p;
1464 if (!elt) {
1465 PyErr_SetString(PyExc_ValueError,
1466 "field elt is required for ListComp");
1467 return NULL;
1468 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001469 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001470 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001471 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472 return NULL;
1473 }
1474 p->kind = ListComp_kind;
1475 p->v.ListComp.elt = elt;
1476 p->v.ListComp.generators = generators;
1477 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001478 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479 return p;
1480}
1481
1482expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001483GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1484 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001485{
1486 expr_ty p;
1487 if (!elt) {
1488 PyErr_SetString(PyExc_ValueError,
1489 "field elt is required for GeneratorExp");
1490 return NULL;
1491 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001492 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001493 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001494 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001495 return NULL;
1496 }
1497 p->kind = GeneratorExp_kind;
1498 p->v.GeneratorExp.elt = elt;
1499 p->v.GeneratorExp.generators = generators;
1500 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001501 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001502 return p;
1503}
1504
1505expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001506Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001507{
1508 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001509 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001511 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001512 return NULL;
1513 }
1514 p->kind = Yield_kind;
1515 p->v.Yield.value = value;
1516 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001517 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518 return p;
1519}
1520
1521expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001522Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1523 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524{
1525 expr_ty p;
1526 if (!left) {
1527 PyErr_SetString(PyExc_ValueError,
1528 "field left is required for Compare");
1529 return NULL;
1530 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001531 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001533 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001534 return NULL;
1535 }
1536 p->kind = Compare_kind;
1537 p->v.Compare.left = left;
1538 p->v.Compare.ops = ops;
1539 p->v.Compare.comparators = comparators;
1540 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001541 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542 return p;
1543}
1544
1545expr_ty
1546Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001547 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548{
1549 expr_ty p;
1550 if (!func) {
1551 PyErr_SetString(PyExc_ValueError,
1552 "field func is required for Call");
1553 return NULL;
1554 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001555 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001556 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001557 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001558 return NULL;
1559 }
1560 p->kind = Call_kind;
1561 p->v.Call.func = func;
1562 p->v.Call.args = args;
1563 p->v.Call.keywords = keywords;
1564 p->v.Call.starargs = starargs;
1565 p->v.Call.kwargs = kwargs;
1566 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001567 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001568 return p;
1569}
1570
1571expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001572Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001573{
1574 expr_ty p;
1575 if (!n) {
1576 PyErr_SetString(PyExc_ValueError,
1577 "field n is required for Num");
1578 return NULL;
1579 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001580 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001581 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001582 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001583 return NULL;
1584 }
1585 p->kind = Num_kind;
1586 p->v.Num.n = n;
1587 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001588 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001589 return p;
1590}
1591
1592expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001593Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594{
1595 expr_ty p;
1596 if (!s) {
1597 PyErr_SetString(PyExc_ValueError,
1598 "field s is required for Str");
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 = Str_kind;
1607 p->v.Str.s = s;
1608 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001609 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001610 return p;
1611}
1612
1613expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001614Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1615 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001616{
1617 expr_ty p;
1618 if (!value) {
1619 PyErr_SetString(PyExc_ValueError,
1620 "field value is required for Attribute");
1621 return NULL;
1622 }
1623 if (!attr) {
1624 PyErr_SetString(PyExc_ValueError,
1625 "field attr is required for Attribute");
1626 return NULL;
1627 }
1628 if (!ctx) {
1629 PyErr_SetString(PyExc_ValueError,
1630 "field ctx is required for Attribute");
1631 return NULL;
1632 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001633 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001634 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001635 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001636 return NULL;
1637 }
1638 p->kind = Attribute_kind;
1639 p->v.Attribute.value = value;
1640 p->v.Attribute.attr = attr;
1641 p->v.Attribute.ctx = ctx;
1642 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001643 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001644 return p;
1645}
1646
1647expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001648Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1649 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001650{
1651 expr_ty p;
1652 if (!value) {
1653 PyErr_SetString(PyExc_ValueError,
1654 "field value is required for Subscript");
1655 return NULL;
1656 }
1657 if (!slice) {
1658 PyErr_SetString(PyExc_ValueError,
1659 "field slice is required for Subscript");
1660 return NULL;
1661 }
1662 if (!ctx) {
1663 PyErr_SetString(PyExc_ValueError,
1664 "field ctx is required for Subscript");
1665 return NULL;
1666 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001667 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001669 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001670 return NULL;
1671 }
1672 p->kind = Subscript_kind;
1673 p->v.Subscript.value = value;
1674 p->v.Subscript.slice = slice;
1675 p->v.Subscript.ctx = ctx;
1676 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001677 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001678 return p;
1679}
1680
1681expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001682Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1683 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684{
1685 expr_ty p;
1686 if (!id) {
1687 PyErr_SetString(PyExc_ValueError,
1688 "field id is required for Name");
1689 return NULL;
1690 }
1691 if (!ctx) {
1692 PyErr_SetString(PyExc_ValueError,
1693 "field ctx is required for Name");
1694 return NULL;
1695 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001696 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001698 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001699 return NULL;
1700 }
1701 p->kind = Name_kind;
1702 p->v.Name.id = id;
1703 p->v.Name.ctx = ctx;
1704 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001705 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706 return p;
1707}
1708
1709expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001710List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1711 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001712{
1713 expr_ty p;
1714 if (!ctx) {
1715 PyErr_SetString(PyExc_ValueError,
1716 "field ctx is required for List");
1717 return NULL;
1718 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001719 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001721 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001722 return NULL;
1723 }
1724 p->kind = List_kind;
1725 p->v.List.elts = elts;
1726 p->v.List.ctx = ctx;
1727 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001728 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001729 return p;
1730}
1731
1732expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001733Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1734 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001735{
1736 expr_ty p;
1737 if (!ctx) {
1738 PyErr_SetString(PyExc_ValueError,
1739 "field ctx is required for Tuple");
1740 return NULL;
1741 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001742 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001743 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001744 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001745 return NULL;
1746 }
1747 p->kind = Tuple_kind;
1748 p->v.Tuple.elts = elts;
1749 p->v.Tuple.ctx = ctx;
1750 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001751 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001752 return p;
1753}
1754
1755slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001756Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757{
1758 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001759 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001761 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762 return NULL;
1763 }
1764 p->kind = Ellipsis_kind;
1765 return p;
1766}
1767
1768slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001769Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770{
1771 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001772 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001773 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001774 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001775 return NULL;
1776 }
1777 p->kind = Slice_kind;
1778 p->v.Slice.lower = lower;
1779 p->v.Slice.upper = upper;
1780 p->v.Slice.step = step;
1781 return p;
1782}
1783
1784slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001785ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001786{
1787 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001788 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001789 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001790 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791 return NULL;
1792 }
1793 p->kind = ExtSlice_kind;
1794 p->v.ExtSlice.dims = dims;
1795 return p;
1796}
1797
1798slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001799Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001800{
1801 slice_ty p;
1802 if (!value) {
1803 PyErr_SetString(PyExc_ValueError,
1804 "field value is required for Index");
1805 return NULL;
1806 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001807 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001808 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001809 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001810 return NULL;
1811 }
1812 p->kind = Index_kind;
1813 p->v.Index.value = value;
1814 return p;
1815}
1816
1817comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001818comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001819{
1820 comprehension_ty p;
1821 if (!target) {
1822 PyErr_SetString(PyExc_ValueError,
1823 "field target is required for comprehension");
1824 return NULL;
1825 }
1826 if (!iter) {
1827 PyErr_SetString(PyExc_ValueError,
1828 "field iter is required for comprehension");
1829 return NULL;
1830 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001831 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001832 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001833 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001834 return NULL;
1835 }
1836 p->target = target;
1837 p->iter = iter;
1838 p->ifs = ifs;
1839 return p;
1840}
1841
1842excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001843excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1844 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845{
1846 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001847 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001849 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850 return NULL;
1851 }
1852 p->type = type;
1853 p->name = name;
1854 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001855 p->lineno = lineno;
1856 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857 return p;
1858}
1859
1860arguments_ty
1861arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001862 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863{
1864 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001865 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001867 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868 return NULL;
1869 }
1870 p->args = args;
1871 p->vararg = vararg;
1872 p->kwarg = kwarg;
1873 p->defaults = defaults;
1874 return p;
1875}
1876
1877keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001878keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879{
1880 keyword_ty p;
1881 if (!arg) {
1882 PyErr_SetString(PyExc_ValueError,
1883 "field arg is required for keyword");
1884 return NULL;
1885 }
1886 if (!value) {
1887 PyErr_SetString(PyExc_ValueError,
1888 "field value is required for keyword");
1889 return NULL;
1890 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001891 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001892 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001893 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001894 return NULL;
1895 }
1896 p->arg = arg;
1897 p->value = value;
1898 return p;
1899}
1900
1901alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001902alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001903{
1904 alias_ty p;
1905 if (!name) {
1906 PyErr_SetString(PyExc_ValueError,
1907 "field name is required for alias");
1908 return NULL;
1909 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001910 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001912 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913 return NULL;
1914 }
1915 p->name = name;
1916 p->asname = asname;
1917 return p;
1918}
1919
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001920
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001921PyObject*
1922ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001923{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001924 mod_ty o = (mod_ty)_o;
1925 PyObject *result = NULL, *value = NULL;
1926 if (!o) {
1927 Py_INCREF(Py_None);
1928 return Py_None;
1929 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001930
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931 switch (o->kind) {
1932 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001933 result = PyType_GenericNew(Module_type, NULL, NULL);
1934 if (!result) goto failed;
1935 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1936 if (!value) goto failed;
1937 if (PyObject_SetAttrString(result, "body", value) == -1)
1938 goto failed;
1939 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001940 break;
1941 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001942 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1943 if (!result) goto failed;
1944 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1945 if (!value) goto failed;
1946 if (PyObject_SetAttrString(result, "body", value) == -1)
1947 goto failed;
1948 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001949 break;
1950 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001951 result = PyType_GenericNew(Expression_type, NULL, NULL);
1952 if (!result) goto failed;
1953 value = ast2obj_expr(o->v.Expression.body);
1954 if (!value) goto failed;
1955 if (PyObject_SetAttrString(result, "body", value) == -1)
1956 goto failed;
1957 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001958 break;
1959 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001960 result = PyType_GenericNew(Suite_type, NULL, NULL);
1961 if (!result) goto failed;
1962 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1963 if (!value) goto failed;
1964 if (PyObject_SetAttrString(result, "body", value) == -1)
1965 goto failed;
1966 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001967 break;
1968 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001969 return result;
1970failed:
1971 Py_XDECREF(value);
1972 Py_XDECREF(result);
1973 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001974}
1975
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001976PyObject*
1977ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001979 stmt_ty o = (stmt_ty)_o;
1980 PyObject *result = NULL, *value = NULL;
1981 if (!o) {
1982 Py_INCREF(Py_None);
1983 return Py_None;
1984 }
1985
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001986 switch (o->kind) {
1987 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001988 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1989 if (!result) goto failed;
1990 value = ast2obj_identifier(o->v.FunctionDef.name);
1991 if (!value) goto failed;
1992 if (PyObject_SetAttrString(result, "name", value) == -1)
1993 goto failed;
1994 Py_DECREF(value);
1995 value = ast2obj_arguments(o->v.FunctionDef.args);
1996 if (!value) goto failed;
1997 if (PyObject_SetAttrString(result, "args", value) == -1)
1998 goto failed;
1999 Py_DECREF(value);
2000 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2001 if (!value) goto failed;
2002 if (PyObject_SetAttrString(result, "body", value) == -1)
2003 goto failed;
2004 Py_DECREF(value);
2005 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2006 if (!value) goto failed;
2007 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2008 goto failed;
2009 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002010 break;
2011 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002012 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2013 if (!result) goto failed;
2014 value = ast2obj_identifier(o->v.ClassDef.name);
2015 if (!value) goto failed;
2016 if (PyObject_SetAttrString(result, "name", value) == -1)
2017 goto failed;
2018 Py_DECREF(value);
2019 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "bases", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
2024 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2025 if (!value) goto failed;
2026 if (PyObject_SetAttrString(result, "body", value) == -1)
2027 goto failed;
2028 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002029 break;
2030 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002031 result = PyType_GenericNew(Return_type, NULL, NULL);
2032 if (!result) goto failed;
2033 value = ast2obj_expr(o->v.Return.value);
2034 if (!value) goto failed;
2035 if (PyObject_SetAttrString(result, "value", value) == -1)
2036 goto failed;
2037 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002038 break;
2039 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002040 result = PyType_GenericNew(Delete_type, NULL, NULL);
2041 if (!result) goto failed;
2042 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2043 if (!value) goto failed;
2044 if (PyObject_SetAttrString(result, "targets", value) == -1)
2045 goto failed;
2046 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002047 break;
2048 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002049 result = PyType_GenericNew(Assign_type, NULL, NULL);
2050 if (!result) goto failed;
2051 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2052 if (!value) goto failed;
2053 if (PyObject_SetAttrString(result, "targets", value) == -1)
2054 goto failed;
2055 Py_DECREF(value);
2056 value = ast2obj_expr(o->v.Assign.value);
2057 if (!value) goto failed;
2058 if (PyObject_SetAttrString(result, "value", value) == -1)
2059 goto failed;
2060 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061 break;
2062 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002063 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2064 if (!result) goto failed;
2065 value = ast2obj_expr(o->v.AugAssign.target);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "target", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
2070 value = ast2obj_operator(o->v.AugAssign.op);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "op", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
2075 value = ast2obj_expr(o->v.AugAssign.value);
2076 if (!value) goto failed;
2077 if (PyObject_SetAttrString(result, "value", value) == -1)
2078 goto failed;
2079 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002080 break;
2081 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002082 result = PyType_GenericNew(Print_type, NULL, NULL);
2083 if (!result) goto failed;
2084 value = ast2obj_expr(o->v.Print.dest);
2085 if (!value) goto failed;
2086 if (PyObject_SetAttrString(result, "dest", value) == -1)
2087 goto failed;
2088 Py_DECREF(value);
2089 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2090 if (!value) goto failed;
2091 if (PyObject_SetAttrString(result, "values", value) == -1)
2092 goto failed;
2093 Py_DECREF(value);
2094 value = ast2obj_bool(o->v.Print.nl);
2095 if (!value) goto failed;
2096 if (PyObject_SetAttrString(result, "nl", value) == -1)
2097 goto failed;
2098 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002099 break;
2100 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002101 result = PyType_GenericNew(For_type, NULL, NULL);
2102 if (!result) goto failed;
2103 value = ast2obj_expr(o->v.For.target);
2104 if (!value) goto failed;
2105 if (PyObject_SetAttrString(result, "target", value) == -1)
2106 goto failed;
2107 Py_DECREF(value);
2108 value = ast2obj_expr(o->v.For.iter);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "iter", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2114 if (!value) goto failed;
2115 if (PyObject_SetAttrString(result, "body", value) == -1)
2116 goto failed;
2117 Py_DECREF(value);
2118 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2119 if (!value) goto failed;
2120 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2121 goto failed;
2122 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002123 break;
2124 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002125 result = PyType_GenericNew(While_type, NULL, NULL);
2126 if (!result) goto failed;
2127 value = ast2obj_expr(o->v.While.test);
2128 if (!value) goto failed;
2129 if (PyObject_SetAttrString(result, "test", value) == -1)
2130 goto failed;
2131 Py_DECREF(value);
2132 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "body", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
2137 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2138 if (!value) goto failed;
2139 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2140 goto failed;
2141 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002142 break;
2143 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002144 result = PyType_GenericNew(If_type, NULL, NULL);
2145 if (!result) goto failed;
2146 value = ast2obj_expr(o->v.If.test);
2147 if (!value) goto failed;
2148 if (PyObject_SetAttrString(result, "test", value) == -1)
2149 goto failed;
2150 Py_DECREF(value);
2151 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2152 if (!value) goto failed;
2153 if (PyObject_SetAttrString(result, "body", value) == -1)
2154 goto failed;
2155 Py_DECREF(value);
2156 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002161 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002162 case With_kind:
2163 result = PyType_GenericNew(With_type, NULL, NULL);
2164 if (!result) goto failed;
2165 value = ast2obj_expr(o->v.With.context_expr);
2166 if (!value) goto failed;
2167 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2168 goto failed;
2169 Py_DECREF(value);
2170 value = ast2obj_expr(o->v.With.optional_vars);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2173 -1)
2174 goto failed;
2175 Py_DECREF(value);
2176 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2177 if (!value) goto failed;
2178 if (PyObject_SetAttrString(result, "body", value) == -1)
2179 goto failed;
2180 Py_DECREF(value);
2181 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002183 result = PyType_GenericNew(Raise_type, NULL, NULL);
2184 if (!result) goto failed;
2185 value = ast2obj_expr(o->v.Raise.type);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "type", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
2190 value = ast2obj_expr(o->v.Raise.inst);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "inst", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_expr(o->v.Raise.tback);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "tback", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002200 break;
2201 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002202 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2203 if (!result) goto failed;
2204 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2205 if (!value) goto failed;
2206 if (PyObject_SetAttrString(result, "body", value) == -1)
2207 goto failed;
2208 Py_DECREF(value);
2209 value = ast2obj_list(o->v.TryExcept.handlers,
2210 ast2obj_excepthandler);
2211 if (!value) goto failed;
2212 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2213 goto failed;
2214 Py_DECREF(value);
2215 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220 break;
2221 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002222 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2223 if (!result) goto failed;
2224 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2225 if (!value) goto failed;
2226 if (PyObject_SetAttrString(result, "body", value) == -1)
2227 goto failed;
2228 Py_DECREF(value);
2229 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002234 break;
2235 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002236 result = PyType_GenericNew(Assert_type, NULL, NULL);
2237 if (!result) goto failed;
2238 value = ast2obj_expr(o->v.Assert.test);
2239 if (!value) goto failed;
2240 if (PyObject_SetAttrString(result, "test", value) == -1)
2241 goto failed;
2242 Py_DECREF(value);
2243 value = ast2obj_expr(o->v.Assert.msg);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "msg", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002248 break;
2249 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002250 result = PyType_GenericNew(Import_type, NULL, NULL);
2251 if (!result) goto failed;
2252 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2253 if (!value) goto failed;
2254 if (PyObject_SetAttrString(result, "names", value) == -1)
2255 goto failed;
2256 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002257 break;
2258 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002259 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2260 if (!result) goto failed;
2261 value = ast2obj_identifier(o->v.ImportFrom.module);
2262 if (!value) goto failed;
2263 if (PyObject_SetAttrString(result, "module", value) == -1)
2264 goto failed;
2265 Py_DECREF(value);
2266 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2267 if (!value) goto failed;
2268 if (PyObject_SetAttrString(result, "names", value) == -1)
2269 goto failed;
2270 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002271 value = ast2obj_int(o->v.ImportFrom.level);
2272 if (!value) goto failed;
2273 if (PyObject_SetAttrString(result, "level", value) == -1)
2274 goto failed;
2275 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276 break;
2277 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002278 result = PyType_GenericNew(Exec_type, NULL, NULL);
2279 if (!result) goto failed;
2280 value = ast2obj_expr(o->v.Exec.body);
2281 if (!value) goto failed;
2282 if (PyObject_SetAttrString(result, "body", value) == -1)
2283 goto failed;
2284 Py_DECREF(value);
2285 value = ast2obj_expr(o->v.Exec.globals);
2286 if (!value) goto failed;
2287 if (PyObject_SetAttrString(result, "globals", value) == -1)
2288 goto failed;
2289 Py_DECREF(value);
2290 value = ast2obj_expr(o->v.Exec.locals);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "locals", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002295 break;
2296 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002297 result = PyType_GenericNew(Global_type, NULL, NULL);
2298 if (!result) goto failed;
2299 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2300 if (!value) goto failed;
2301 if (PyObject_SetAttrString(result, "names", value) == -1)
2302 goto failed;
2303 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002304 break;
2305 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002306 result = PyType_GenericNew(Expr_type, NULL, NULL);
2307 if (!result) goto failed;
2308 value = ast2obj_expr(o->v.Expr.value);
2309 if (!value) goto failed;
2310 if (PyObject_SetAttrString(result, "value", value) == -1)
2311 goto failed;
2312 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002313 break;
2314 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002315 result = PyType_GenericNew(Pass_type, NULL, NULL);
2316 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317 break;
2318 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002319 result = PyType_GenericNew(Break_type, NULL, NULL);
2320 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002321 break;
2322 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002323 result = PyType_GenericNew(Continue_type, NULL, NULL);
2324 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325 break;
2326 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002327 value = ast2obj_int(o->lineno);
2328 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002329 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2330 goto failed;
2331 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002332 value = ast2obj_int(o->col_offset);
2333 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002334 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2335 goto failed;
2336 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002337 return result;
2338failed:
2339 Py_XDECREF(value);
2340 Py_XDECREF(result);
2341 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342}
2343
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344PyObject*
2345ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002347 expr_ty o = (expr_ty)_o;
2348 PyObject *result = NULL, *value = NULL;
2349 if (!o) {
2350 Py_INCREF(Py_None);
2351 return Py_None;
2352 }
2353
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002354 switch (o->kind) {
2355 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002356 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2357 if (!result) goto failed;
2358 value = ast2obj_boolop(o->v.BoolOp.op);
2359 if (!value) goto failed;
2360 if (PyObject_SetAttrString(result, "op", value) == -1)
2361 goto failed;
2362 Py_DECREF(value);
2363 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2364 if (!value) goto failed;
2365 if (PyObject_SetAttrString(result, "values", value) == -1)
2366 goto failed;
2367 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002368 break;
2369 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002370 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2371 if (!result) goto failed;
2372 value = ast2obj_expr(o->v.BinOp.left);
2373 if (!value) goto failed;
2374 if (PyObject_SetAttrString(result, "left", value) == -1)
2375 goto failed;
2376 Py_DECREF(value);
2377 value = ast2obj_operator(o->v.BinOp.op);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "op", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
2382 value = ast2obj_expr(o->v.BinOp.right);
2383 if (!value) goto failed;
2384 if (PyObject_SetAttrString(result, "right", value) == -1)
2385 goto failed;
2386 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002387 break;
2388 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002389 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2390 if (!result) goto failed;
2391 value = ast2obj_unaryop(o->v.UnaryOp.op);
2392 if (!value) goto failed;
2393 if (PyObject_SetAttrString(result, "op", value) == -1)
2394 goto failed;
2395 Py_DECREF(value);
2396 value = ast2obj_expr(o->v.UnaryOp.operand);
2397 if (!value) goto failed;
2398 if (PyObject_SetAttrString(result, "operand", value) == -1)
2399 goto failed;
2400 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002401 break;
2402 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002403 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2404 if (!result) goto failed;
2405 value = ast2obj_arguments(o->v.Lambda.args);
2406 if (!value) goto failed;
2407 if (PyObject_SetAttrString(result, "args", value) == -1)
2408 goto failed;
2409 Py_DECREF(value);
2410 value = ast2obj_expr(o->v.Lambda.body);
2411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "body", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002415 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002416 case IfExp_kind:
2417 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2418 if (!result) goto failed;
2419 value = ast2obj_expr(o->v.IfExp.test);
2420 if (!value) goto failed;
2421 if (PyObject_SetAttrString(result, "test", value) == -1)
2422 goto failed;
2423 Py_DECREF(value);
2424 value = ast2obj_expr(o->v.IfExp.body);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "body", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
2429 value = ast2obj_expr(o->v.IfExp.orelse);
2430 if (!value) goto failed;
2431 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2432 goto failed;
2433 Py_DECREF(value);
2434 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002435 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002436 result = PyType_GenericNew(Dict_type, NULL, NULL);
2437 if (!result) goto failed;
2438 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2439 if (!value) goto failed;
2440 if (PyObject_SetAttrString(result, "keys", value) == -1)
2441 goto failed;
2442 Py_DECREF(value);
2443 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2444 if (!value) goto failed;
2445 if (PyObject_SetAttrString(result, "values", value) == -1)
2446 goto failed;
2447 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002448 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002449 case Set_kind:
2450 result = PyType_GenericNew(Set_type, NULL, NULL);
2451 if (!result) goto failed;
2452 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2453 if (!value) goto failed;
2454 if (PyObject_SetAttrString(result, "elts", value) == -1)
2455 goto failed;
2456 Py_DECREF(value);
2457 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002458 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002459 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2460 if (!result) goto failed;
2461 value = ast2obj_expr(o->v.ListComp.elt);
2462 if (!value) goto failed;
2463 if (PyObject_SetAttrString(result, "elt", value) == -1)
2464 goto failed;
2465 Py_DECREF(value);
2466 value = ast2obj_list(o->v.ListComp.generators,
2467 ast2obj_comprehension);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "generators", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002472 break;
2473 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002474 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2475 if (!result) goto failed;
2476 value = ast2obj_expr(o->v.GeneratorExp.elt);
2477 if (!value) goto failed;
2478 if (PyObject_SetAttrString(result, "elt", value) == -1)
2479 goto failed;
2480 Py_DECREF(value);
2481 value = ast2obj_list(o->v.GeneratorExp.generators,
2482 ast2obj_comprehension);
2483 if (!value) goto failed;
2484 if (PyObject_SetAttrString(result, "generators", value) == -1)
2485 goto failed;
2486 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487 break;
2488 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002489 result = PyType_GenericNew(Yield_type, NULL, NULL);
2490 if (!result) goto failed;
2491 value = ast2obj_expr(o->v.Yield.value);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "value", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496 break;
2497 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002498 result = PyType_GenericNew(Compare_type, NULL, NULL);
2499 if (!result) goto failed;
2500 value = ast2obj_expr(o->v.Compare.left);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "left", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002505 {
2506 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2507 value = PyList_New(n);
2508 if (!value) goto failed;
2509 for(i = 0; i < n; i++)
2510 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2511 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002512 if (!value) goto failed;
2513 if (PyObject_SetAttrString(result, "ops", value) == -1)
2514 goto failed;
2515 Py_DECREF(value);
2516 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2517 if (!value) goto failed;
2518 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2519 goto failed;
2520 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002521 break;
2522 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002523 result = PyType_GenericNew(Call_type, NULL, NULL);
2524 if (!result) goto failed;
2525 value = ast2obj_expr(o->v.Call.func);
2526 if (!value) goto failed;
2527 if (PyObject_SetAttrString(result, "func", value) == -1)
2528 goto failed;
2529 Py_DECREF(value);
2530 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2531 if (!value) goto failed;
2532 if (PyObject_SetAttrString(result, "args", value) == -1)
2533 goto failed;
2534 Py_DECREF(value);
2535 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2536 if (!value) goto failed;
2537 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2538 goto failed;
2539 Py_DECREF(value);
2540 value = ast2obj_expr(o->v.Call.starargs);
2541 if (!value) goto failed;
2542 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2543 goto failed;
2544 Py_DECREF(value);
2545 value = ast2obj_expr(o->v.Call.kwargs);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002550 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002551 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002552 result = PyType_GenericNew(Num_type, NULL, NULL);
2553 if (!result) goto failed;
2554 value = ast2obj_object(o->v.Num.n);
2555 if (!value) goto failed;
2556 if (PyObject_SetAttrString(result, "n", value) == -1)
2557 goto failed;
2558 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002559 break;
2560 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002561 result = PyType_GenericNew(Str_type, NULL, NULL);
2562 if (!result) goto failed;
2563 value = ast2obj_string(o->v.Str.s);
2564 if (!value) goto failed;
2565 if (PyObject_SetAttrString(result, "s", value) == -1)
2566 goto failed;
2567 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002568 break;
2569 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002570 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2571 if (!result) goto failed;
2572 value = ast2obj_expr(o->v.Attribute.value);
2573 if (!value) goto failed;
2574 if (PyObject_SetAttrString(result, "value", value) == -1)
2575 goto failed;
2576 Py_DECREF(value);
2577 value = ast2obj_identifier(o->v.Attribute.attr);
2578 if (!value) goto failed;
2579 if (PyObject_SetAttrString(result, "attr", value) == -1)
2580 goto failed;
2581 Py_DECREF(value);
2582 value = ast2obj_expr_context(o->v.Attribute.ctx);
2583 if (!value) goto failed;
2584 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2585 goto failed;
2586 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002587 break;
2588 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002589 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2590 if (!result) goto failed;
2591 value = ast2obj_expr(o->v.Subscript.value);
2592 if (!value) goto failed;
2593 if (PyObject_SetAttrString(result, "value", value) == -1)
2594 goto failed;
2595 Py_DECREF(value);
2596 value = ast2obj_slice(o->v.Subscript.slice);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "slice", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 value = ast2obj_expr_context(o->v.Subscript.ctx);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606 break;
2607 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002608 result = PyType_GenericNew(Name_type, NULL, NULL);
2609 if (!result) goto failed;
2610 value = ast2obj_identifier(o->v.Name.id);
2611 if (!value) goto failed;
2612 if (PyObject_SetAttrString(result, "id", value) == -1)
2613 goto failed;
2614 Py_DECREF(value);
2615 value = ast2obj_expr_context(o->v.Name.ctx);
2616 if (!value) goto failed;
2617 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2618 goto failed;
2619 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002620 break;
2621 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002622 result = PyType_GenericNew(List_type, NULL, NULL);
2623 if (!result) goto failed;
2624 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2625 if (!value) goto failed;
2626 if (PyObject_SetAttrString(result, "elts", value) == -1)
2627 goto failed;
2628 Py_DECREF(value);
2629 value = ast2obj_expr_context(o->v.List.ctx);
2630 if (!value) goto failed;
2631 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2632 goto failed;
2633 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002634 break;
2635 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002636 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2637 if (!result) goto failed;
2638 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2639 if (!value) goto failed;
2640 if (PyObject_SetAttrString(result, "elts", value) == -1)
2641 goto failed;
2642 Py_DECREF(value);
2643 value = ast2obj_expr_context(o->v.Tuple.ctx);
2644 if (!value) goto failed;
2645 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2646 goto failed;
2647 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002648 break;
2649 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002650 value = ast2obj_int(o->lineno);
2651 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002652 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2653 goto failed;
2654 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002655 value = ast2obj_int(o->col_offset);
2656 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002657 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2658 goto failed;
2659 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002660 return result;
2661failed:
2662 Py_XDECREF(value);
2663 Py_XDECREF(result);
2664 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665}
2666
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002667PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002668{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002669 switch(o) {
2670 case Load:
2671 Py_INCREF(Load_singleton);
2672 return Load_singleton;
2673 case Store:
2674 Py_INCREF(Store_singleton);
2675 return Store_singleton;
2676 case Del:
2677 Py_INCREF(Del_singleton);
2678 return Del_singleton;
2679 case AugLoad:
2680 Py_INCREF(AugLoad_singleton);
2681 return AugLoad_singleton;
2682 case AugStore:
2683 Py_INCREF(AugStore_singleton);
2684 return AugStore_singleton;
2685 case Param:
2686 Py_INCREF(Param_singleton);
2687 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002689 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691PyObject*
2692ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 slice_ty o = (slice_ty)_o;
2695 PyObject *result = NULL, *value = NULL;
2696 if (!o) {
2697 Py_INCREF(Py_None);
2698 return Py_None;
2699 }
2700
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002701 switch (o->kind) {
2702 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002703 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2704 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002705 break;
2706 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002707 result = PyType_GenericNew(Slice_type, NULL, NULL);
2708 if (!result) goto failed;
2709 value = ast2obj_expr(o->v.Slice.lower);
2710 if (!value) goto failed;
2711 if (PyObject_SetAttrString(result, "lower", value) == -1)
2712 goto failed;
2713 Py_DECREF(value);
2714 value = ast2obj_expr(o->v.Slice.upper);
2715 if (!value) goto failed;
2716 if (PyObject_SetAttrString(result, "upper", value) == -1)
2717 goto failed;
2718 Py_DECREF(value);
2719 value = ast2obj_expr(o->v.Slice.step);
2720 if (!value) goto failed;
2721 if (PyObject_SetAttrString(result, "step", value) == -1)
2722 goto failed;
2723 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002724 break;
2725 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002726 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2727 if (!result) goto failed;
2728 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2729 if (!value) goto failed;
2730 if (PyObject_SetAttrString(result, "dims", value) == -1)
2731 goto failed;
2732 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002733 break;
2734 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002735 result = PyType_GenericNew(Index_type, NULL, NULL);
2736 if (!result) goto failed;
2737 value = ast2obj_expr(o->v.Index.value);
2738 if (!value) goto failed;
2739 if (PyObject_SetAttrString(result, "value", value) == -1)
2740 goto failed;
2741 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002742 break;
2743 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002744 return result;
2745failed:
2746 Py_XDECREF(value);
2747 Py_XDECREF(result);
2748 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002749}
2750
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002751PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002752{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002753 switch(o) {
2754 case And:
2755 Py_INCREF(And_singleton);
2756 return And_singleton;
2757 case Or:
2758 Py_INCREF(Or_singleton);
2759 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002760 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002761 return NULL; /* cannot happen */
2762}
2763PyObject* ast2obj_operator(operator_ty o)
2764{
2765 switch(o) {
2766 case Add:
2767 Py_INCREF(Add_singleton);
2768 return Add_singleton;
2769 case Sub:
2770 Py_INCREF(Sub_singleton);
2771 return Sub_singleton;
2772 case Mult:
2773 Py_INCREF(Mult_singleton);
2774 return Mult_singleton;
2775 case Div:
2776 Py_INCREF(Div_singleton);
2777 return Div_singleton;
2778 case Mod:
2779 Py_INCREF(Mod_singleton);
2780 return Mod_singleton;
2781 case Pow:
2782 Py_INCREF(Pow_singleton);
2783 return Pow_singleton;
2784 case LShift:
2785 Py_INCREF(LShift_singleton);
2786 return LShift_singleton;
2787 case RShift:
2788 Py_INCREF(RShift_singleton);
2789 return RShift_singleton;
2790 case BitOr:
2791 Py_INCREF(BitOr_singleton);
2792 return BitOr_singleton;
2793 case BitXor:
2794 Py_INCREF(BitXor_singleton);
2795 return BitXor_singleton;
2796 case BitAnd:
2797 Py_INCREF(BitAnd_singleton);
2798 return BitAnd_singleton;
2799 case FloorDiv:
2800 Py_INCREF(FloorDiv_singleton);
2801 return FloorDiv_singleton;
2802 }
2803 return NULL; /* cannot happen */
2804}
2805PyObject* ast2obj_unaryop(unaryop_ty o)
2806{
2807 switch(o) {
2808 case Invert:
2809 Py_INCREF(Invert_singleton);
2810 return Invert_singleton;
2811 case Not:
2812 Py_INCREF(Not_singleton);
2813 return Not_singleton;
2814 case UAdd:
2815 Py_INCREF(UAdd_singleton);
2816 return UAdd_singleton;
2817 case USub:
2818 Py_INCREF(USub_singleton);
2819 return USub_singleton;
2820 }
2821 return NULL; /* cannot happen */
2822}
2823PyObject* ast2obj_cmpop(cmpop_ty o)
2824{
2825 switch(o) {
2826 case Eq:
2827 Py_INCREF(Eq_singleton);
2828 return Eq_singleton;
2829 case NotEq:
2830 Py_INCREF(NotEq_singleton);
2831 return NotEq_singleton;
2832 case Lt:
2833 Py_INCREF(Lt_singleton);
2834 return Lt_singleton;
2835 case LtE:
2836 Py_INCREF(LtE_singleton);
2837 return LtE_singleton;
2838 case Gt:
2839 Py_INCREF(Gt_singleton);
2840 return Gt_singleton;
2841 case GtE:
2842 Py_INCREF(GtE_singleton);
2843 return GtE_singleton;
2844 case Is:
2845 Py_INCREF(Is_singleton);
2846 return Is_singleton;
2847 case IsNot:
2848 Py_INCREF(IsNot_singleton);
2849 return IsNot_singleton;
2850 case In:
2851 Py_INCREF(In_singleton);
2852 return In_singleton;
2853 case NotIn:
2854 Py_INCREF(NotIn_singleton);
2855 return NotIn_singleton;
2856 }
2857 return NULL; /* cannot happen */
2858}
2859PyObject*
2860ast2obj_comprehension(void* _o)
2861{
2862 comprehension_ty o = (comprehension_ty)_o;
2863 PyObject *result = NULL, *value = NULL;
2864 if (!o) {
2865 Py_INCREF(Py_None);
2866 return Py_None;
2867 }
2868
2869 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2870 if (!result) return NULL;
2871 value = ast2obj_expr(o->target);
2872 if (!value) goto failed;
2873 if (PyObject_SetAttrString(result, "target", value) == -1)
2874 goto failed;
2875 Py_DECREF(value);
2876 value = ast2obj_expr(o->iter);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "iter", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
2881 value = ast2obj_list(o->ifs, ast2obj_expr);
2882 if (!value) goto failed;
2883 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2884 goto failed;
2885 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002886 return result;
2887failed:
2888 Py_XDECREF(value);
2889 Py_XDECREF(result);
2890 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002891}
2892
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002893PyObject*
2894ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002895{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002896 excepthandler_ty o = (excepthandler_ty)_o;
2897 PyObject *result = NULL, *value = NULL;
2898 if (!o) {
2899 Py_INCREF(Py_None);
2900 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002901 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002902
2903 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2904 if (!result) return NULL;
2905 value = ast2obj_expr(o->type);
2906 if (!value) goto failed;
2907 if (PyObject_SetAttrString(result, "type", value) == -1)
2908 goto failed;
2909 Py_DECREF(value);
2910 value = ast2obj_expr(o->name);
2911 if (!value) goto failed;
2912 if (PyObject_SetAttrString(result, "name", value) == -1)
2913 goto failed;
2914 Py_DECREF(value);
2915 value = ast2obj_list(o->body, ast2obj_stmt);
2916 if (!value) goto failed;
2917 if (PyObject_SetAttrString(result, "body", value) == -1)
2918 goto failed;
2919 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002920 value = ast2obj_int(o->lineno);
2921 if (!value) goto failed;
2922 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2923 goto failed;
2924 Py_DECREF(value);
2925 value = ast2obj_int(o->col_offset);
2926 if (!value) goto failed;
2927 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2928 goto failed;
2929 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002930 return result;
2931failed:
2932 Py_XDECREF(value);
2933 Py_XDECREF(result);
2934 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002935}
2936
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002937PyObject*
2938ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002939{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002940 arguments_ty o = (arguments_ty)_o;
2941 PyObject *result = NULL, *value = NULL;
2942 if (!o) {
2943 Py_INCREF(Py_None);
2944 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002945 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002946
2947 result = PyType_GenericNew(arguments_type, NULL, NULL);
2948 if (!result) return NULL;
2949 value = ast2obj_list(o->args, ast2obj_expr);
2950 if (!value) goto failed;
2951 if (PyObject_SetAttrString(result, "args", value) == -1)
2952 goto failed;
2953 Py_DECREF(value);
2954 value = ast2obj_identifier(o->vararg);
2955 if (!value) goto failed;
2956 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2957 goto failed;
2958 Py_DECREF(value);
2959 value = ast2obj_identifier(o->kwarg);
2960 if (!value) goto failed;
2961 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2962 goto failed;
2963 Py_DECREF(value);
2964 value = ast2obj_list(o->defaults, ast2obj_expr);
2965 if (!value) goto failed;
2966 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2967 goto failed;
2968 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002969 return result;
2970failed:
2971 Py_XDECREF(value);
2972 Py_XDECREF(result);
2973 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002974}
2975
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002976PyObject*
2977ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002978{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002979 keyword_ty o = (keyword_ty)_o;
2980 PyObject *result = NULL, *value = NULL;
2981 if (!o) {
2982 Py_INCREF(Py_None);
2983 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002984 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002985
2986 result = PyType_GenericNew(keyword_type, NULL, NULL);
2987 if (!result) return NULL;
2988 value = ast2obj_identifier(o->arg);
2989 if (!value) goto failed;
2990 if (PyObject_SetAttrString(result, "arg", value) == -1)
2991 goto failed;
2992 Py_DECREF(value);
2993 value = ast2obj_expr(o->value);
2994 if (!value) goto failed;
2995 if (PyObject_SetAttrString(result, "value", value) == -1)
2996 goto failed;
2997 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002998 return result;
2999failed:
3000 Py_XDECREF(value);
3001 Py_XDECREF(result);
3002 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003003}
3004
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003005PyObject*
3006ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003007{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003008 alias_ty o = (alias_ty)_o;
3009 PyObject *result = NULL, *value = NULL;
3010 if (!o) {
3011 Py_INCREF(Py_None);
3012 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003013 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003014
3015 result = PyType_GenericNew(alias_type, NULL, NULL);
3016 if (!result) return NULL;
3017 value = ast2obj_identifier(o->name);
3018 if (!value) goto failed;
3019 if (PyObject_SetAttrString(result, "name", value) == -1)
3020 goto failed;
3021 Py_DECREF(value);
3022 value = ast2obj_identifier(o->asname);
3023 if (!value) goto failed;
3024 if (PyObject_SetAttrString(result, "asname", value) == -1)
3025 goto failed;
3026 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003027 return result;
3028failed:
3029 Py_XDECREF(value);
3030 Py_XDECREF(result);
3031 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003032}
3033
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003034
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003035PyMODINIT_FUNC
3036init_ast(void)
3037{
3038 PyObject *m, *d;
3039 if (!init_types()) return;
3040 m = Py_InitModule3("_ast", NULL, NULL);
3041 if (!m) return;
3042 d = PyModule_GetDict(m);
3043 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3044 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3045 return;
Georg Brandl17ab9a02006-08-28 16:38:22 +00003046 if (PyModule_AddStringConstant(m, "__version__", "51631") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003047 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003048 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3049 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3050 return;
3051 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3052 < 0) return;
3053 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3054 0) return;
3055 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3056 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3057 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3058 < 0) return;
3059 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3060 return;
3061 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3062 return;
3063 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3066 return;
3067 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3068 0) return;
3069 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3070 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3071 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3072 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3073 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3074 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3075 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3076 0) return;
3077 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3078 0) return;
3079 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3080 return;
3081 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3082 return;
3083 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3084 0) return;
3085 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3086 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3087 return;
3088 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3089 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3090 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3092 return;
3093 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3094 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3095 return;
3096 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3097 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3098 return;
3099 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3100 return;
3101 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3102 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003103 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003104 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3105 return;
3106 if (PyDict_SetItemString(d, "GeneratorExp",
3107 (PyObject*)GeneratorExp_type) < 0) return;
3108 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3109 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3110 return;
3111 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003112 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3114 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3115 0) return;
3116 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3117 0) return;
3118 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3119 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3120 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3121 if (PyDict_SetItemString(d, "expr_context",
3122 (PyObject*)expr_context_type) < 0) return;
3123 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3124 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3126 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3129 return;
3130 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3131 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3132 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3133 return;
3134 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3135 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3136 return;
3137 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3138 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3139 return;
3140 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3141 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3142 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3143 return;
3144 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3145 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3146 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3147 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3148 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3149 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3150 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3151 return;
3152 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3153 return;
3154 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3155 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3156 return;
3157 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3158 return;
3159 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3160 return;
3161 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3162 return;
3163 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3164 return;
3165 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3166 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3167 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3168 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3169 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3170 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3172 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3173 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3174 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3175 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3176 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3177 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3178 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3179 if (PyDict_SetItemString(d, "comprehension",
3180 (PyObject*)comprehension_type) < 0) return;
3181 if (PyDict_SetItemString(d, "excepthandler",
3182 (PyObject*)excepthandler_type) < 0) return;
3183 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3184 0) return;
3185 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3186 return;
3187 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003188}
3189
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003190
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003191PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003192{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003193 init_types();
3194 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003195}
3196
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003197