blob: 7a0f52825c56f1484e15dda1cc61d6ad64013bb0 [file] [log] [blame]
Neal Norwitz897ff812005-12-11 21:18:22 +00001/* File automatically generated by Parser/asdl_c.py */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
3#include "Python.h"
4#include "Python-ast.h"
5
Neal Norwitz53d960c2006-02-28 22:47:29 +00006static PyTypeObject* AST_type;
7static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +00009static PyTypeObject *Module_type;
10static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000011 "body",
12};
Neal Norwitz53d960c2006-02-28 22:47:29 +000013static PyTypeObject *Interactive_type;
14static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000015 "body",
16};
Neal Norwitz53d960c2006-02-28 22:47:29 +000017static PyTypeObject *Expression_type;
18static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000019 "body",
20};
Neal Norwitz53d960c2006-02-28 22:47:29 +000021static PyTypeObject *Suite_type;
22static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000023 "body",
24};
Neal Norwitz53d960c2006-02-28 22:47:29 +000025static PyTypeObject *stmt_type;
26static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000027 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000028 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000029};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000030static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000031static PyTypeObject *FunctionDef_type;
32static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000033 "name",
34 "args",
35 "body",
36 "decorators",
37};
Neal Norwitz53d960c2006-02-28 22:47:29 +000038static PyTypeObject *ClassDef_type;
39static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000040 "name",
41 "bases",
42 "body",
43};
Neal Norwitz53d960c2006-02-28 22:47:29 +000044static PyTypeObject *Return_type;
45static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000046 "value",
47};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *Delete_type;
49static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "targets",
51};
Neal Norwitz53d960c2006-02-28 22:47:29 +000052static PyTypeObject *Assign_type;
53static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000054 "targets",
55 "value",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *AugAssign_type;
58static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "target",
60 "op",
61 "value",
62};
Neal Norwitz53d960c2006-02-28 22:47:29 +000063static PyTypeObject *Print_type;
64static char *Print_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000065 "dest",
66 "values",
67 "nl",
68};
Neal Norwitz53d960c2006-02-28 22:47:29 +000069static PyTypeObject *For_type;
70static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000071 "target",
72 "iter",
73 "body",
74 "orelse",
75};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *While_type;
77static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000078 "test",
79 "body",
80 "orelse",
81};
Neal Norwitz53d960c2006-02-28 22:47:29 +000082static PyTypeObject *If_type;
83static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000084 "test",
85 "body",
86 "orelse",
87};
Neal Norwitz53d960c2006-02-28 22:47:29 +000088static PyTypeObject *With_type;
89static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000090 "context_expr",
91 "optional_vars",
92 "body",
93};
Neal Norwitz53d960c2006-02-28 22:47:29 +000094static PyTypeObject *Raise_type;
95static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000096 "type",
97 "inst",
98 "tback",
99};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000100static PyTypeObject *TryExcept_type;
101static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000102 "body",
103 "handlers",
104 "orelse",
105};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000106static PyTypeObject *TryFinally_type;
107static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000108 "body",
109 "finalbody",
110};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000111static PyTypeObject *Assert_type;
112static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000113 "test",
114 "msg",
115};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000116static PyTypeObject *Import_type;
117static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000118 "names",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *ImportFrom_type;
121static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "module",
123 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000124 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000125};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000126static PyTypeObject *Exec_type;
127static char *Exec_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000128 "body",
129 "globals",
130 "locals",
131};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000132static PyTypeObject *Global_type;
133static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000134 "names",
135};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000136static PyTypeObject *Expr_type;
137static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000138 "value",
139};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000140static PyTypeObject *Pass_type;
141static PyTypeObject *Break_type;
142static PyTypeObject *Continue_type;
143static PyTypeObject *expr_type;
144static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000145 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000146 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000147};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000148static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *BoolOp_type;
150static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000151 "op",
152 "values",
153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *BinOp_type;
155static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "left",
157 "op",
158 "right",
159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *UnaryOp_type;
161static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000162 "op",
163 "operand",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *Lambda_type;
166static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "args",
168 "body",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *IfExp_type;
171static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000172 "test",
173 "body",
174 "orelse",
175};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000176static PyTypeObject *Dict_type;
177static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000178 "keys",
179 "values",
180};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000181static PyTypeObject *ListComp_type;
182static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000183 "elt",
184 "generators",
185};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000186static PyTypeObject *GeneratorExp_type;
187static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000188 "elt",
189 "generators",
190};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000191static PyTypeObject *Yield_type;
192static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000193 "value",
194};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000195static PyTypeObject *Compare_type;
196static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000197 "left",
198 "ops",
199 "comparators",
200};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000201static PyTypeObject *Call_type;
202static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000203 "func",
204 "args",
205 "keywords",
206 "starargs",
207 "kwargs",
208};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000209static PyTypeObject *Repr_type;
210static char *Repr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000211 "value",
212};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000213static PyTypeObject *Num_type;
214static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000215 "n",
216};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Str_type;
218static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "s",
220};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000221static PyTypeObject *Attribute_type;
222static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000223 "value",
224 "attr",
225 "ctx",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Subscript_type;
228static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "value",
230 "slice",
231 "ctx",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *Name_type;
234static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "id",
236 "ctx",
237};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000238static PyTypeObject *List_type;
239static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000240 "elts",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Tuple_type;
244static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "elts",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
250*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
251static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000252static PyTypeObject *Load_type;
253static PyTypeObject *Store_type;
254static PyTypeObject *Del_type;
255static PyTypeObject *AugLoad_type;
256static PyTypeObject *AugStore_type;
257static PyTypeObject *Param_type;
258static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000260static PyTypeObject *Ellipsis_type;
261static PyTypeObject *Slice_type;
262static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000263 "lower",
264 "upper",
265 "step",
266};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *ExtSlice_type;
268static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269 "dims",
270};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000271static PyTypeObject *Index_type;
272static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000273 "value",
274};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000276static PyObject *And_singleton, *Or_singleton;
277static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000278static PyTypeObject *And_type;
279static PyTypeObject *Or_type;
280static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000281static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
282*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
283*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
284*FloorDiv_singleton;
285static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000286static PyTypeObject *Add_type;
287static PyTypeObject *Sub_type;
288static PyTypeObject *Mult_type;
289static PyTypeObject *Div_type;
290static PyTypeObject *Mod_type;
291static PyTypeObject *Pow_type;
292static PyTypeObject *LShift_type;
293static PyTypeObject *RShift_type;
294static PyTypeObject *BitOr_type;
295static PyTypeObject *BitXor_type;
296static PyTypeObject *BitAnd_type;
297static PyTypeObject *FloorDiv_type;
298static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000299static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
300*USub_singleton;
301static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000302static PyTypeObject *Invert_type;
303static PyTypeObject *Not_type;
304static PyTypeObject *UAdd_type;
305static PyTypeObject *USub_type;
306static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000307static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
308*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
309*NotIn_singleton;
310static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Eq_type;
312static PyTypeObject *NotEq_type;
313static PyTypeObject *Lt_type;
314static PyTypeObject *LtE_type;
315static PyTypeObject *Gt_type;
316static PyTypeObject *GtE_type;
317static PyTypeObject *Is_type;
318static PyTypeObject *IsNot_type;
319static PyTypeObject *In_type;
320static PyTypeObject *NotIn_type;
321static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000322static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000323static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324 "target",
325 "iter",
326 "ifs",
327};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331 "type",
332 "name",
333 "body",
Jeremy Hylton2f327c12006-04-04 04:00:23 +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{
Neal Norwitz19379f12006-04-03 04:50: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;
Neal Norwitz19379f12006-04-03 04:50: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 }
Neal Norwitz19379f12006-04-03 04:50: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{
Neal Norwitz19379f12006-04-03 04:50: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;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 GeneratorExp_type = make_type("GeneratorExp", expr_type,
527 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Repr_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,
Jeremy Hylton2f327c12006-04-04 04:00:23 +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
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001444ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1445 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001446{
1447 expr_ty p;
1448 if (!elt) {
1449 PyErr_SetString(PyExc_ValueError,
1450 "field elt is required for ListComp");
1451 return NULL;
1452 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001453 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001454 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001455 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001456 return NULL;
1457 }
1458 p->kind = ListComp_kind;
1459 p->v.ListComp.elt = elt;
1460 p->v.ListComp.generators = generators;
1461 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001462 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 return p;
1464}
1465
1466expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001467GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1468 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469{
1470 expr_ty p;
1471 if (!elt) {
1472 PyErr_SetString(PyExc_ValueError,
1473 "field elt is required for GeneratorExp");
1474 return NULL;
1475 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001476 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001478 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479 return NULL;
1480 }
1481 p->kind = GeneratorExp_kind;
1482 p->v.GeneratorExp.elt = elt;
1483 p->v.GeneratorExp.generators = generators;
1484 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001485 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001486 return p;
1487}
1488
1489expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001490Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491{
1492 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001493 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001495 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001496 return NULL;
1497 }
1498 p->kind = Yield_kind;
1499 p->v.Yield.value = value;
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öwis0cc56e52006-04-13 12:29:43 +00001506Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1507 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001508{
1509 expr_ty p;
1510 if (!left) {
1511 PyErr_SetString(PyExc_ValueError,
1512 "field left is required for Compare");
1513 return NULL;
1514 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001515 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001517 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518 return NULL;
1519 }
1520 p->kind = Compare_kind;
1521 p->v.Compare.left = left;
1522 p->v.Compare.ops = ops;
1523 p->v.Compare.comparators = comparators;
1524 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001525 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 return p;
1527}
1528
1529expr_ty
1530Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001531 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532{
1533 expr_ty p;
1534 if (!func) {
1535 PyErr_SetString(PyExc_ValueError,
1536 "field func is required for Call");
1537 return NULL;
1538 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001539 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001541 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542 return NULL;
1543 }
1544 p->kind = Call_kind;
1545 p->v.Call.func = func;
1546 p->v.Call.args = args;
1547 p->v.Call.keywords = keywords;
1548 p->v.Call.starargs = starargs;
1549 p->v.Call.kwargs = kwargs;
1550 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001551 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001552 return p;
1553}
1554
1555expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001556Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001557{
1558 expr_ty p;
1559 if (!value) {
1560 PyErr_SetString(PyExc_ValueError,
1561 "field value is required for Repr");
1562 return NULL;
1563 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001564 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001566 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567 return NULL;
1568 }
1569 p->kind = Repr_kind;
1570 p->v.Repr.value = value;
1571 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001572 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001573 return p;
1574}
1575
1576expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001577Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001578{
1579 expr_ty p;
1580 if (!n) {
1581 PyErr_SetString(PyExc_ValueError,
1582 "field n is required for Num");
1583 return NULL;
1584 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001585 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001586 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001587 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001588 return NULL;
1589 }
1590 p->kind = Num_kind;
1591 p->v.Num.n = n;
1592 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001593 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594 return p;
1595}
1596
1597expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001598Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001599{
1600 expr_ty p;
1601 if (!s) {
1602 PyErr_SetString(PyExc_ValueError,
1603 "field s is required for Str");
1604 return NULL;
1605 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001606 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001607 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001608 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001609 return NULL;
1610 }
1611 p->kind = Str_kind;
1612 p->v.Str.s = s;
1613 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001614 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001615 return p;
1616}
1617
1618expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001619Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1620 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001621{
1622 expr_ty p;
1623 if (!value) {
1624 PyErr_SetString(PyExc_ValueError,
1625 "field value is required for Attribute");
1626 return NULL;
1627 }
1628 if (!attr) {
1629 PyErr_SetString(PyExc_ValueError,
1630 "field attr is required for Attribute");
1631 return NULL;
1632 }
1633 if (!ctx) {
1634 PyErr_SetString(PyExc_ValueError,
1635 "field ctx is required for Attribute");
1636 return NULL;
1637 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001638 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001639 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001640 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001641 return NULL;
1642 }
1643 p->kind = Attribute_kind;
1644 p->v.Attribute.value = value;
1645 p->v.Attribute.attr = attr;
1646 p->v.Attribute.ctx = ctx;
1647 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001648 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001649 return p;
1650}
1651
1652expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001653Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1654 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001655{
1656 expr_ty p;
1657 if (!value) {
1658 PyErr_SetString(PyExc_ValueError,
1659 "field value is required for Subscript");
1660 return NULL;
1661 }
1662 if (!slice) {
1663 PyErr_SetString(PyExc_ValueError,
1664 "field slice is required for Subscript");
1665 return NULL;
1666 }
1667 if (!ctx) {
1668 PyErr_SetString(PyExc_ValueError,
1669 "field ctx is required for Subscript");
1670 return NULL;
1671 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001672 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001673 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001674 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001675 return NULL;
1676 }
1677 p->kind = Subscript_kind;
1678 p->v.Subscript.value = value;
1679 p->v.Subscript.slice = slice;
1680 p->v.Subscript.ctx = ctx;
1681 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001682 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001683 return p;
1684}
1685
1686expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001687Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1688 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001689{
1690 expr_ty p;
1691 if (!id) {
1692 PyErr_SetString(PyExc_ValueError,
1693 "field id is required for Name");
1694 return NULL;
1695 }
1696 if (!ctx) {
1697 PyErr_SetString(PyExc_ValueError,
1698 "field ctx is required for Name");
1699 return NULL;
1700 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001701 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001703 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001704 return NULL;
1705 }
1706 p->kind = Name_kind;
1707 p->v.Name.id = id;
1708 p->v.Name.ctx = ctx;
1709 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001710 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001711 return p;
1712}
1713
1714expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001715List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1716 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001717{
1718 expr_ty p;
1719 if (!ctx) {
1720 PyErr_SetString(PyExc_ValueError,
1721 "field ctx is required for List");
1722 return NULL;
1723 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001724 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001726 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001727 return NULL;
1728 }
1729 p->kind = List_kind;
1730 p->v.List.elts = elts;
1731 p->v.List.ctx = ctx;
1732 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001733 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001734 return p;
1735}
1736
1737expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001738Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1739 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740{
1741 expr_ty p;
1742 if (!ctx) {
1743 PyErr_SetString(PyExc_ValueError,
1744 "field ctx is required for Tuple");
1745 return NULL;
1746 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001747 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001749 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750 return NULL;
1751 }
1752 p->kind = Tuple_kind;
1753 p->v.Tuple.elts = elts;
1754 p->v.Tuple.ctx = ctx;
1755 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001756 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757 return p;
1758}
1759
1760slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001761Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762{
1763 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001764 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001765 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001766 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767 return NULL;
1768 }
1769 p->kind = Ellipsis_kind;
1770 return p;
1771}
1772
1773slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001774Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001775{
1776 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001779 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 return NULL;
1781 }
1782 p->kind = Slice_kind;
1783 p->v.Slice.lower = lower;
1784 p->v.Slice.upper = upper;
1785 p->v.Slice.step = step;
1786 return p;
1787}
1788
1789slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001790ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791{
1792 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001793 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001795 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001796 return NULL;
1797 }
1798 p->kind = ExtSlice_kind;
1799 p->v.ExtSlice.dims = dims;
1800 return p;
1801}
1802
1803slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001804Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805{
1806 slice_ty p;
1807 if (!value) {
1808 PyErr_SetString(PyExc_ValueError,
1809 "field value is required for Index");
1810 return NULL;
1811 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001812 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001814 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815 return NULL;
1816 }
1817 p->kind = Index_kind;
1818 p->v.Index.value = value;
1819 return p;
1820}
1821
1822comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001823comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001824{
1825 comprehension_ty p;
1826 if (!target) {
1827 PyErr_SetString(PyExc_ValueError,
1828 "field target is required for comprehension");
1829 return NULL;
1830 }
1831 if (!iter) {
1832 PyErr_SetString(PyExc_ValueError,
1833 "field iter is required for comprehension");
1834 return NULL;
1835 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001836 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001837 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001838 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001839 return NULL;
1840 }
1841 p->target = target;
1842 p->iter = iter;
1843 p->ifs = ifs;
1844 return p;
1845}
1846
1847excepthandler_ty
Jeremy Hylton2f327c12006-04-04 04:00:23 +00001848excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1849 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850{
1851 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001852 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001854 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855 return NULL;
1856 }
1857 p->type = type;
1858 p->name = name;
1859 p->body = body;
Jeremy Hylton2f327c12006-04-04 04:00:23 +00001860 p->lineno = lineno;
1861 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 return p;
1863}
1864
1865arguments_ty
1866arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001867 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868{
1869 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001870 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001871 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001872 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001873 return NULL;
1874 }
1875 p->args = args;
1876 p->vararg = vararg;
1877 p->kwarg = kwarg;
1878 p->defaults = defaults;
1879 return p;
1880}
1881
1882keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001883keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001884{
1885 keyword_ty p;
1886 if (!arg) {
1887 PyErr_SetString(PyExc_ValueError,
1888 "field arg is required for keyword");
1889 return NULL;
1890 }
1891 if (!value) {
1892 PyErr_SetString(PyExc_ValueError,
1893 "field value is required for keyword");
1894 return NULL;
1895 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001896 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001898 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899 return NULL;
1900 }
1901 p->arg = arg;
1902 p->value = value;
1903 return p;
1904}
1905
1906alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001907alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001908{
1909 alias_ty p;
1910 if (!name) {
1911 PyErr_SetString(PyExc_ValueError,
1912 "field name is required for alias");
1913 return NULL;
1914 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001915 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001916 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001917 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001918 return NULL;
1919 }
1920 p->name = name;
1921 p->asname = asname;
1922 return p;
1923}
1924
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001925
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001926PyObject*
1927ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001928{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001929 mod_ty o = (mod_ty)_o;
1930 PyObject *result = NULL, *value = NULL;
1931 if (!o) {
1932 Py_INCREF(Py_None);
1933 return Py_None;
1934 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001935
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001936 switch (o->kind) {
1937 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001938 result = PyType_GenericNew(Module_type, NULL, NULL);
1939 if (!result) goto failed;
1940 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1941 if (!value) goto failed;
1942 if (PyObject_SetAttrString(result, "body", value) == -1)
1943 goto failed;
1944 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001945 break;
1946 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001947 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1948 if (!result) goto failed;
1949 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1950 if (!value) goto failed;
1951 if (PyObject_SetAttrString(result, "body", value) == -1)
1952 goto failed;
1953 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001954 break;
1955 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001956 result = PyType_GenericNew(Expression_type, NULL, NULL);
1957 if (!result) goto failed;
1958 value = ast2obj_expr(o->v.Expression.body);
1959 if (!value) goto failed;
1960 if (PyObject_SetAttrString(result, "body", value) == -1)
1961 goto failed;
1962 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001963 break;
1964 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001965 result = PyType_GenericNew(Suite_type, NULL, NULL);
1966 if (!result) goto failed;
1967 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1968 if (!value) goto failed;
1969 if (PyObject_SetAttrString(result, "body", value) == -1)
1970 goto failed;
1971 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001972 break;
1973 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001974 return result;
1975failed:
1976 Py_XDECREF(value);
1977 Py_XDECREF(result);
1978 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001979}
1980
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001981PyObject*
1982ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001983{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001984 stmt_ty o = (stmt_ty)_o;
1985 PyObject *result = NULL, *value = NULL;
1986 if (!o) {
1987 Py_INCREF(Py_None);
1988 return Py_None;
1989 }
1990
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001991 switch (o->kind) {
1992 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001993 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1994 if (!result) goto failed;
1995 value = ast2obj_identifier(o->v.FunctionDef.name);
1996 if (!value) goto failed;
1997 if (PyObject_SetAttrString(result, "name", value) == -1)
1998 goto failed;
1999 Py_DECREF(value);
2000 value = ast2obj_arguments(o->v.FunctionDef.args);
2001 if (!value) goto failed;
2002 if (PyObject_SetAttrString(result, "args", value) == -1)
2003 goto failed;
2004 Py_DECREF(value);
2005 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2006 if (!value) goto failed;
2007 if (PyObject_SetAttrString(result, "body", value) == -1)
2008 goto failed;
2009 Py_DECREF(value);
2010 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2011 if (!value) goto failed;
2012 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2013 goto failed;
2014 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002015 break;
2016 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002017 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2018 if (!result) goto failed;
2019 value = ast2obj_identifier(o->v.ClassDef.name);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "name", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
2024 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2025 if (!value) goto failed;
2026 if (PyObject_SetAttrString(result, "bases", value) == -1)
2027 goto failed;
2028 Py_DECREF(value);
2029 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2030 if (!value) goto failed;
2031 if (PyObject_SetAttrString(result, "body", value) == -1)
2032 goto failed;
2033 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002034 break;
2035 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002036 result = PyType_GenericNew(Return_type, NULL, NULL);
2037 if (!result) goto failed;
2038 value = ast2obj_expr(o->v.Return.value);
2039 if (!value) goto failed;
2040 if (PyObject_SetAttrString(result, "value", value) == -1)
2041 goto failed;
2042 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002043 break;
2044 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002045 result = PyType_GenericNew(Delete_type, NULL, NULL);
2046 if (!result) goto failed;
2047 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2048 if (!value) goto failed;
2049 if (PyObject_SetAttrString(result, "targets", value) == -1)
2050 goto failed;
2051 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002052 break;
2053 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002054 result = PyType_GenericNew(Assign_type, NULL, NULL);
2055 if (!result) goto failed;
2056 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2057 if (!value) goto failed;
2058 if (PyObject_SetAttrString(result, "targets", value) == -1)
2059 goto failed;
2060 Py_DECREF(value);
2061 value = ast2obj_expr(o->v.Assign.value);
2062 if (!value) goto failed;
2063 if (PyObject_SetAttrString(result, "value", value) == -1)
2064 goto failed;
2065 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002066 break;
2067 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002068 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2069 if (!result) goto failed;
2070 value = ast2obj_expr(o->v.AugAssign.target);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "target", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
2075 value = ast2obj_operator(o->v.AugAssign.op);
2076 if (!value) goto failed;
2077 if (PyObject_SetAttrString(result, "op", value) == -1)
2078 goto failed;
2079 Py_DECREF(value);
2080 value = ast2obj_expr(o->v.AugAssign.value);
2081 if (!value) goto failed;
2082 if (PyObject_SetAttrString(result, "value", value) == -1)
2083 goto failed;
2084 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002085 break;
2086 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002087 result = PyType_GenericNew(Print_type, NULL, NULL);
2088 if (!result) goto failed;
2089 value = ast2obj_expr(o->v.Print.dest);
2090 if (!value) goto failed;
2091 if (PyObject_SetAttrString(result, "dest", value) == -1)
2092 goto failed;
2093 Py_DECREF(value);
2094 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2095 if (!value) goto failed;
2096 if (PyObject_SetAttrString(result, "values", value) == -1)
2097 goto failed;
2098 Py_DECREF(value);
2099 value = ast2obj_bool(o->v.Print.nl);
2100 if (!value) goto failed;
2101 if (PyObject_SetAttrString(result, "nl", value) == -1)
2102 goto failed;
2103 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002104 break;
2105 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002106 result = PyType_GenericNew(For_type, NULL, NULL);
2107 if (!result) goto failed;
2108 value = ast2obj_expr(o->v.For.target);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "target", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_expr(o->v.For.iter);
2114 if (!value) goto failed;
2115 if (PyObject_SetAttrString(result, "iter", value) == -1)
2116 goto failed;
2117 Py_DECREF(value);
2118 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2119 if (!value) goto failed;
2120 if (PyObject_SetAttrString(result, "body", value) == -1)
2121 goto failed;
2122 Py_DECREF(value);
2123 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2124 if (!value) goto failed;
2125 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2126 goto failed;
2127 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002128 break;
2129 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002130 result = PyType_GenericNew(While_type, NULL, NULL);
2131 if (!result) goto failed;
2132 value = ast2obj_expr(o->v.While.test);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "test", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
2137 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2138 if (!value) goto failed;
2139 if (PyObject_SetAttrString(result, "body", value) == -1)
2140 goto failed;
2141 Py_DECREF(value);
2142 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2143 if (!value) goto failed;
2144 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2145 goto failed;
2146 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002147 break;
2148 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002149 result = PyType_GenericNew(If_type, NULL, NULL);
2150 if (!result) goto failed;
2151 value = ast2obj_expr(o->v.If.test);
2152 if (!value) goto failed;
2153 if (PyObject_SetAttrString(result, "test", value) == -1)
2154 goto failed;
2155 Py_DECREF(value);
2156 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "body", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
2161 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2162 if (!value) goto failed;
2163 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2164 goto failed;
2165 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002166 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002167 case With_kind:
2168 result = PyType_GenericNew(With_type, NULL, NULL);
2169 if (!result) goto failed;
2170 value = ast2obj_expr(o->v.With.context_expr);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2173 goto failed;
2174 Py_DECREF(value);
2175 value = ast2obj_expr(o->v.With.optional_vars);
2176 if (!value) goto failed;
2177 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2178 -1)
2179 goto failed;
2180 Py_DECREF(value);
2181 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2182 if (!value) goto failed;
2183 if (PyObject_SetAttrString(result, "body", value) == -1)
2184 goto failed;
2185 Py_DECREF(value);
2186 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002187 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002188 result = PyType_GenericNew(Raise_type, NULL, NULL);
2189 if (!result) goto failed;
2190 value = ast2obj_expr(o->v.Raise.type);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "type", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_expr(o->v.Raise.inst);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "inst", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
2200 value = ast2obj_expr(o->v.Raise.tback);
2201 if (!value) goto failed;
2202 if (PyObject_SetAttrString(result, "tback", value) == -1)
2203 goto failed;
2204 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002205 break;
2206 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002207 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2208 if (!result) goto failed;
2209 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2210 if (!value) goto failed;
2211 if (PyObject_SetAttrString(result, "body", value) == -1)
2212 goto failed;
2213 Py_DECREF(value);
2214 value = ast2obj_list(o->v.TryExcept.handlers,
2215 ast2obj_excepthandler);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
2220 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002225 break;
2226 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002227 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2228 if (!result) goto failed;
2229 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "body", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
2234 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002239 break;
2240 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002241 result = PyType_GenericNew(Assert_type, NULL, NULL);
2242 if (!result) goto failed;
2243 value = ast2obj_expr(o->v.Assert.test);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "test", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
2248 value = ast2obj_expr(o->v.Assert.msg);
2249 if (!value) goto failed;
2250 if (PyObject_SetAttrString(result, "msg", value) == -1)
2251 goto failed;
2252 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253 break;
2254 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002255 result = PyType_GenericNew(Import_type, NULL, NULL);
2256 if (!result) goto failed;
2257 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2258 if (!value) goto failed;
2259 if (PyObject_SetAttrString(result, "names", value) == -1)
2260 goto failed;
2261 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262 break;
2263 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002264 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2265 if (!result) goto failed;
2266 value = ast2obj_identifier(o->v.ImportFrom.module);
2267 if (!value) goto failed;
2268 if (PyObject_SetAttrString(result, "module", value) == -1)
2269 goto failed;
2270 Py_DECREF(value);
2271 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2272 if (!value) goto failed;
2273 if (PyObject_SetAttrString(result, "names", value) == -1)
2274 goto failed;
2275 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002276 value = ast2obj_int(o->v.ImportFrom.level);
2277 if (!value) goto failed;
2278 if (PyObject_SetAttrString(result, "level", value) == -1)
2279 goto failed;
2280 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002281 break;
2282 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002283 result = PyType_GenericNew(Exec_type, NULL, NULL);
2284 if (!result) goto failed;
2285 value = ast2obj_expr(o->v.Exec.body);
2286 if (!value) goto failed;
2287 if (PyObject_SetAttrString(result, "body", value) == -1)
2288 goto failed;
2289 Py_DECREF(value);
2290 value = ast2obj_expr(o->v.Exec.globals);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "globals", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
2295 value = ast2obj_expr(o->v.Exec.locals);
2296 if (!value) goto failed;
2297 if (PyObject_SetAttrString(result, "locals", value) == -1)
2298 goto failed;
2299 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002300 break;
2301 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002302 result = PyType_GenericNew(Global_type, NULL, NULL);
2303 if (!result) goto failed;
2304 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2305 if (!value) goto failed;
2306 if (PyObject_SetAttrString(result, "names", value) == -1)
2307 goto failed;
2308 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002309 break;
2310 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002311 result = PyType_GenericNew(Expr_type, NULL, NULL);
2312 if (!result) goto failed;
2313 value = ast2obj_expr(o->v.Expr.value);
2314 if (!value) goto failed;
2315 if (PyObject_SetAttrString(result, "value", value) == -1)
2316 goto failed;
2317 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002318 break;
2319 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002320 result = PyType_GenericNew(Pass_type, NULL, NULL);
2321 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002322 break;
2323 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002324 result = PyType_GenericNew(Break_type, NULL, NULL);
2325 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002326 break;
2327 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002328 result = PyType_GenericNew(Continue_type, NULL, NULL);
2329 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002330 break;
2331 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002332 value = ast2obj_int(o->lineno);
2333 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002334 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2335 goto failed;
2336 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002337 value = ast2obj_int(o->col_offset);
2338 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002339 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2340 goto failed;
2341 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002342 return result;
2343failed:
2344 Py_XDECREF(value);
2345 Py_XDECREF(result);
2346 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002347}
2348
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002349PyObject*
2350ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002351{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002352 expr_ty o = (expr_ty)_o;
2353 PyObject *result = NULL, *value = NULL;
2354 if (!o) {
2355 Py_INCREF(Py_None);
2356 return Py_None;
2357 }
2358
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002359 switch (o->kind) {
2360 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002361 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2362 if (!result) goto failed;
2363 value = ast2obj_boolop(o->v.BoolOp.op);
2364 if (!value) goto failed;
2365 if (PyObject_SetAttrString(result, "op", value) == -1)
2366 goto failed;
2367 Py_DECREF(value);
2368 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2369 if (!value) goto failed;
2370 if (PyObject_SetAttrString(result, "values", value) == -1)
2371 goto failed;
2372 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002373 break;
2374 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002375 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2376 if (!result) goto failed;
2377 value = ast2obj_expr(o->v.BinOp.left);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "left", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
2382 value = ast2obj_operator(o->v.BinOp.op);
2383 if (!value) goto failed;
2384 if (PyObject_SetAttrString(result, "op", value) == -1)
2385 goto failed;
2386 Py_DECREF(value);
2387 value = ast2obj_expr(o->v.BinOp.right);
2388 if (!value) goto failed;
2389 if (PyObject_SetAttrString(result, "right", value) == -1)
2390 goto failed;
2391 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002392 break;
2393 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002394 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2395 if (!result) goto failed;
2396 value = ast2obj_unaryop(o->v.UnaryOp.op);
2397 if (!value) goto failed;
2398 if (PyObject_SetAttrString(result, "op", value) == -1)
2399 goto failed;
2400 Py_DECREF(value);
2401 value = ast2obj_expr(o->v.UnaryOp.operand);
2402 if (!value) goto failed;
2403 if (PyObject_SetAttrString(result, "operand", value) == -1)
2404 goto failed;
2405 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002406 break;
2407 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002408 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2409 if (!result) goto failed;
2410 value = ast2obj_arguments(o->v.Lambda.args);
2411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "args", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
2415 value = ast2obj_expr(o->v.Lambda.body);
2416 if (!value) goto failed;
2417 if (PyObject_SetAttrString(result, "body", value) == -1)
2418 goto failed;
2419 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002420 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002421 case IfExp_kind:
2422 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2423 if (!result) goto failed;
2424 value = ast2obj_expr(o->v.IfExp.test);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "test", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
2429 value = ast2obj_expr(o->v.IfExp.body);
2430 if (!value) goto failed;
2431 if (PyObject_SetAttrString(result, "body", value) == -1)
2432 goto failed;
2433 Py_DECREF(value);
2434 value = ast2obj_expr(o->v.IfExp.orelse);
2435 if (!value) goto failed;
2436 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2437 goto failed;
2438 Py_DECREF(value);
2439 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002440 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002441 result = PyType_GenericNew(Dict_type, NULL, NULL);
2442 if (!result) goto failed;
2443 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2444 if (!value) goto failed;
2445 if (PyObject_SetAttrString(result, "keys", value) == -1)
2446 goto failed;
2447 Py_DECREF(value);
2448 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2449 if (!value) goto failed;
2450 if (PyObject_SetAttrString(result, "values", value) == -1)
2451 goto failed;
2452 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002453 break;
2454 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002455 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2456 if (!result) goto failed;
2457 value = ast2obj_expr(o->v.ListComp.elt);
2458 if (!value) goto failed;
2459 if (PyObject_SetAttrString(result, "elt", value) == -1)
2460 goto failed;
2461 Py_DECREF(value);
2462 value = ast2obj_list(o->v.ListComp.generators,
2463 ast2obj_comprehension);
2464 if (!value) goto failed;
2465 if (PyObject_SetAttrString(result, "generators", value) == -1)
2466 goto failed;
2467 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002468 break;
2469 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002470 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2471 if (!result) goto failed;
2472 value = ast2obj_expr(o->v.GeneratorExp.elt);
2473 if (!value) goto failed;
2474 if (PyObject_SetAttrString(result, "elt", value) == -1)
2475 goto failed;
2476 Py_DECREF(value);
2477 value = ast2obj_list(o->v.GeneratorExp.generators,
2478 ast2obj_comprehension);
2479 if (!value) goto failed;
2480 if (PyObject_SetAttrString(result, "generators", value) == -1)
2481 goto failed;
2482 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002483 break;
2484 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002485 result = PyType_GenericNew(Yield_type, NULL, NULL);
2486 if (!result) goto failed;
2487 value = ast2obj_expr(o->v.Yield.value);
2488 if (!value) goto failed;
2489 if (PyObject_SetAttrString(result, "value", value) == -1)
2490 goto failed;
2491 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002492 break;
2493 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002494 result = PyType_GenericNew(Compare_type, NULL, NULL);
2495 if (!result) goto failed;
2496 value = ast2obj_expr(o->v.Compare.left);
2497 if (!value) goto failed;
2498 if (PyObject_SetAttrString(result, "left", value) == -1)
2499 goto failed;
2500 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002501 {
2502 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2503 value = PyList_New(n);
2504 if (!value) goto failed;
2505 for(i = 0; i < n; i++)
Martin v. Löwis0cc56e52006-04-13 12:29:43 +00002506 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002507 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002508 if (!value) goto failed;
2509 if (PyObject_SetAttrString(result, "ops", value) == -1)
2510 goto failed;
2511 Py_DECREF(value);
2512 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517 break;
2518 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002519 result = PyType_GenericNew(Call_type, NULL, NULL);
2520 if (!result) goto failed;
2521 value = ast2obj_expr(o->v.Call.func);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "func", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
2526 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2527 if (!value) goto failed;
2528 if (PyObject_SetAttrString(result, "args", value) == -1)
2529 goto failed;
2530 Py_DECREF(value);
2531 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_expr(o->v.Call.starargs);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 value = ast2obj_expr(o->v.Call.kwargs);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002546 break;
2547 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002548 result = PyType_GenericNew(Repr_type, NULL, NULL);
2549 if (!result) goto failed;
2550 value = ast2obj_expr(o->v.Repr.value);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "value", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002555 break;
2556 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002557 result = PyType_GenericNew(Num_type, NULL, NULL);
2558 if (!result) goto failed;
2559 value = ast2obj_object(o->v.Num.n);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "n", value) == -1)
2562 goto failed;
2563 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002564 break;
2565 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002566 result = PyType_GenericNew(Str_type, NULL, NULL);
2567 if (!result) goto failed;
2568 value = ast2obj_string(o->v.Str.s);
2569 if (!value) goto failed;
2570 if (PyObject_SetAttrString(result, "s", value) == -1)
2571 goto failed;
2572 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002573 break;
2574 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002575 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2576 if (!result) goto failed;
2577 value = ast2obj_expr(o->v.Attribute.value);
2578 if (!value) goto failed;
2579 if (PyObject_SetAttrString(result, "value", value) == -1)
2580 goto failed;
2581 Py_DECREF(value);
2582 value = ast2obj_identifier(o->v.Attribute.attr);
2583 if (!value) goto failed;
2584 if (PyObject_SetAttrString(result, "attr", value) == -1)
2585 goto failed;
2586 Py_DECREF(value);
2587 value = ast2obj_expr_context(o->v.Attribute.ctx);
2588 if (!value) goto failed;
2589 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2590 goto failed;
2591 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002592 break;
2593 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002594 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2595 if (!result) goto failed;
2596 value = ast2obj_expr(o->v.Subscript.value);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "value", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 value = ast2obj_slice(o->v.Subscript.slice);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "slice", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
2606 value = ast2obj_expr_context(o->v.Subscript.ctx);
2607 if (!value) goto failed;
2608 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2609 goto failed;
2610 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002611 break;
2612 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002613 result = PyType_GenericNew(Name_type, NULL, NULL);
2614 if (!result) goto failed;
2615 value = ast2obj_identifier(o->v.Name.id);
2616 if (!value) goto failed;
2617 if (PyObject_SetAttrString(result, "id", value) == -1)
2618 goto failed;
2619 Py_DECREF(value);
2620 value = ast2obj_expr_context(o->v.Name.ctx);
2621 if (!value) goto failed;
2622 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2623 goto failed;
2624 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002625 break;
2626 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002627 result = PyType_GenericNew(List_type, NULL, NULL);
2628 if (!result) goto failed;
2629 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2630 if (!value) goto failed;
2631 if (PyObject_SetAttrString(result, "elts", value) == -1)
2632 goto failed;
2633 Py_DECREF(value);
2634 value = ast2obj_expr_context(o->v.List.ctx);
2635 if (!value) goto failed;
2636 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2637 goto failed;
2638 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002639 break;
2640 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002641 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2642 if (!result) goto failed;
2643 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2644 if (!value) goto failed;
2645 if (PyObject_SetAttrString(result, "elts", value) == -1)
2646 goto failed;
2647 Py_DECREF(value);
2648 value = ast2obj_expr_context(o->v.Tuple.ctx);
2649 if (!value) goto failed;
2650 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2651 goto failed;
2652 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002653 break;
2654 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002655 value = ast2obj_int(o->lineno);
2656 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002657 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2658 goto failed;
2659 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002660 value = ast2obj_int(o->col_offset);
2661 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002662 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2663 goto failed;
2664 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002665 return result;
2666failed:
2667 Py_XDECREF(value);
2668 Py_XDECREF(result);
2669 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002670}
2671
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002672PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002673{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002674 switch(o) {
2675 case Load:
2676 Py_INCREF(Load_singleton);
2677 return Load_singleton;
2678 case Store:
2679 Py_INCREF(Store_singleton);
2680 return Store_singleton;
2681 case Del:
2682 Py_INCREF(Del_singleton);
2683 return Del_singleton;
2684 case AugLoad:
2685 Py_INCREF(AugLoad_singleton);
2686 return AugLoad_singleton;
2687 case AugStore:
2688 Py_INCREF(AugStore_singleton);
2689 return AugStore_singleton;
2690 case Param:
2691 Py_INCREF(Param_singleton);
2692 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002695}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002696PyObject*
2697ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002698{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002699 slice_ty o = (slice_ty)_o;
2700 PyObject *result = NULL, *value = NULL;
2701 if (!o) {
2702 Py_INCREF(Py_None);
2703 return Py_None;
2704 }
2705
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002706 switch (o->kind) {
2707 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002708 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2709 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002710 break;
2711 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002712 result = PyType_GenericNew(Slice_type, NULL, NULL);
2713 if (!result) goto failed;
2714 value = ast2obj_expr(o->v.Slice.lower);
2715 if (!value) goto failed;
2716 if (PyObject_SetAttrString(result, "lower", value) == -1)
2717 goto failed;
2718 Py_DECREF(value);
2719 value = ast2obj_expr(o->v.Slice.upper);
2720 if (!value) goto failed;
2721 if (PyObject_SetAttrString(result, "upper", value) == -1)
2722 goto failed;
2723 Py_DECREF(value);
2724 value = ast2obj_expr(o->v.Slice.step);
2725 if (!value) goto failed;
2726 if (PyObject_SetAttrString(result, "step", value) == -1)
2727 goto failed;
2728 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002729 break;
2730 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002731 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2732 if (!result) goto failed;
2733 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2734 if (!value) goto failed;
2735 if (PyObject_SetAttrString(result, "dims", value) == -1)
2736 goto failed;
2737 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002738 break;
2739 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002740 result = PyType_GenericNew(Index_type, NULL, NULL);
2741 if (!result) goto failed;
2742 value = ast2obj_expr(o->v.Index.value);
2743 if (!value) goto failed;
2744 if (PyObject_SetAttrString(result, "value", value) == -1)
2745 goto failed;
2746 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002747 break;
2748 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002749 return result;
2750failed:
2751 Py_XDECREF(value);
2752 Py_XDECREF(result);
2753 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002754}
2755
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002756PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002757{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002758 switch(o) {
2759 case And:
2760 Py_INCREF(And_singleton);
2761 return And_singleton;
2762 case Or:
2763 Py_INCREF(Or_singleton);
2764 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002765 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002766 return NULL; /* cannot happen */
2767}
2768PyObject* ast2obj_operator(operator_ty o)
2769{
2770 switch(o) {
2771 case Add:
2772 Py_INCREF(Add_singleton);
2773 return Add_singleton;
2774 case Sub:
2775 Py_INCREF(Sub_singleton);
2776 return Sub_singleton;
2777 case Mult:
2778 Py_INCREF(Mult_singleton);
2779 return Mult_singleton;
2780 case Div:
2781 Py_INCREF(Div_singleton);
2782 return Div_singleton;
2783 case Mod:
2784 Py_INCREF(Mod_singleton);
2785 return Mod_singleton;
2786 case Pow:
2787 Py_INCREF(Pow_singleton);
2788 return Pow_singleton;
2789 case LShift:
2790 Py_INCREF(LShift_singleton);
2791 return LShift_singleton;
2792 case RShift:
2793 Py_INCREF(RShift_singleton);
2794 return RShift_singleton;
2795 case BitOr:
2796 Py_INCREF(BitOr_singleton);
2797 return BitOr_singleton;
2798 case BitXor:
2799 Py_INCREF(BitXor_singleton);
2800 return BitXor_singleton;
2801 case BitAnd:
2802 Py_INCREF(BitAnd_singleton);
2803 return BitAnd_singleton;
2804 case FloorDiv:
2805 Py_INCREF(FloorDiv_singleton);
2806 return FloorDiv_singleton;
2807 }
2808 return NULL; /* cannot happen */
2809}
2810PyObject* ast2obj_unaryop(unaryop_ty o)
2811{
2812 switch(o) {
2813 case Invert:
2814 Py_INCREF(Invert_singleton);
2815 return Invert_singleton;
2816 case Not:
2817 Py_INCREF(Not_singleton);
2818 return Not_singleton;
2819 case UAdd:
2820 Py_INCREF(UAdd_singleton);
2821 return UAdd_singleton;
2822 case USub:
2823 Py_INCREF(USub_singleton);
2824 return USub_singleton;
2825 }
2826 return NULL; /* cannot happen */
2827}
2828PyObject* ast2obj_cmpop(cmpop_ty o)
2829{
2830 switch(o) {
2831 case Eq:
2832 Py_INCREF(Eq_singleton);
2833 return Eq_singleton;
2834 case NotEq:
2835 Py_INCREF(NotEq_singleton);
2836 return NotEq_singleton;
2837 case Lt:
2838 Py_INCREF(Lt_singleton);
2839 return Lt_singleton;
2840 case LtE:
2841 Py_INCREF(LtE_singleton);
2842 return LtE_singleton;
2843 case Gt:
2844 Py_INCREF(Gt_singleton);
2845 return Gt_singleton;
2846 case GtE:
2847 Py_INCREF(GtE_singleton);
2848 return GtE_singleton;
2849 case Is:
2850 Py_INCREF(Is_singleton);
2851 return Is_singleton;
2852 case IsNot:
2853 Py_INCREF(IsNot_singleton);
2854 return IsNot_singleton;
2855 case In:
2856 Py_INCREF(In_singleton);
2857 return In_singleton;
2858 case NotIn:
2859 Py_INCREF(NotIn_singleton);
2860 return NotIn_singleton;
2861 }
2862 return NULL; /* cannot happen */
2863}
2864PyObject*
2865ast2obj_comprehension(void* _o)
2866{
2867 comprehension_ty o = (comprehension_ty)_o;
2868 PyObject *result = NULL, *value = NULL;
2869 if (!o) {
2870 Py_INCREF(Py_None);
2871 return Py_None;
2872 }
2873
2874 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2875 if (!result) return NULL;
2876 value = ast2obj_expr(o->target);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "target", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
2881 value = ast2obj_expr(o->iter);
2882 if (!value) goto failed;
2883 if (PyObject_SetAttrString(result, "iter", value) == -1)
2884 goto failed;
2885 Py_DECREF(value);
2886 value = ast2obj_list(o->ifs, ast2obj_expr);
2887 if (!value) goto failed;
2888 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2889 goto failed;
2890 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002891 return result;
2892failed:
2893 Py_XDECREF(value);
2894 Py_XDECREF(result);
2895 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002896}
2897
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002898PyObject*
2899ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002900{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002901 excepthandler_ty o = (excepthandler_ty)_o;
2902 PyObject *result = NULL, *value = NULL;
2903 if (!o) {
2904 Py_INCREF(Py_None);
2905 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002906 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002907
2908 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2909 if (!result) return NULL;
2910 value = ast2obj_expr(o->type);
2911 if (!value) goto failed;
2912 if (PyObject_SetAttrString(result, "type", value) == -1)
2913 goto failed;
2914 Py_DECREF(value);
2915 value = ast2obj_expr(o->name);
2916 if (!value) goto failed;
2917 if (PyObject_SetAttrString(result, "name", value) == -1)
2918 goto failed;
2919 Py_DECREF(value);
2920 value = ast2obj_list(o->body, ast2obj_stmt);
2921 if (!value) goto failed;
2922 if (PyObject_SetAttrString(result, "body", value) == -1)
2923 goto failed;
2924 Py_DECREF(value);
Jeremy Hylton2f327c12006-04-04 04:00:23 +00002925 value = ast2obj_int(o->lineno);
2926 if (!value) goto failed;
2927 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2928 goto failed;
2929 Py_DECREF(value);
2930 value = ast2obj_int(o->col_offset);
2931 if (!value) goto failed;
2932 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2933 goto failed;
2934 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002935 return result;
2936failed:
2937 Py_XDECREF(value);
2938 Py_XDECREF(result);
2939 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002940}
2941
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002942PyObject*
2943ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002944{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002945 arguments_ty o = (arguments_ty)_o;
2946 PyObject *result = NULL, *value = NULL;
2947 if (!o) {
2948 Py_INCREF(Py_None);
2949 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002950 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951
2952 result = PyType_GenericNew(arguments_type, NULL, NULL);
2953 if (!result) return NULL;
2954 value = ast2obj_list(o->args, ast2obj_expr);
2955 if (!value) goto failed;
2956 if (PyObject_SetAttrString(result, "args", value) == -1)
2957 goto failed;
2958 Py_DECREF(value);
2959 value = ast2obj_identifier(o->vararg);
2960 if (!value) goto failed;
2961 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2962 goto failed;
2963 Py_DECREF(value);
2964 value = ast2obj_identifier(o->kwarg);
2965 if (!value) goto failed;
2966 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2967 goto failed;
2968 Py_DECREF(value);
2969 value = ast2obj_list(o->defaults, ast2obj_expr);
2970 if (!value) goto failed;
2971 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2972 goto failed;
2973 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002974 return result;
2975failed:
2976 Py_XDECREF(value);
2977 Py_XDECREF(result);
2978 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002979}
2980
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002981PyObject*
2982ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002983{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002984 keyword_ty o = (keyword_ty)_o;
2985 PyObject *result = NULL, *value = NULL;
2986 if (!o) {
2987 Py_INCREF(Py_None);
2988 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002989 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002990
2991 result = PyType_GenericNew(keyword_type, NULL, NULL);
2992 if (!result) return NULL;
2993 value = ast2obj_identifier(o->arg);
2994 if (!value) goto failed;
2995 if (PyObject_SetAttrString(result, "arg", value) == -1)
2996 goto failed;
2997 Py_DECREF(value);
2998 value = ast2obj_expr(o->value);
2999 if (!value) goto failed;
3000 if (PyObject_SetAttrString(result, "value", value) == -1)
3001 goto failed;
3002 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003003 return result;
3004failed:
3005 Py_XDECREF(value);
3006 Py_XDECREF(result);
3007 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003008}
3009
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003010PyObject*
3011ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003012{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003013 alias_ty o = (alias_ty)_o;
3014 PyObject *result = NULL, *value = NULL;
3015 if (!o) {
3016 Py_INCREF(Py_None);
3017 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003018 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003019
3020 result = PyType_GenericNew(alias_type, NULL, NULL);
3021 if (!result) return NULL;
3022 value = ast2obj_identifier(o->name);
3023 if (!value) goto failed;
3024 if (PyObject_SetAttrString(result, "name", value) == -1)
3025 goto failed;
3026 Py_DECREF(value);
3027 value = ast2obj_identifier(o->asname);
3028 if (!value) goto failed;
3029 if (PyObject_SetAttrString(result, "asname", value) == -1)
3030 goto failed;
3031 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003032 return result;
3033failed:
3034 Py_XDECREF(value);
3035 Py_XDECREF(result);
3036 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003037}
3038
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003039
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003040PyMODINIT_FUNC
3041init_ast(void)
3042{
3043 PyObject *m, *d;
3044 if (!init_types()) return;
3045 m = Py_InitModule3("_ast", NULL, NULL);
3046 if (!m) return;
3047 d = PyModule_GetDict(m);
3048 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3049 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3050 return;
Martin v. Löwisad7c44c2006-04-07 06:26:31 +00003051 if (PyModule_AddStringConstant(m, "__version__", "43614") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003052 return;
Neal Norwitz19379f12006-04-03 04:50:58 +00003053 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3054 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3055 return;
3056 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3057 < 0) return;
3058 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3059 0) return;
3060 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3061 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3062 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3063 < 0) return;
3064 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3065 return;
3066 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3067 return;
3068 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3069 return;
3070 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3071 return;
3072 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3073 0) return;
3074 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3075 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3076 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3077 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3078 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3079 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3080 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3081 0) return;
3082 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3083 0) return;
3084 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3085 return;
3086 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3087 return;
3088 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3089 0) return;
3090 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3092 return;
3093 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3094 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3095 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3096 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3097 return;
3098 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3099 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3100 return;
3101 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3102 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3103 return;
3104 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3105 return;
3106 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3107 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3108 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3109 return;
3110 if (PyDict_SetItemString(d, "GeneratorExp",
3111 (PyObject*)GeneratorExp_type) < 0) return;
3112 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3114 return;
3115 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3116 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3117 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3118 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3120 0) return;
3121 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3122 0) return;
3123 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3124 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3126 if (PyDict_SetItemString(d, "expr_context",
3127 (PyObject*)expr_context_type) < 0) return;
3128 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3129 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3130 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3131 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3132 return;
3133 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3134 return;
3135 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3136 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3138 return;
3139 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3140 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3141 return;
3142 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3143 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3144 return;
3145 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3146 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3147 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3148 return;
3149 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3150 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3151 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3152 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3153 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3154 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3155 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3156 return;
3157 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3158 return;
3159 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3160 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3161 return;
3162 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3163 return;
3164 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3165 return;
3166 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3167 return;
3168 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3169 return;
3170 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3171 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3172 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3173 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3174 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3175 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3176 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3177 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3178 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3179 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3180 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3181 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3182 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3183 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3184 if (PyDict_SetItemString(d, "comprehension",
3185 (PyObject*)comprehension_type) < 0) return;
3186 if (PyDict_SetItemString(d, "excepthandler",
3187 (PyObject*)excepthandler_type) < 0) return;
3188 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3189 0) return;
3190 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3191 return;
3192 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003193}
3194
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003195
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003196PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003197{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003198 init_types();
3199 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003200}
3201
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003202