blob: 13fc5e0cd22b23c82addc66c2216a3485202a293 [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",
Neal Norwitzc1505362006-12-28 06:47:50 +000037 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000038};
Neal Norwitz53d960c2006-02-28 22:47:29 +000039static PyTypeObject *ClassDef_type;
40static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000041 "name",
42 "bases",
43 "body",
44};
Neal Norwitz53d960c2006-02-28 22:47:29 +000045static PyTypeObject *Return_type;
46static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047 "value",
48};
Neal Norwitz53d960c2006-02-28 22:47:29 +000049static PyTypeObject *Delete_type;
50static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000051 "targets",
52};
Neal Norwitz53d960c2006-02-28 22:47:29 +000053static PyTypeObject *Assign_type;
54static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000055 "targets",
56 "value",
57};
Neal Norwitz53d960c2006-02-28 22:47:29 +000058static PyTypeObject *AugAssign_type;
59static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000060 "target",
61 "op",
62 "value",
63};
Neal Norwitz53d960c2006-02-28 22:47:29 +000064static PyTypeObject *For_type;
65static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000066 "target",
67 "iter",
68 "body",
69 "orelse",
70};
Neal Norwitz53d960c2006-02-28 22:47:29 +000071static PyTypeObject *While_type;
72static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000073 "test",
74 "body",
75 "orelse",
76};
Neal Norwitz53d960c2006-02-28 22:47:29 +000077static PyTypeObject *If_type;
78static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000079 "test",
80 "body",
81 "orelse",
82};
Neal Norwitz53d960c2006-02-28 22:47:29 +000083static PyTypeObject *With_type;
84static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000085 "context_expr",
86 "optional_vars",
87 "body",
88};
Neal Norwitz53d960c2006-02-28 22:47:29 +000089static PyTypeObject *Raise_type;
90static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000091 "type",
92 "inst",
93 "tback",
94};
Neal Norwitz53d960c2006-02-28 22:47:29 +000095static PyTypeObject *TryExcept_type;
96static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000097 "body",
98 "handlers",
99 "orelse",
100};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000101static PyTypeObject *TryFinally_type;
102static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000103 "body",
104 "finalbody",
105};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000106static PyTypeObject *Assert_type;
107static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000108 "test",
109 "msg",
110};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000111static PyTypeObject *Import_type;
112static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000113 "names",
114};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000115static PyTypeObject *ImportFrom_type;
116static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000117 "module",
118 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000119 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000120};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000121static PyTypeObject *Global_type;
122static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000123 "names",
124};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000125static PyTypeObject *Expr_type;
126static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000127 "value",
128};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000129static PyTypeObject *Pass_type;
130static PyTypeObject *Break_type;
131static PyTypeObject *Continue_type;
132static PyTypeObject *expr_type;
133static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000134 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000135 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000136};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000137static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000138static PyTypeObject *BoolOp_type;
139static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000140 "op",
141 "values",
142};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000143static PyTypeObject *BinOp_type;
144static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000145 "left",
146 "op",
147 "right",
148};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *UnaryOp_type;
150static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000151 "op",
152 "operand",
153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *Lambda_type;
155static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "args",
157 "body",
158};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000159static PyTypeObject *IfExp_type;
160static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000161 "test",
162 "body",
163 "orelse",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *Dict_type;
166static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "keys",
168 "values",
169};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000170static PyTypeObject *Set_type;
171static char *Set_fields[]={
172 "elts",
173};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000174static PyTypeObject *ListComp_type;
175static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000176 "elt",
177 "generators",
178};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000179static PyTypeObject *GeneratorExp_type;
180static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000181 "elt",
182 "generators",
183};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000184static PyTypeObject *Yield_type;
185static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000186 "value",
187};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000188static PyTypeObject *Compare_type;
189static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000190 "left",
191 "ops",
192 "comparators",
193};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000194static PyTypeObject *Call_type;
195static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000196 "func",
197 "args",
198 "keywords",
199 "starargs",
200 "kwargs",
201};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000202static PyTypeObject *Num_type;
203static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000204 "n",
205};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000206static PyTypeObject *Str_type;
207static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000208 "s",
209};
Georg Brandl52318d62006-09-06 07:06:08 +0000210static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000211static PyTypeObject *Attribute_type;
212static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213 "value",
214 "attr",
215 "ctx",
216};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Subscript_type;
218static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "value",
220 "slice",
221 "ctx",
222};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000223static PyTypeObject *Name_type;
224static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000225 "id",
226 "ctx",
227};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000228static PyTypeObject *List_type;
229static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000230 "elts",
231 "ctx",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *Tuple_type;
234static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "elts",
236 "ctx",
237};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000238static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000239static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
240*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
241static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Load_type;
243static PyTypeObject *Store_type;
244static PyTypeObject *Del_type;
245static PyTypeObject *AugLoad_type;
246static PyTypeObject *AugStore_type;
247static PyTypeObject *Param_type;
248static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000250static PyTypeObject *Slice_type;
251static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000252 "lower",
253 "upper",
254 "step",
255};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000256static PyTypeObject *ExtSlice_type;
257static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000258 "dims",
259};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000260static PyTypeObject *Index_type;
261static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000262 "value",
263};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000264static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000265static PyObject *And_singleton, *Or_singleton;
266static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *And_type;
268static PyTypeObject *Or_type;
269static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000270static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
271*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
272*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
273*FloorDiv_singleton;
274static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *Add_type;
276static PyTypeObject *Sub_type;
277static PyTypeObject *Mult_type;
278static PyTypeObject *Div_type;
279static PyTypeObject *Mod_type;
280static PyTypeObject *Pow_type;
281static PyTypeObject *LShift_type;
282static PyTypeObject *RShift_type;
283static PyTypeObject *BitOr_type;
284static PyTypeObject *BitXor_type;
285static PyTypeObject *BitAnd_type;
286static PyTypeObject *FloorDiv_type;
287static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000288static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
289*USub_singleton;
290static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000291static PyTypeObject *Invert_type;
292static PyTypeObject *Not_type;
293static PyTypeObject *UAdd_type;
294static PyTypeObject *USub_type;
295static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000296static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
297*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
298*NotIn_singleton;
299static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000300static PyTypeObject *Eq_type;
301static PyTypeObject *NotEq_type;
302static PyTypeObject *Lt_type;
303static PyTypeObject *LtE_type;
304static PyTypeObject *Gt_type;
305static PyTypeObject *GtE_type;
306static PyTypeObject *Is_type;
307static PyTypeObject *IsNot_type;
308static PyTypeObject *In_type;
309static PyTypeObject *NotIn_type;
310static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000311static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000312static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000313 "target",
314 "iter",
315 "ifs",
316};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000317static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000318static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000319static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000320 "type",
321 "name",
322 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000323 "lineno",
324 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000325};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000326static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000327static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329 "args",
330 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000331 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000332 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000334 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000335 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000336 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000337};
Neal Norwitzc1505362006-12-28 06:47:50 +0000338static PyTypeObject *arg_type;
339static PyObject* ast2obj_arg(void*);
340static PyTypeObject *SimpleArg_type;
341static char *SimpleArg_fields[]={
342 "arg",
343 "annotation",
344};
345static PyTypeObject *NestedArgs_type;
346static char *NestedArgs_fields[]={
347 "args",
348};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000351static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352 "arg",
353 "value",
354};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000355static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000356static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000357static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000358 "name",
359 "asname",
360};
361
362
363static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
364{
365 PyObject *fnames, *result;
366 int i;
367 if (num_fields) {
368 fnames = PyTuple_New(num_fields);
369 if (!fnames) return NULL;
370 } else {
371 fnames = Py_None;
372 Py_INCREF(Py_None);
373 }
374 for(i=0; i < num_fields; i++) {
375 PyObject *field = PyString_FromString(fields[i]);
376 if (!field) {
377 Py_DECREF(fnames);
378 return NULL;
379 }
380 PyTuple_SET_ITEM(fnames, i, field);
381 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000382 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000383 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000384 Py_DECREF(fnames);
385 return (PyTypeObject*)result;
386}
387
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000388static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
389{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000390 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000391 PyObject *s, *l = PyList_New(num_fields);
392 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000393 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000394 s = PyString_FromString(attrs[i]);
395 if (!s) {
396 Py_DECREF(l);
397 return 0;
398 }
399 PyList_SET_ITEM(l, i, s);
400 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000401 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
402 Py_DECREF(l);
403 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000404}
405
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000406static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
407{
408 int i, n = asdl_seq_LEN(seq);
409 PyObject *result = PyList_New(n);
410 PyObject *value;
411 if (!result)
412 return NULL;
413 for (i = 0; i < n; i++) {
414 value = func(asdl_seq_GET(seq, i));
415 if (!value) {
416 Py_DECREF(result);
417 return NULL;
418 }
419 PyList_SET_ITEM(result, i, value);
420 }
421 return result;
422}
423
424static PyObject* ast2obj_object(void *o)
425{
426 if (!o)
427 o = Py_None;
428 Py_INCREF((PyObject*)o);
429 return (PyObject*)o;
430}
431#define ast2obj_identifier ast2obj_object
432#define ast2obj_string ast2obj_object
433static PyObject* ast2obj_bool(bool b)
434{
435 return PyBool_FromLong(b);
436}
437
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000438static PyObject* ast2obj_int(bool b)
439{
440 return PyInt_FromLong(b);
441}
442
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443static int init_types(void)
444{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000445 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000446 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000447 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
448 mod_type = make_type("mod", AST_type, NULL, 0);
449 if (!mod_type) return 0;
450 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000451 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000453 Interactive_type = make_type("Interactive", mod_type,
454 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000455 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 Expression_type = make_type("Expression", mod_type, Expression_fields,
457 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!Suite_type) return 0;
461 stmt_type = make_type("stmt", AST_type, NULL, 0);
462 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000463 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000465 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000483 With_type = make_type("With", stmt_type, With_fields, 3);
484 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000487 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000488 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000489 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
490 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000497 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000503 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000505 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000507 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Continue_type) return 0;
509 expr_type = make_type("expr", AST_type, NULL, 0);
510 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000511 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000520 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000524 Set_type = make_type("Set", expr_type, Set_fields, 1);
525 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000528 GeneratorExp_type = make_type("GeneratorExp", expr_type,
529 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Str_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000541 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
542 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000547 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000551 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000552 if (!Tuple_type) return 0;
553 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
554 if (!expr_context_type) return 0;
555 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000556 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000560 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000564 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000568 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000572 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000574 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000575 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000576 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!Param_singleton) return 0;
580 slice_type = make_type("slice", AST_type, NULL, 0);
581 if (!slice_type) return 0;
582 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Index_type) return 0;
589 boolop_type = make_type("boolop", AST_type, NULL, 0);
590 if (!boolop_type) return 0;
591 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000592 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000596 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Or_singleton) return 0;
600 operator_type = make_type("operator", AST_type, NULL, 0);
601 if (!operator_type) return 0;
602 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000615 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000647 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000649 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!FloorDiv_singleton) return 0;
651 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
652 if (!unaryop_type) return 0;
653 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000666 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!USub_singleton) return 0;
670 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
671 if (!cmpop_type) return 0;
672 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000705 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000707 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000709 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000711 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!NotIn_singleton) return 0;
713 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000714 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!comprehension_type) return 0;
716 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000717 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000719 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000721 arg_type = make_type("arg", AST_type, NULL, 0);
722 if (!arg_type) return 0;
723 if (!add_attributes(arg_type, NULL, 0)) return 0;
724 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
725 if (!SimpleArg_type) return 0;
726 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
727 1);
728 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
730 if (!keyword_type) return 0;
731 alias_type = make_type("alias", AST_type, alias_fields, 2);
732 if (!alias_type) return 0;
733 initialized = 1;
734 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000735}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000736
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000737mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000738Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000739{
740 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000741 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000742 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000743 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000744 return NULL;
745 }
746 p->kind = Module_kind;
747 p->v.Module.body = body;
748 return p;
749}
750
751mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000752Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000753{
754 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000755 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000756 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000757 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000758 return NULL;
759 }
760 p->kind = Interactive_kind;
761 p->v.Interactive.body = body;
762 return p;
763}
764
765mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000766Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767{
768 mod_ty p;
769 if (!body) {
770 PyErr_SetString(PyExc_ValueError,
771 "field body is required for Expression");
772 return NULL;
773 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000774 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000776 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000777 return NULL;
778 }
779 p->kind = Expression_kind;
780 p->v.Expression.body = body;
781 return p;
782}
783
784mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000785Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000786{
787 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000788 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000789 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000790 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000791 return NULL;
792 }
793 p->kind = Suite_kind;
794 p->v.Suite.body = body;
795 return p;
796}
797
798stmt_ty
799FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000800 decorators, expr_ty returns, int lineno, int col_offset, PyArena
801 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802{
803 stmt_ty p;
804 if (!name) {
805 PyErr_SetString(PyExc_ValueError,
806 "field name is required for FunctionDef");
807 return NULL;
808 }
809 if (!args) {
810 PyErr_SetString(PyExc_ValueError,
811 "field args is required for FunctionDef");
812 return NULL;
813 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000814 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000815 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000816 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817 return NULL;
818 }
819 p->kind = FunctionDef_kind;
820 p->v.FunctionDef.name = name;
821 p->v.FunctionDef.args = args;
822 p->v.FunctionDef.body = body;
823 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000824 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000826 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000827 return p;
828}
829
830stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000831ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
832 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000833{
834 stmt_ty p;
835 if (!name) {
836 PyErr_SetString(PyExc_ValueError,
837 "field name is required for ClassDef");
838 return NULL;
839 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000840 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000842 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 return NULL;
844 }
845 p->kind = ClassDef_kind;
846 p->v.ClassDef.name = name;
847 p->v.ClassDef.bases = bases;
848 p->v.ClassDef.body = body;
849 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000850 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851 return p;
852}
853
854stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000855Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856{
857 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000858 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000860 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861 return NULL;
862 }
863 p->kind = Return_kind;
864 p->v.Return.value = value;
865 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000866 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 return p;
868}
869
870stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000871Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000872{
873 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000874 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000876 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877 return NULL;
878 }
879 p->kind = Delete_kind;
880 p->v.Delete.targets = targets;
881 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000882 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000883 return p;
884}
885
886stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000887Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
888 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000889{
890 stmt_ty p;
891 if (!value) {
892 PyErr_SetString(PyExc_ValueError,
893 "field value is required for Assign");
894 return NULL;
895 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000896 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000897 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000898 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 return NULL;
900 }
901 p->kind = Assign_kind;
902 p->v.Assign.targets = targets;
903 p->v.Assign.value = value;
904 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000905 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000906 return p;
907}
908
909stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000910AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
911 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000912{
913 stmt_ty p;
914 if (!target) {
915 PyErr_SetString(PyExc_ValueError,
916 "field target is required for AugAssign");
917 return NULL;
918 }
919 if (!op) {
920 PyErr_SetString(PyExc_ValueError,
921 "field op is required for AugAssign");
922 return NULL;
923 }
924 if (!value) {
925 PyErr_SetString(PyExc_ValueError,
926 "field value is required for AugAssign");
927 return NULL;
928 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000929 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000931 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000932 return NULL;
933 }
934 p->kind = AugAssign_kind;
935 p->v.AugAssign.target = target;
936 p->v.AugAssign.op = op;
937 p->v.AugAssign.value = value;
938 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000939 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000940 return p;
941}
942
943stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000944For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000945 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000946{
947 stmt_ty p;
948 if (!target) {
949 PyErr_SetString(PyExc_ValueError,
950 "field target is required for For");
951 return NULL;
952 }
953 if (!iter) {
954 PyErr_SetString(PyExc_ValueError,
955 "field iter is required for For");
956 return NULL;
957 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000958 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000959 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000960 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000961 return NULL;
962 }
963 p->kind = For_kind;
964 p->v.For.target = target;
965 p->v.For.iter = iter;
966 p->v.For.body = body;
967 p->v.For.orelse = orelse;
968 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000969 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000970 return p;
971}
972
973stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000974While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
975 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000976{
977 stmt_ty p;
978 if (!test) {
979 PyErr_SetString(PyExc_ValueError,
980 "field test is required for While");
981 return NULL;
982 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000983 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000984 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000985 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000986 return NULL;
987 }
988 p->kind = While_kind;
989 p->v.While.test = test;
990 p->v.While.body = body;
991 p->v.While.orelse = orelse;
992 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000993 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000994 return p;
995}
996
997stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000998If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
999 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001000{
1001 stmt_ty p;
1002 if (!test) {
1003 PyErr_SetString(PyExc_ValueError,
1004 "field test is required for If");
1005 return NULL;
1006 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001007 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001008 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001009 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001010 return NULL;
1011 }
1012 p->kind = If_kind;
1013 p->v.If.test = test;
1014 p->v.If.body = body;
1015 p->v.If.orelse = orelse;
1016 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001017 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001018 return p;
1019}
1020
1021stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001022With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001023 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001024{
1025 stmt_ty p;
1026 if (!context_expr) {
1027 PyErr_SetString(PyExc_ValueError,
1028 "field context_expr is required for With");
1029 return NULL;
1030 }
1031 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1032 if (!p) {
1033 PyErr_NoMemory();
1034 return NULL;
1035 }
1036 p->kind = With_kind;
1037 p->v.With.context_expr = context_expr;
1038 p->v.With.optional_vars = optional_vars;
1039 p->v.With.body = body;
1040 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001041 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001042 return p;
1043}
1044
1045stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001046Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1047 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001048{
1049 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001050 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001051 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001052 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001053 return NULL;
1054 }
1055 p->kind = Raise_kind;
1056 p->v.Raise.type = type;
1057 p->v.Raise.inst = inst;
1058 p->v.Raise.tback = tback;
1059 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001060 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001061 return p;
1062}
1063
1064stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001065TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001066 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001067{
1068 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001069 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001071 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001072 return NULL;
1073 }
1074 p->kind = TryExcept_kind;
1075 p->v.TryExcept.body = body;
1076 p->v.TryExcept.handlers = handlers;
1077 p->v.TryExcept.orelse = orelse;
1078 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001079 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001080 return p;
1081}
1082
1083stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001084TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1085 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001086{
1087 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001088 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001090 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001091 return NULL;
1092 }
1093 p->kind = TryFinally_kind;
1094 p->v.TryFinally.body = body;
1095 p->v.TryFinally.finalbody = finalbody;
1096 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001097 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 return p;
1099}
1100
1101stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001102Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001103{
1104 stmt_ty p;
1105 if (!test) {
1106 PyErr_SetString(PyExc_ValueError,
1107 "field test is required for Assert");
1108 return NULL;
1109 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001110 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001111 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001112 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113 return NULL;
1114 }
1115 p->kind = Assert_kind;
1116 p->v.Assert.test = test;
1117 p->v.Assert.msg = msg;
1118 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001119 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 return p;
1121}
1122
1123stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001124Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125{
1126 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001127 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001129 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001130 return NULL;
1131 }
1132 p->kind = Import_kind;
1133 p->v.Import.names = names;
1134 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001135 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001136 return p;
1137}
1138
1139stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001140ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1141 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001142{
1143 stmt_ty p;
1144 if (!module) {
1145 PyErr_SetString(PyExc_ValueError,
1146 "field module is required for ImportFrom");
1147 return NULL;
1148 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001149 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001150 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001151 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001152 return NULL;
1153 }
1154 p->kind = ImportFrom_kind;
1155 p->v.ImportFrom.module = module;
1156 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001157 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001158 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001159 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001160 return p;
1161}
1162
1163stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001164Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001165{
1166 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001167 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001169 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001170 return NULL;
1171 }
1172 p->kind = Global_kind;
1173 p->v.Global.names = names;
1174 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001175 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001176 return p;
1177}
1178
1179stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001180Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001181{
1182 stmt_ty p;
1183 if (!value) {
1184 PyErr_SetString(PyExc_ValueError,
1185 "field value is required for Expr");
1186 return NULL;
1187 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001188 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001189 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001190 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 return NULL;
1192 }
1193 p->kind = Expr_kind;
1194 p->v.Expr.value = value;
1195 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001196 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 return p;
1198}
1199
1200stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001201Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001202{
1203 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001204 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001205 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001206 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 return NULL;
1208 }
1209 p->kind = Pass_kind;
1210 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001211 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001212 return p;
1213}
1214
1215stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001216Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217{
1218 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001219 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001221 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return NULL;
1223 }
1224 p->kind = Break_kind;
1225 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001226 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 return p;
1228}
1229
1230stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001231Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232{
1233 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001234 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001236 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001237 return NULL;
1238 }
1239 p->kind = Continue_kind;
1240 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001241 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001242 return p;
1243}
1244
1245expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001246BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1247 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001248{
1249 expr_ty p;
1250 if (!op) {
1251 PyErr_SetString(PyExc_ValueError,
1252 "field op is required for BoolOp");
1253 return NULL;
1254 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001255 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001256 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001257 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001258 return NULL;
1259 }
1260 p->kind = BoolOp_kind;
1261 p->v.BoolOp.op = op;
1262 p->v.BoolOp.values = values;
1263 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001264 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001265 return p;
1266}
1267
1268expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001269BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1270 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001271{
1272 expr_ty p;
1273 if (!left) {
1274 PyErr_SetString(PyExc_ValueError,
1275 "field left is required for BinOp");
1276 return NULL;
1277 }
1278 if (!op) {
1279 PyErr_SetString(PyExc_ValueError,
1280 "field op is required for BinOp");
1281 return NULL;
1282 }
1283 if (!right) {
1284 PyErr_SetString(PyExc_ValueError,
1285 "field right is required for BinOp");
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 = BinOp_kind;
1294 p->v.BinOp.left = left;
1295 p->v.BinOp.op = op;
1296 p->v.BinOp.right = right;
1297 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001298 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001299 return p;
1300}
1301
1302expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001303UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1304 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001305{
1306 expr_ty p;
1307 if (!op) {
1308 PyErr_SetString(PyExc_ValueError,
1309 "field op is required for UnaryOp");
1310 return NULL;
1311 }
1312 if (!operand) {
1313 PyErr_SetString(PyExc_ValueError,
1314 "field operand is required for UnaryOp");
1315 return NULL;
1316 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001317 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001319 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001320 return NULL;
1321 }
1322 p->kind = UnaryOp_kind;
1323 p->v.UnaryOp.op = op;
1324 p->v.UnaryOp.operand = operand;
1325 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001326 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001327 return p;
1328}
1329
1330expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001331Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1332 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001333{
1334 expr_ty p;
1335 if (!args) {
1336 PyErr_SetString(PyExc_ValueError,
1337 "field args is required for Lambda");
1338 return NULL;
1339 }
1340 if (!body) {
1341 PyErr_SetString(PyExc_ValueError,
1342 "field body is required for Lambda");
1343 return NULL;
1344 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001345 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001346 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001347 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001348 return NULL;
1349 }
1350 p->kind = Lambda_kind;
1351 p->v.Lambda.args = args;
1352 p->v.Lambda.body = body;
1353 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001354 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001355 return p;
1356}
1357
1358expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001359IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1360 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001361{
1362 expr_ty p;
1363 if (!test) {
1364 PyErr_SetString(PyExc_ValueError,
1365 "field test is required for IfExp");
1366 return NULL;
1367 }
1368 if (!body) {
1369 PyErr_SetString(PyExc_ValueError,
1370 "field body is required for IfExp");
1371 return NULL;
1372 }
1373 if (!orelse) {
1374 PyErr_SetString(PyExc_ValueError,
1375 "field orelse is required for IfExp");
1376 return NULL;
1377 }
1378 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1379 if (!p) {
1380 PyErr_NoMemory();
1381 return NULL;
1382 }
1383 p->kind = IfExp_kind;
1384 p->v.IfExp.test = test;
1385 p->v.IfExp.body = body;
1386 p->v.IfExp.orelse = orelse;
1387 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001388 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001389 return p;
1390}
1391
1392expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001393Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1394 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001395{
1396 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001397 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001398 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001399 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001400 return NULL;
1401 }
1402 p->kind = Dict_kind;
1403 p->v.Dict.keys = keys;
1404 p->v.Dict.values = values;
1405 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001406 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001407 return p;
1408}
1409
1410expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001411Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1412{
1413 expr_ty p;
1414 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1415 if (!p) {
1416 PyErr_NoMemory();
1417 return NULL;
1418 }
1419 p->kind = Set_kind;
1420 p->v.Set.elts = elts;
1421 p->lineno = lineno;
1422 p->col_offset = col_offset;
1423 return p;
1424}
1425
1426expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001427ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1428 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001429{
1430 expr_ty p;
1431 if (!elt) {
1432 PyErr_SetString(PyExc_ValueError,
1433 "field elt is required for ListComp");
1434 return NULL;
1435 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001436 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001437 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001438 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001439 return NULL;
1440 }
1441 p->kind = ListComp_kind;
1442 p->v.ListComp.elt = elt;
1443 p->v.ListComp.generators = generators;
1444 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001445 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001446 return p;
1447}
1448
1449expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001450GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1451 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452{
1453 expr_ty p;
1454 if (!elt) {
1455 PyErr_SetString(PyExc_ValueError,
1456 "field elt is required for GeneratorExp");
1457 return NULL;
1458 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001459 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001460 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001461 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001462 return NULL;
1463 }
1464 p->kind = GeneratorExp_kind;
1465 p->v.GeneratorExp.elt = elt;
1466 p->v.GeneratorExp.generators = generators;
1467 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001468 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469 return p;
1470}
1471
1472expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001473Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001474{
1475 expr_ty p;
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 = Yield_kind;
1482 p->v.Yield.value = value;
1483 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001484 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001485 return p;
1486}
1487
1488expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001489Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1490 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491{
1492 expr_ty p;
1493 if (!left) {
1494 PyErr_SetString(PyExc_ValueError,
1495 "field left is required for Compare");
1496 return NULL;
1497 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001498 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001499 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001500 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001501 return NULL;
1502 }
1503 p->kind = Compare_kind;
1504 p->v.Compare.left = left;
1505 p->v.Compare.ops = ops;
1506 p->v.Compare.comparators = comparators;
1507 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001508 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001509 return p;
1510}
1511
1512expr_ty
1513Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001514 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001515{
1516 expr_ty p;
1517 if (!func) {
1518 PyErr_SetString(PyExc_ValueError,
1519 "field func is required for Call");
1520 return NULL;
1521 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001522 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001523 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001524 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001525 return NULL;
1526 }
1527 p->kind = Call_kind;
1528 p->v.Call.func = func;
1529 p->v.Call.args = args;
1530 p->v.Call.keywords = keywords;
1531 p->v.Call.starargs = starargs;
1532 p->v.Call.kwargs = kwargs;
1533 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001534 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001535 return p;
1536}
1537
1538expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001539Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540{
1541 expr_ty p;
1542 if (!n) {
1543 PyErr_SetString(PyExc_ValueError,
1544 "field n is required for Num");
1545 return NULL;
1546 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001547 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001549 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001550 return NULL;
1551 }
1552 p->kind = Num_kind;
1553 p->v.Num.n = n;
1554 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001555 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001556 return p;
1557}
1558
1559expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001560Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561{
1562 expr_ty p;
1563 if (!s) {
1564 PyErr_SetString(PyExc_ValueError,
1565 "field s is required for Str");
1566 return NULL;
1567 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001568 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001569 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001570 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001571 return NULL;
1572 }
1573 p->kind = Str_kind;
1574 p->v.Str.s = s;
1575 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001576 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001577 return p;
1578}
1579
1580expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001581Ellipsis(int lineno, int col_offset, PyArena *arena)
1582{
1583 expr_ty p;
1584 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1585 if (!p) {
1586 PyErr_NoMemory();
1587 return NULL;
1588 }
1589 p->kind = Ellipsis_kind;
1590 p->lineno = lineno;
1591 p->col_offset = col_offset;
1592 return p;
1593}
1594
1595expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001596Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1597 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001598{
1599 expr_ty p;
1600 if (!value) {
1601 PyErr_SetString(PyExc_ValueError,
1602 "field value is required for Attribute");
1603 return NULL;
1604 }
1605 if (!attr) {
1606 PyErr_SetString(PyExc_ValueError,
1607 "field attr is required for Attribute");
1608 return NULL;
1609 }
1610 if (!ctx) {
1611 PyErr_SetString(PyExc_ValueError,
1612 "field ctx is required for Attribute");
1613 return NULL;
1614 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001615 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001616 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001617 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001618 return NULL;
1619 }
1620 p->kind = Attribute_kind;
1621 p->v.Attribute.value = value;
1622 p->v.Attribute.attr = attr;
1623 p->v.Attribute.ctx = ctx;
1624 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001625 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001626 return p;
1627}
1628
1629expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001630Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1631 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001632{
1633 expr_ty p;
1634 if (!value) {
1635 PyErr_SetString(PyExc_ValueError,
1636 "field value is required for Subscript");
1637 return NULL;
1638 }
1639 if (!slice) {
1640 PyErr_SetString(PyExc_ValueError,
1641 "field slice is required for Subscript");
1642 return NULL;
1643 }
1644 if (!ctx) {
1645 PyErr_SetString(PyExc_ValueError,
1646 "field ctx is required for Subscript");
1647 return NULL;
1648 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001649 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001650 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001651 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 return NULL;
1653 }
1654 p->kind = Subscript_kind;
1655 p->v.Subscript.value = value;
1656 p->v.Subscript.slice = slice;
1657 p->v.Subscript.ctx = ctx;
1658 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001659 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001660 return p;
1661}
1662
1663expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001664Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1665 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001666{
1667 expr_ty p;
1668 if (!id) {
1669 PyErr_SetString(PyExc_ValueError,
1670 "field id is required for Name");
1671 return NULL;
1672 }
1673 if (!ctx) {
1674 PyErr_SetString(PyExc_ValueError,
1675 "field ctx is required for Name");
1676 return NULL;
1677 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001678 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001680 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001681 return NULL;
1682 }
1683 p->kind = Name_kind;
1684 p->v.Name.id = id;
1685 p->v.Name.ctx = ctx;
1686 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001687 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 return p;
1689}
1690
1691expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001692List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1693 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001694{
1695 expr_ty p;
1696 if (!ctx) {
1697 PyErr_SetString(PyExc_ValueError,
1698 "field ctx is required for List");
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 = List_kind;
1707 p->v.List.elts = elts;
1708 p->v.List.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 +00001715Tuple(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 Tuple");
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 = Tuple_kind;
1730 p->v.Tuple.elts = elts;
1731 p->v.Tuple.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
1737slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001738Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001739{
1740 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001741 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001743 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001744 return NULL;
1745 }
1746 p->kind = Slice_kind;
1747 p->v.Slice.lower = lower;
1748 p->v.Slice.upper = upper;
1749 p->v.Slice.step = step;
1750 return p;
1751}
1752
1753slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001754ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001755{
1756 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001757 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001758 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001759 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760 return NULL;
1761 }
1762 p->kind = ExtSlice_kind;
1763 p->v.ExtSlice.dims = dims;
1764 return p;
1765}
1766
1767slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001768Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769{
1770 slice_ty p;
1771 if (!value) {
1772 PyErr_SetString(PyExc_ValueError,
1773 "field value is required for Index");
1774 return NULL;
1775 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001776 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001777 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001778 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001779 return NULL;
1780 }
1781 p->kind = Index_kind;
1782 p->v.Index.value = value;
1783 return p;
1784}
1785
1786comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001787comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001788{
1789 comprehension_ty p;
1790 if (!target) {
1791 PyErr_SetString(PyExc_ValueError,
1792 "field target is required for comprehension");
1793 return NULL;
1794 }
1795 if (!iter) {
1796 PyErr_SetString(PyExc_ValueError,
1797 "field iter is required for comprehension");
1798 return NULL;
1799 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001800 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001801 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001802 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803 return NULL;
1804 }
1805 p->target = target;
1806 p->iter = iter;
1807 p->ifs = ifs;
1808 return p;
1809}
1810
1811excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001812excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001813 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001814{
1815 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001816 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001817 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001818 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001819 return NULL;
1820 }
1821 p->type = type;
1822 p->name = name;
1823 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001824 p->lineno = lineno;
1825 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001826 return p;
1827}
1828
1829arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001830arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1831 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1832 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833{
1834 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001835 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001836 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001837 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001838 return NULL;
1839 }
1840 p->args = args;
1841 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001842 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001843 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001844 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001845 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001847 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 return p;
1849}
1850
Neal Norwitzc1505362006-12-28 06:47:50 +00001851arg_ty
1852SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1853{
1854 arg_ty p;
1855 if (!arg) {
1856 PyErr_SetString(PyExc_ValueError,
1857 "field arg is required for SimpleArg");
1858 return NULL;
1859 }
1860 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1861 if (!p) {
1862 PyErr_NoMemory();
1863 return NULL;
1864 }
1865 p->kind = SimpleArg_kind;
1866 p->v.SimpleArg.arg = arg;
1867 p->v.SimpleArg.annotation = annotation;
1868 return p;
1869}
1870
1871arg_ty
1872NestedArgs(asdl_seq * args, PyArena *arena)
1873{
1874 arg_ty p;
1875 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1876 if (!p) {
1877 PyErr_NoMemory();
1878 return NULL;
1879 }
1880 p->kind = NestedArgs_kind;
1881 p->v.NestedArgs.args = args;
1882 return p;
1883}
1884
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001885keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001886keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001887{
1888 keyword_ty p;
1889 if (!arg) {
1890 PyErr_SetString(PyExc_ValueError,
1891 "field arg is required for keyword");
1892 return NULL;
1893 }
1894 if (!value) {
1895 PyErr_SetString(PyExc_ValueError,
1896 "field value is required for keyword");
1897 return NULL;
1898 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001899 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001900 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001901 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001902 return NULL;
1903 }
1904 p->arg = arg;
1905 p->value = value;
1906 return p;
1907}
1908
1909alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001910alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911{
1912 alias_ty p;
1913 if (!name) {
1914 PyErr_SetString(PyExc_ValueError,
1915 "field name is required for alias");
1916 return NULL;
1917 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001918 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001919 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001920 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001921 return NULL;
1922 }
1923 p->name = name;
1924 p->asname = asname;
1925 return p;
1926}
1927
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001928
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001929PyObject*
1930ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001931{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001932 mod_ty o = (mod_ty)_o;
1933 PyObject *result = NULL, *value = NULL;
1934 if (!o) {
1935 Py_INCREF(Py_None);
1936 return Py_None;
1937 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001938
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001939 switch (o->kind) {
1940 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001941 result = PyType_GenericNew(Module_type, NULL, NULL);
1942 if (!result) goto failed;
1943 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1944 if (!value) goto failed;
1945 if (PyObject_SetAttrString(result, "body", value) == -1)
1946 goto failed;
1947 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948 break;
1949 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001950 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1951 if (!result) goto failed;
1952 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1953 if (!value) goto failed;
1954 if (PyObject_SetAttrString(result, "body", value) == -1)
1955 goto failed;
1956 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001957 break;
1958 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001959 result = PyType_GenericNew(Expression_type, NULL, NULL);
1960 if (!result) goto failed;
1961 value = ast2obj_expr(o->v.Expression.body);
1962 if (!value) goto failed;
1963 if (PyObject_SetAttrString(result, "body", value) == -1)
1964 goto failed;
1965 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 break;
1967 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Suite_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "body", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 return result;
1978failed:
1979 Py_XDECREF(value);
1980 Py_XDECREF(result);
1981 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001982}
1983
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001984PyObject*
1985ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001986{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001987 stmt_ty o = (stmt_ty)_o;
1988 PyObject *result = NULL, *value = NULL;
1989 if (!o) {
1990 Py_INCREF(Py_None);
1991 return Py_None;
1992 }
1993
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001994 switch (o->kind) {
1995 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001996 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1997 if (!result) goto failed;
1998 value = ast2obj_identifier(o->v.FunctionDef.name);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "name", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
2003 value = ast2obj_arguments(o->v.FunctionDef.args);
2004 if (!value) goto failed;
2005 if (PyObject_SetAttrString(result, "args", value) == -1)
2006 goto failed;
2007 Py_DECREF(value);
2008 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2009 if (!value) goto failed;
2010 if (PyObject_SetAttrString(result, "body", value) == -1)
2011 goto failed;
2012 Py_DECREF(value);
2013 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2014 if (!value) goto failed;
2015 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2016 goto failed;
2017 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002018 value = ast2obj_expr(o->v.FunctionDef.returns);
2019 if (!value) goto failed;
2020 if (PyObject_SetAttrString(result, "returns", value) == -1)
2021 goto failed;
2022 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002023 break;
2024 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002025 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2026 if (!result) goto failed;
2027 value = ast2obj_identifier(o->v.ClassDef.name);
2028 if (!value) goto failed;
2029 if (PyObject_SetAttrString(result, "name", value) == -1)
2030 goto failed;
2031 Py_DECREF(value);
2032 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2033 if (!value) goto failed;
2034 if (PyObject_SetAttrString(result, "bases", value) == -1)
2035 goto failed;
2036 Py_DECREF(value);
2037 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2038 if (!value) goto failed;
2039 if (PyObject_SetAttrString(result, "body", value) == -1)
2040 goto failed;
2041 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002042 break;
2043 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002044 result = PyType_GenericNew(Return_type, NULL, NULL);
2045 if (!result) goto failed;
2046 value = ast2obj_expr(o->v.Return.value);
2047 if (!value) goto failed;
2048 if (PyObject_SetAttrString(result, "value", value) == -1)
2049 goto failed;
2050 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002051 break;
2052 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002053 result = PyType_GenericNew(Delete_type, NULL, NULL);
2054 if (!result) goto failed;
2055 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "targets", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002060 break;
2061 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002062 result = PyType_GenericNew(Assign_type, NULL, NULL);
2063 if (!result) goto failed;
2064 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "targets", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
2069 value = ast2obj_expr(o->v.Assign.value);
2070 if (!value) goto failed;
2071 if (PyObject_SetAttrString(result, "value", value) == -1)
2072 goto failed;
2073 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002074 break;
2075 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002076 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2077 if (!result) goto failed;
2078 value = ast2obj_expr(o->v.AugAssign.target);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "target", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
2083 value = ast2obj_operator(o->v.AugAssign.op);
2084 if (!value) goto failed;
2085 if (PyObject_SetAttrString(result, "op", value) == -1)
2086 goto failed;
2087 Py_DECREF(value);
2088 value = ast2obj_expr(o->v.AugAssign.value);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "value", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002093 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002094 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002095 result = PyType_GenericNew(For_type, NULL, NULL);
2096 if (!result) goto failed;
2097 value = ast2obj_expr(o->v.For.target);
2098 if (!value) goto failed;
2099 if (PyObject_SetAttrString(result, "target", value) == -1)
2100 goto failed;
2101 Py_DECREF(value);
2102 value = ast2obj_expr(o->v.For.iter);
2103 if (!value) goto failed;
2104 if (PyObject_SetAttrString(result, "iter", value) == -1)
2105 goto failed;
2106 Py_DECREF(value);
2107 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "body", value) == -1)
2110 goto failed;
2111 Py_DECREF(value);
2112 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2113 if (!value) goto failed;
2114 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2115 goto failed;
2116 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002117 break;
2118 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002119 result = PyType_GenericNew(While_type, NULL, NULL);
2120 if (!result) goto failed;
2121 value = ast2obj_expr(o->v.While.test);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "test", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
2126 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2127 if (!value) goto failed;
2128 if (PyObject_SetAttrString(result, "body", value) == -1)
2129 goto failed;
2130 Py_DECREF(value);
2131 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2132 if (!value) goto failed;
2133 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2134 goto failed;
2135 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002136 break;
2137 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002138 result = PyType_GenericNew(If_type, NULL, NULL);
2139 if (!result) goto failed;
2140 value = ast2obj_expr(o->v.If.test);
2141 if (!value) goto failed;
2142 if (PyObject_SetAttrString(result, "test", value) == -1)
2143 goto failed;
2144 Py_DECREF(value);
2145 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2146 if (!value) goto failed;
2147 if (PyObject_SetAttrString(result, "body", value) == -1)
2148 goto failed;
2149 Py_DECREF(value);
2150 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2151 if (!value) goto failed;
2152 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2153 goto failed;
2154 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002155 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002156 case With_kind:
2157 result = PyType_GenericNew(With_type, NULL, NULL);
2158 if (!result) goto failed;
2159 value = ast2obj_expr(o->v.With.context_expr);
2160 if (!value) goto failed;
2161 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2162 goto failed;
2163 Py_DECREF(value);
2164 value = ast2obj_expr(o->v.With.optional_vars);
2165 if (!value) goto failed;
2166 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2167 -1)
2168 goto failed;
2169 Py_DECREF(value);
2170 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "body", value) == -1)
2173 goto failed;
2174 Py_DECREF(value);
2175 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002176 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002177 result = PyType_GenericNew(Raise_type, NULL, NULL);
2178 if (!result) goto failed;
2179 value = ast2obj_expr(o->v.Raise.type);
2180 if (!value) goto failed;
2181 if (PyObject_SetAttrString(result, "type", value) == -1)
2182 goto failed;
2183 Py_DECREF(value);
2184 value = ast2obj_expr(o->v.Raise.inst);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "inst", value) == -1)
2187 goto failed;
2188 Py_DECREF(value);
2189 value = ast2obj_expr(o->v.Raise.tback);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "tback", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002194 break;
2195 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002196 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2197 if (!result) goto failed;
2198 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2199 if (!value) goto failed;
2200 if (PyObject_SetAttrString(result, "body", value) == -1)
2201 goto failed;
2202 Py_DECREF(value);
2203 value = ast2obj_list(o->v.TryExcept.handlers,
2204 ast2obj_excepthandler);
2205 if (!value) goto failed;
2206 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2207 goto failed;
2208 Py_DECREF(value);
2209 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2210 if (!value) goto failed;
2211 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2212 goto failed;
2213 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002214 break;
2215 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002216 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2217 if (!result) goto failed;
2218 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2219 if (!value) goto failed;
2220 if (PyObject_SetAttrString(result, "body", value) == -1)
2221 goto failed;
2222 Py_DECREF(value);
2223 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2224 if (!value) goto failed;
2225 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2226 goto failed;
2227 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002228 break;
2229 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002230 result = PyType_GenericNew(Assert_type, NULL, NULL);
2231 if (!result) goto failed;
2232 value = ast2obj_expr(o->v.Assert.test);
2233 if (!value) goto failed;
2234 if (PyObject_SetAttrString(result, "test", value) == -1)
2235 goto failed;
2236 Py_DECREF(value);
2237 value = ast2obj_expr(o->v.Assert.msg);
2238 if (!value) goto failed;
2239 if (PyObject_SetAttrString(result, "msg", value) == -1)
2240 goto failed;
2241 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002242 break;
2243 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002244 result = PyType_GenericNew(Import_type, NULL, NULL);
2245 if (!result) goto failed;
2246 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "names", value) == -1)
2249 goto failed;
2250 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 break;
2252 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002253 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_identifier(o->v.ImportFrom.module);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "module", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
2260 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2261 if (!value) goto failed;
2262 if (PyObject_SetAttrString(result, "names", value) == -1)
2263 goto failed;
2264 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002265 value = ast2obj_int(o->v.ImportFrom.level);
2266 if (!value) goto failed;
2267 if (PyObject_SetAttrString(result, "level", value) == -1)
2268 goto failed;
2269 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002270 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002271 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002272 result = PyType_GenericNew(Global_type, NULL, NULL);
2273 if (!result) goto failed;
2274 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2275 if (!value) goto failed;
2276 if (PyObject_SetAttrString(result, "names", value) == -1)
2277 goto failed;
2278 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002279 break;
2280 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002281 result = PyType_GenericNew(Expr_type, NULL, NULL);
2282 if (!result) goto failed;
2283 value = ast2obj_expr(o->v.Expr.value);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "value", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288 break;
2289 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002290 result = PyType_GenericNew(Pass_type, NULL, NULL);
2291 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002292 break;
2293 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002294 result = PyType_GenericNew(Break_type, NULL, NULL);
2295 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002296 break;
2297 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002298 result = PyType_GenericNew(Continue_type, NULL, NULL);
2299 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002300 break;
2301 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002302 value = ast2obj_int(o->lineno);
2303 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002304 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2305 goto failed;
2306 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002307 value = ast2obj_int(o->col_offset);
2308 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002309 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2310 goto failed;
2311 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002312 return result;
2313failed:
2314 Py_XDECREF(value);
2315 Py_XDECREF(result);
2316 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317}
2318
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002319PyObject*
2320ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002321{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002322 expr_ty o = (expr_ty)_o;
2323 PyObject *result = NULL, *value = NULL;
2324 if (!o) {
2325 Py_INCREF(Py_None);
2326 return Py_None;
2327 }
2328
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002329 switch (o->kind) {
2330 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002331 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2332 if (!result) goto failed;
2333 value = ast2obj_boolop(o->v.BoolOp.op);
2334 if (!value) goto failed;
2335 if (PyObject_SetAttrString(result, "op", value) == -1)
2336 goto failed;
2337 Py_DECREF(value);
2338 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2339 if (!value) goto failed;
2340 if (PyObject_SetAttrString(result, "values", value) == -1)
2341 goto failed;
2342 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002343 break;
2344 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002345 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2346 if (!result) goto failed;
2347 value = ast2obj_expr(o->v.BinOp.left);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "left", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
2352 value = ast2obj_operator(o->v.BinOp.op);
2353 if (!value) goto failed;
2354 if (PyObject_SetAttrString(result, "op", value) == -1)
2355 goto failed;
2356 Py_DECREF(value);
2357 value = ast2obj_expr(o->v.BinOp.right);
2358 if (!value) goto failed;
2359 if (PyObject_SetAttrString(result, "right", value) == -1)
2360 goto failed;
2361 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002362 break;
2363 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002364 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2365 if (!result) goto failed;
2366 value = ast2obj_unaryop(o->v.UnaryOp.op);
2367 if (!value) goto failed;
2368 if (PyObject_SetAttrString(result, "op", value) == -1)
2369 goto failed;
2370 Py_DECREF(value);
2371 value = ast2obj_expr(o->v.UnaryOp.operand);
2372 if (!value) goto failed;
2373 if (PyObject_SetAttrString(result, "operand", value) == -1)
2374 goto failed;
2375 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002376 break;
2377 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002378 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2379 if (!result) goto failed;
2380 value = ast2obj_arguments(o->v.Lambda.args);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "args", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
2385 value = ast2obj_expr(o->v.Lambda.body);
2386 if (!value) goto failed;
2387 if (PyObject_SetAttrString(result, "body", value) == -1)
2388 goto failed;
2389 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002390 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002391 case IfExp_kind:
2392 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2393 if (!result) goto failed;
2394 value = ast2obj_expr(o->v.IfExp.test);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "test", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
2399 value = ast2obj_expr(o->v.IfExp.body);
2400 if (!value) goto failed;
2401 if (PyObject_SetAttrString(result, "body", value) == -1)
2402 goto failed;
2403 Py_DECREF(value);
2404 value = ast2obj_expr(o->v.IfExp.orelse);
2405 if (!value) goto failed;
2406 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2407 goto failed;
2408 Py_DECREF(value);
2409 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002410 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002411 result = PyType_GenericNew(Dict_type, NULL, NULL);
2412 if (!result) goto failed;
2413 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2414 if (!value) goto failed;
2415 if (PyObject_SetAttrString(result, "keys", value) == -1)
2416 goto failed;
2417 Py_DECREF(value);
2418 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2419 if (!value) goto failed;
2420 if (PyObject_SetAttrString(result, "values", value) == -1)
2421 goto failed;
2422 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002423 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002424 case Set_kind:
2425 result = PyType_GenericNew(Set_type, NULL, NULL);
2426 if (!result) goto failed;
2427 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "elts", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
2432 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002433 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002434 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2435 if (!result) goto failed;
2436 value = ast2obj_expr(o->v.ListComp.elt);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "elt", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
2441 value = ast2obj_list(o->v.ListComp.generators,
2442 ast2obj_comprehension);
2443 if (!value) goto failed;
2444 if (PyObject_SetAttrString(result, "generators", value) == -1)
2445 goto failed;
2446 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002447 break;
2448 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002449 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2450 if (!result) goto failed;
2451 value = ast2obj_expr(o->v.GeneratorExp.elt);
2452 if (!value) goto failed;
2453 if (PyObject_SetAttrString(result, "elt", value) == -1)
2454 goto failed;
2455 Py_DECREF(value);
2456 value = ast2obj_list(o->v.GeneratorExp.generators,
2457 ast2obj_comprehension);
2458 if (!value) goto failed;
2459 if (PyObject_SetAttrString(result, "generators", value) == -1)
2460 goto failed;
2461 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002462 break;
2463 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002464 result = PyType_GenericNew(Yield_type, NULL, NULL);
2465 if (!result) goto failed;
2466 value = ast2obj_expr(o->v.Yield.value);
2467 if (!value) goto failed;
2468 if (PyObject_SetAttrString(result, "value", value) == -1)
2469 goto failed;
2470 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471 break;
2472 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002473 result = PyType_GenericNew(Compare_type, NULL, NULL);
2474 if (!result) goto failed;
2475 value = ast2obj_expr(o->v.Compare.left);
2476 if (!value) goto failed;
2477 if (PyObject_SetAttrString(result, "left", value) == -1)
2478 goto failed;
2479 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002480 {
2481 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2482 value = PyList_New(n);
2483 if (!value) goto failed;
2484 for(i = 0; i < n; i++)
2485 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2486 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002487 if (!value) goto failed;
2488 if (PyObject_SetAttrString(result, "ops", value) == -1)
2489 goto failed;
2490 Py_DECREF(value);
2491 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496 break;
2497 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002498 result = PyType_GenericNew(Call_type, NULL, NULL);
2499 if (!result) goto failed;
2500 value = ast2obj_expr(o->v.Call.func);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "func", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
2505 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "args", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
2510 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2511 if (!value) goto failed;
2512 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2513 goto failed;
2514 Py_DECREF(value);
2515 value = ast2obj_expr(o->v.Call.starargs);
2516 if (!value) goto failed;
2517 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2518 goto failed;
2519 Py_DECREF(value);
2520 value = ast2obj_expr(o->v.Call.kwargs);
2521 if (!value) goto failed;
2522 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2523 goto failed;
2524 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002525 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002526 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002527 result = PyType_GenericNew(Num_type, NULL, NULL);
2528 if (!result) goto failed;
2529 value = ast2obj_object(o->v.Num.n);
2530 if (!value) goto failed;
2531 if (PyObject_SetAttrString(result, "n", value) == -1)
2532 goto failed;
2533 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002534 break;
2535 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002536 result = PyType_GenericNew(Str_type, NULL, NULL);
2537 if (!result) goto failed;
2538 value = ast2obj_string(o->v.Str.s);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "s", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002543 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002544 case Ellipsis_kind:
2545 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2546 if (!result) goto failed;
2547 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002548 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002549 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2550 if (!result) goto failed;
2551 value = ast2obj_expr(o->v.Attribute.value);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "value", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
2556 value = ast2obj_identifier(o->v.Attribute.attr);
2557 if (!value) goto failed;
2558 if (PyObject_SetAttrString(result, "attr", value) == -1)
2559 goto failed;
2560 Py_DECREF(value);
2561 value = ast2obj_expr_context(o->v.Attribute.ctx);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002566 break;
2567 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002568 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2569 if (!result) goto failed;
2570 value = ast2obj_expr(o->v.Subscript.value);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "value", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
2575 value = ast2obj_slice(o->v.Subscript.slice);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "slice", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_expr_context(o->v.Subscript.ctx);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002585 break;
2586 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002587 result = PyType_GenericNew(Name_type, NULL, NULL);
2588 if (!result) goto failed;
2589 value = ast2obj_identifier(o->v.Name.id);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "id", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
2594 value = ast2obj_expr_context(o->v.Name.ctx);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002599 break;
2600 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002601 result = PyType_GenericNew(List_type, NULL, NULL);
2602 if (!result) goto failed;
2603 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2604 if (!value) goto failed;
2605 if (PyObject_SetAttrString(result, "elts", value) == -1)
2606 goto failed;
2607 Py_DECREF(value);
2608 value = ast2obj_expr_context(o->v.List.ctx);
2609 if (!value) goto failed;
2610 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2611 goto failed;
2612 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002613 break;
2614 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002615 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2616 if (!result) goto failed;
2617 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2618 if (!value) goto failed;
2619 if (PyObject_SetAttrString(result, "elts", value) == -1)
2620 goto failed;
2621 Py_DECREF(value);
2622 value = ast2obj_expr_context(o->v.Tuple.ctx);
2623 if (!value) goto failed;
2624 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2625 goto failed;
2626 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002627 break;
2628 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002629 value = ast2obj_int(o->lineno);
2630 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002631 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2632 goto failed;
2633 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002634 value = ast2obj_int(o->col_offset);
2635 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002636 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2637 goto failed;
2638 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002639 return result;
2640failed:
2641 Py_XDECREF(value);
2642 Py_XDECREF(result);
2643 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002644}
2645
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002646PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648 switch(o) {
2649 case Load:
2650 Py_INCREF(Load_singleton);
2651 return Load_singleton;
2652 case Store:
2653 Py_INCREF(Store_singleton);
2654 return Store_singleton;
2655 case Del:
2656 Py_INCREF(Del_singleton);
2657 return Del_singleton;
2658 case AugLoad:
2659 Py_INCREF(AugLoad_singleton);
2660 return AugLoad_singleton;
2661 case AugStore:
2662 Py_INCREF(AugStore_singleton);
2663 return AugStore_singleton;
2664 case Param:
2665 Py_INCREF(Param_singleton);
2666 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002667 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002668 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002669}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002670PyObject*
2671ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002672{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002673 slice_ty o = (slice_ty)_o;
2674 PyObject *result = NULL, *value = NULL;
2675 if (!o) {
2676 Py_INCREF(Py_None);
2677 return Py_None;
2678 }
2679
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002680 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002681 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002682 result = PyType_GenericNew(Slice_type, NULL, NULL);
2683 if (!result) goto failed;
2684 value = ast2obj_expr(o->v.Slice.lower);
2685 if (!value) goto failed;
2686 if (PyObject_SetAttrString(result, "lower", value) == -1)
2687 goto failed;
2688 Py_DECREF(value);
2689 value = ast2obj_expr(o->v.Slice.upper);
2690 if (!value) goto failed;
2691 if (PyObject_SetAttrString(result, "upper", value) == -1)
2692 goto failed;
2693 Py_DECREF(value);
2694 value = ast2obj_expr(o->v.Slice.step);
2695 if (!value) goto failed;
2696 if (PyObject_SetAttrString(result, "step", value) == -1)
2697 goto failed;
2698 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002699 break;
2700 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002701 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2702 if (!result) goto failed;
2703 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2704 if (!value) goto failed;
2705 if (PyObject_SetAttrString(result, "dims", value) == -1)
2706 goto failed;
2707 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002708 break;
2709 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002710 result = PyType_GenericNew(Index_type, NULL, NULL);
2711 if (!result) goto failed;
2712 value = ast2obj_expr(o->v.Index.value);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "value", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717 break;
2718 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002719 return result;
2720failed:
2721 Py_XDECREF(value);
2722 Py_XDECREF(result);
2723 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002724}
2725
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002726PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002727{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002728 switch(o) {
2729 case And:
2730 Py_INCREF(And_singleton);
2731 return And_singleton;
2732 case Or:
2733 Py_INCREF(Or_singleton);
2734 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002735 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002736 return NULL; /* cannot happen */
2737}
2738PyObject* ast2obj_operator(operator_ty o)
2739{
2740 switch(o) {
2741 case Add:
2742 Py_INCREF(Add_singleton);
2743 return Add_singleton;
2744 case Sub:
2745 Py_INCREF(Sub_singleton);
2746 return Sub_singleton;
2747 case Mult:
2748 Py_INCREF(Mult_singleton);
2749 return Mult_singleton;
2750 case Div:
2751 Py_INCREF(Div_singleton);
2752 return Div_singleton;
2753 case Mod:
2754 Py_INCREF(Mod_singleton);
2755 return Mod_singleton;
2756 case Pow:
2757 Py_INCREF(Pow_singleton);
2758 return Pow_singleton;
2759 case LShift:
2760 Py_INCREF(LShift_singleton);
2761 return LShift_singleton;
2762 case RShift:
2763 Py_INCREF(RShift_singleton);
2764 return RShift_singleton;
2765 case BitOr:
2766 Py_INCREF(BitOr_singleton);
2767 return BitOr_singleton;
2768 case BitXor:
2769 Py_INCREF(BitXor_singleton);
2770 return BitXor_singleton;
2771 case BitAnd:
2772 Py_INCREF(BitAnd_singleton);
2773 return BitAnd_singleton;
2774 case FloorDiv:
2775 Py_INCREF(FloorDiv_singleton);
2776 return FloorDiv_singleton;
2777 }
2778 return NULL; /* cannot happen */
2779}
2780PyObject* ast2obj_unaryop(unaryop_ty o)
2781{
2782 switch(o) {
2783 case Invert:
2784 Py_INCREF(Invert_singleton);
2785 return Invert_singleton;
2786 case Not:
2787 Py_INCREF(Not_singleton);
2788 return Not_singleton;
2789 case UAdd:
2790 Py_INCREF(UAdd_singleton);
2791 return UAdd_singleton;
2792 case USub:
2793 Py_INCREF(USub_singleton);
2794 return USub_singleton;
2795 }
2796 return NULL; /* cannot happen */
2797}
2798PyObject* ast2obj_cmpop(cmpop_ty o)
2799{
2800 switch(o) {
2801 case Eq:
2802 Py_INCREF(Eq_singleton);
2803 return Eq_singleton;
2804 case NotEq:
2805 Py_INCREF(NotEq_singleton);
2806 return NotEq_singleton;
2807 case Lt:
2808 Py_INCREF(Lt_singleton);
2809 return Lt_singleton;
2810 case LtE:
2811 Py_INCREF(LtE_singleton);
2812 return LtE_singleton;
2813 case Gt:
2814 Py_INCREF(Gt_singleton);
2815 return Gt_singleton;
2816 case GtE:
2817 Py_INCREF(GtE_singleton);
2818 return GtE_singleton;
2819 case Is:
2820 Py_INCREF(Is_singleton);
2821 return Is_singleton;
2822 case IsNot:
2823 Py_INCREF(IsNot_singleton);
2824 return IsNot_singleton;
2825 case In:
2826 Py_INCREF(In_singleton);
2827 return In_singleton;
2828 case NotIn:
2829 Py_INCREF(NotIn_singleton);
2830 return NotIn_singleton;
2831 }
2832 return NULL; /* cannot happen */
2833}
2834PyObject*
2835ast2obj_comprehension(void* _o)
2836{
2837 comprehension_ty o = (comprehension_ty)_o;
2838 PyObject *result = NULL, *value = NULL;
2839 if (!o) {
2840 Py_INCREF(Py_None);
2841 return Py_None;
2842 }
2843
2844 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2845 if (!result) return NULL;
2846 value = ast2obj_expr(o->target);
2847 if (!value) goto failed;
2848 if (PyObject_SetAttrString(result, "target", value) == -1)
2849 goto failed;
2850 Py_DECREF(value);
2851 value = ast2obj_expr(o->iter);
2852 if (!value) goto failed;
2853 if (PyObject_SetAttrString(result, "iter", value) == -1)
2854 goto failed;
2855 Py_DECREF(value);
2856 value = ast2obj_list(o->ifs, ast2obj_expr);
2857 if (!value) goto failed;
2858 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2859 goto failed;
2860 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002861 return result;
2862failed:
2863 Py_XDECREF(value);
2864 Py_XDECREF(result);
2865 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002866}
2867
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002868PyObject*
2869ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002870{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002871 excepthandler_ty o = (excepthandler_ty)_o;
2872 PyObject *result = NULL, *value = NULL;
2873 if (!o) {
2874 Py_INCREF(Py_None);
2875 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002876 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002877
2878 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2879 if (!result) return NULL;
2880 value = ast2obj_expr(o->type);
2881 if (!value) goto failed;
2882 if (PyObject_SetAttrString(result, "type", value) == -1)
2883 goto failed;
2884 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002885 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002886 if (!value) goto failed;
2887 if (PyObject_SetAttrString(result, "name", value) == -1)
2888 goto failed;
2889 Py_DECREF(value);
2890 value = ast2obj_list(o->body, ast2obj_stmt);
2891 if (!value) goto failed;
2892 if (PyObject_SetAttrString(result, "body", value) == -1)
2893 goto failed;
2894 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002895 value = ast2obj_int(o->lineno);
2896 if (!value) goto failed;
2897 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2898 goto failed;
2899 Py_DECREF(value);
2900 value = ast2obj_int(o->col_offset);
2901 if (!value) goto failed;
2902 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2903 goto failed;
2904 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002905 return result;
2906failed:
2907 Py_XDECREF(value);
2908 Py_XDECREF(result);
2909 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002910}
2911
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002912PyObject*
2913ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002914{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002915 arguments_ty o = (arguments_ty)_o;
2916 PyObject *result = NULL, *value = NULL;
2917 if (!o) {
2918 Py_INCREF(Py_None);
2919 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002920 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002921
2922 result = PyType_GenericNew(arguments_type, NULL, NULL);
2923 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002924 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002925 if (!value) goto failed;
2926 if (PyObject_SetAttrString(result, "args", value) == -1)
2927 goto failed;
2928 Py_DECREF(value);
2929 value = ast2obj_identifier(o->vararg);
2930 if (!value) goto failed;
2931 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2932 goto failed;
2933 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002934 value = ast2obj_expr(o->varargannotation);
2935 if (!value) goto failed;
2936 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2937 goto failed;
2938 Py_DECREF(value);
2939 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002940 if (!value) goto failed;
2941 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2942 goto failed;
2943 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002944 value = ast2obj_identifier(o->kwarg);
2945 if (!value) goto failed;
2946 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2947 goto failed;
2948 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002949 value = ast2obj_expr(o->kwargannotation);
2950 if (!value) goto failed;
2951 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2952 goto failed;
2953 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002954 value = ast2obj_list(o->defaults, ast2obj_expr);
2955 if (!value) goto failed;
2956 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2957 goto failed;
2958 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002959 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2960 if (!value) goto failed;
2961 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2962 goto failed;
2963 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002964 return result;
2965failed:
2966 Py_XDECREF(value);
2967 Py_XDECREF(result);
2968 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002969}
2970
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002971PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002972ast2obj_arg(void* _o)
2973{
2974 arg_ty o = (arg_ty)_o;
2975 PyObject *result = NULL, *value = NULL;
2976 if (!o) {
2977 Py_INCREF(Py_None);
2978 return Py_None;
2979 }
2980
2981 switch (o->kind) {
2982 case SimpleArg_kind:
2983 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2984 if (!result) goto failed;
2985 value = ast2obj_identifier(o->v.SimpleArg.arg);
2986 if (!value) goto failed;
2987 if (PyObject_SetAttrString(result, "arg", value) == -1)
2988 goto failed;
2989 Py_DECREF(value);
2990 value = ast2obj_expr(o->v.SimpleArg.annotation);
2991 if (!value) goto failed;
2992 if (PyObject_SetAttrString(result, "annotation", value) == -1)
2993 goto failed;
2994 Py_DECREF(value);
2995 break;
2996 case NestedArgs_kind:
2997 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
2998 if (!result) goto failed;
2999 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3000 if (!value) goto failed;
3001 if (PyObject_SetAttrString(result, "args", value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
3004 break;
3005 }
3006 return result;
3007failed:
3008 Py_XDECREF(value);
3009 Py_XDECREF(result);
3010 return NULL;
3011}
3012
3013PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003014ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003015{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003016 keyword_ty o = (keyword_ty)_o;
3017 PyObject *result = NULL, *value = NULL;
3018 if (!o) {
3019 Py_INCREF(Py_None);
3020 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003021 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003022
3023 result = PyType_GenericNew(keyword_type, NULL, NULL);
3024 if (!result) return NULL;
3025 value = ast2obj_identifier(o->arg);
3026 if (!value) goto failed;
3027 if (PyObject_SetAttrString(result, "arg", value) == -1)
3028 goto failed;
3029 Py_DECREF(value);
3030 value = ast2obj_expr(o->value);
3031 if (!value) goto failed;
3032 if (PyObject_SetAttrString(result, "value", value) == -1)
3033 goto failed;
3034 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003035 return result;
3036failed:
3037 Py_XDECREF(value);
3038 Py_XDECREF(result);
3039 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003040}
3041
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003042PyObject*
3043ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003044{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003045 alias_ty o = (alias_ty)_o;
3046 PyObject *result = NULL, *value = NULL;
3047 if (!o) {
3048 Py_INCREF(Py_None);
3049 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003050 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003051
3052 result = PyType_GenericNew(alias_type, NULL, NULL);
3053 if (!result) return NULL;
3054 value = ast2obj_identifier(o->name);
3055 if (!value) goto failed;
3056 if (PyObject_SetAttrString(result, "name", value) == -1)
3057 goto failed;
3058 Py_DECREF(value);
3059 value = ast2obj_identifier(o->asname);
3060 if (!value) goto failed;
3061 if (PyObject_SetAttrString(result, "asname", value) == -1)
3062 goto failed;
3063 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003064 return result;
3065failed:
3066 Py_XDECREF(value);
3067 Py_XDECREF(result);
3068 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003069}
3070
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003071
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003072PyMODINIT_FUNC
3073init_ast(void)
3074{
3075 PyObject *m, *d;
3076 if (!init_types()) return;
3077 m = Py_InitModule3("_ast", NULL, NULL);
3078 if (!m) return;
3079 d = PyModule_GetDict(m);
3080 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3081 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3082 return;
Georg Brandlc2d9d7f2007-02-11 23:06:17 +00003083 if (PyModule_AddStringConstant(m, "__version__", "53704") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003084 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003085 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3086 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3087 return;
3088 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3089 < 0) return;
3090 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3091 0) return;
3092 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3093 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3094 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3095 < 0) return;
3096 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3097 return;
3098 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3099 return;
3100 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3103 return;
3104 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3105 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003106 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3107 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3108 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3109 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3110 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3111 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3112 0) return;
3113 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3114 0) return;
3115 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3116 return;
3117 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3118 return;
3119 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3120 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003121 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3122 return;
3123 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3124 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3126 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3129 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3130 return;
3131 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3132 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3133 return;
3134 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3135 return;
3136 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003138 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003139 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3140 return;
3141 if (PyDict_SetItemString(d, "GeneratorExp",
3142 (PyObject*)GeneratorExp_type) < 0) return;
3143 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3144 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3145 return;
3146 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003147 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3148 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003149 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3150 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003151 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3152 0) return;
3153 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3154 0) return;
3155 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3156 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3157 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3158 if (PyDict_SetItemString(d, "expr_context",
3159 (PyObject*)expr_context_type) < 0) return;
3160 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3161 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3162 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3163 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3164 return;
3165 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3166 return;
3167 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3168 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003169 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3170 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3171 return;
3172 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3173 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3174 return;
3175 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3176 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3177 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3178 return;
3179 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3180 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3181 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3182 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3183 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3184 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3185 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3186 return;
3187 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3188 return;
3189 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3190 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3191 return;
3192 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3193 return;
3194 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3195 return;
3196 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3197 return;
3198 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3199 return;
3200 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3201 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3202 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3203 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3204 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3205 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3206 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3207 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3208 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3209 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3210 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3211 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3212 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3213 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3214 if (PyDict_SetItemString(d, "comprehension",
3215 (PyObject*)comprehension_type) < 0) return;
3216 if (PyDict_SetItemString(d, "excepthandler",
3217 (PyObject*)excepthandler_type) < 0) return;
3218 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3219 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003220 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3221 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3222 0) return;
3223 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3224 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003225 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3226 return;
3227 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003228}
3229
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003230
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003231PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003232{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003233 init_types();
3234 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003235}
3236
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003237