blob: 3644945af9a1cdbf3968f4fd811d9c8742ae10b1 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum8981ad02007-04-16 17:02:00 +00005 __version__ 54835.
Thomas Wouterscf297e42007-02-23 15:07:44 +00006
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
10*/
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000011
12#include "Python.h"
13#include "Python-ast.h"
14
Neal Norwitz53d960c2006-02-28 22:47:29 +000015static PyTypeObject* AST_type;
16static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000017static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000018static PyTypeObject *Module_type;
19static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000020 "body",
21};
Neal Norwitz53d960c2006-02-28 22:47:29 +000022static PyTypeObject *Interactive_type;
23static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000024 "body",
25};
Neal Norwitz53d960c2006-02-28 22:47:29 +000026static PyTypeObject *Expression_type;
27static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000028 "body",
29};
Neal Norwitz53d960c2006-02-28 22:47:29 +000030static PyTypeObject *Suite_type;
31static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000032 "body",
33};
Neal Norwitz53d960c2006-02-28 22:47:29 +000034static PyTypeObject *stmt_type;
35static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000036 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000037 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000038};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000039static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000040static PyTypeObject *FunctionDef_type;
41static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000042 "name",
43 "args",
44 "body",
45 "decorators",
Neal Norwitzc1505362006-12-28 06:47:50 +000046 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *ClassDef_type;
49static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "name",
51 "bases",
Guido van Rossum52cc1d82007-03-18 15:41:51 +000052 "keywords",
53 "starargs",
54 "kwargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000055 "body",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *Return_type;
58static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "value",
60};
Neal Norwitz53d960c2006-02-28 22:47:29 +000061static PyTypeObject *Delete_type;
62static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000063 "targets",
64};
Neal Norwitz53d960c2006-02-28 22:47:29 +000065static PyTypeObject *Assign_type;
66static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000067 "targets",
68 "value",
69};
Neal Norwitz53d960c2006-02-28 22:47:29 +000070static PyTypeObject *AugAssign_type;
71static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000072 "target",
73 "op",
74 "value",
75};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *For_type;
77static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000078 "target",
79 "iter",
80 "body",
81 "orelse",
82};
Neal Norwitz53d960c2006-02-28 22:47:29 +000083static PyTypeObject *While_type;
84static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000085 "test",
86 "body",
87 "orelse",
88};
Neal Norwitz53d960c2006-02-28 22:47:29 +000089static PyTypeObject *If_type;
90static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000091 "test",
92 "body",
93 "orelse",
94};
Neal Norwitz53d960c2006-02-28 22:47:29 +000095static PyTypeObject *With_type;
96static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000097 "context_expr",
98 "optional_vars",
99 "body",
100};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000101static PyTypeObject *Raise_type;
102static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000103 "type",
104 "inst",
105 "tback",
106};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000107static PyTypeObject *TryExcept_type;
108static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000109 "body",
110 "handlers",
111 "orelse",
112};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000113static PyTypeObject *TryFinally_type;
114static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000115 "body",
116 "finalbody",
117};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000118static PyTypeObject *Assert_type;
119static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000120 "test",
121 "msg",
122};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000123static PyTypeObject *Import_type;
124static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000125 "names",
126};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000127static PyTypeObject *ImportFrom_type;
128static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000129 "module",
130 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000131 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000132};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000133static PyTypeObject *Global_type;
134static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000135 "names",
136};
Jeremy Hylton81e95022007-02-27 06:50:52 +0000137static PyTypeObject *Nonlocal_type;
138static char *Nonlocal_fields[]={
139 "names",
140};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000141static PyTypeObject *Expr_type;
142static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000143 "value",
144};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000145static PyTypeObject *Pass_type;
146static PyTypeObject *Break_type;
147static PyTypeObject *Continue_type;
148static PyTypeObject *expr_type;
149static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000150 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000151 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000152};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000153static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *BoolOp_type;
155static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "op",
157 "values",
158};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000159static PyTypeObject *BinOp_type;
160static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000161 "left",
162 "op",
163 "right",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *UnaryOp_type;
166static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "op",
168 "operand",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *Lambda_type;
171static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000172 "args",
173 "body",
174};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000175static PyTypeObject *IfExp_type;
176static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000177 "test",
178 "body",
179 "orelse",
180};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000181static PyTypeObject *Dict_type;
182static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000183 "keys",
184 "values",
185};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000186static PyTypeObject *Set_type;
187static char *Set_fields[]={
188 "elts",
189};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000190static PyTypeObject *ListComp_type;
191static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000192 "elt",
193 "generators",
194};
Nick Coghlan650f0d02007-04-15 12:05:43 +0000195static PyTypeObject *SetComp_type;
196static char *SetComp_fields[]={
197 "elt",
198 "generators",
199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *GeneratorExp_type;
201static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000202 "elt",
203 "generators",
204};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000205static PyTypeObject *Yield_type;
206static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000207 "value",
208};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000209static PyTypeObject *Compare_type;
210static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000211 "left",
212 "ops",
213 "comparators",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Call_type;
216static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "func",
218 "args",
219 "keywords",
220 "starargs",
221 "kwargs",
222};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000223static PyTypeObject *Num_type;
224static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000225 "n",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Str_type;
228static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "s",
230};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000231static PyTypeObject *Bytes_type;
232static char *Bytes_fields[]={
233 "s",
234};
Georg Brandl52318d62006-09-06 07:06:08 +0000235static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000236static PyTypeObject *Attribute_type;
237static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000238 "value",
239 "attr",
240 "ctx",
241};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Subscript_type;
243static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244 "value",
245 "slice",
246 "ctx",
247};
Guido van Rossum0368b722007-05-11 16:50:42 +0000248static PyTypeObject *Starred_type;
249static char *Starred_fields[]={
250 "value",
251 "ctx",
252};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000253static PyTypeObject *Name_type;
254static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255 "id",
256 "ctx",
257};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000258static PyTypeObject *List_type;
259static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000260 "elts",
261 "ctx",
262};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000263static PyTypeObject *Tuple_type;
264static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000265 "elts",
266 "ctx",
267};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000268static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
270*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
271static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000272static PyTypeObject *Load_type;
273static PyTypeObject *Store_type;
274static PyTypeObject *Del_type;
275static PyTypeObject *AugLoad_type;
276static PyTypeObject *AugStore_type;
277static PyTypeObject *Param_type;
278static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000279static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *Slice_type;
281static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000282 "lower",
283 "upper",
284 "step",
285};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000286static PyTypeObject *ExtSlice_type;
287static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000288 "dims",
289};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000290static PyTypeObject *Index_type;
291static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000292 "value",
293};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000294static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295static PyObject *And_singleton, *Or_singleton;
296static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000297static PyTypeObject *And_type;
298static PyTypeObject *Or_type;
299static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000300static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
301*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
302*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
303*FloorDiv_singleton;
304static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000305static PyTypeObject *Add_type;
306static PyTypeObject *Sub_type;
307static PyTypeObject *Mult_type;
308static PyTypeObject *Div_type;
309static PyTypeObject *Mod_type;
310static PyTypeObject *Pow_type;
311static PyTypeObject *LShift_type;
312static PyTypeObject *RShift_type;
313static PyTypeObject *BitOr_type;
314static PyTypeObject *BitXor_type;
315static PyTypeObject *BitAnd_type;
316static PyTypeObject *FloorDiv_type;
317static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000318static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
319*USub_singleton;
320static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000321static PyTypeObject *Invert_type;
322static PyTypeObject *Not_type;
323static PyTypeObject *UAdd_type;
324static PyTypeObject *USub_type;
325static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000326static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
327*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
328*NotIn_singleton;
329static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static PyTypeObject *Eq_type;
331static PyTypeObject *NotEq_type;
332static PyTypeObject *Lt_type;
333static PyTypeObject *LtE_type;
334static PyTypeObject *Gt_type;
335static PyTypeObject *GtE_type;
336static PyTypeObject *Is_type;
337static PyTypeObject *IsNot_type;
338static PyTypeObject *In_type;
339static PyTypeObject *NotIn_type;
340static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000341static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000342static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000343 "target",
344 "iter",
345 "ifs",
346};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000347static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350 "type",
351 "name",
352 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000353 "lineno",
354 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000355};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000356static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000357static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000358static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000359 "args",
360 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000361 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000362 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000363 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000364 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000365 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000366 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000367};
Neal Norwitzc1505362006-12-28 06:47:50 +0000368static PyTypeObject *arg_type;
369static PyObject* ast2obj_arg(void*);
370static PyTypeObject *SimpleArg_type;
371static char *SimpleArg_fields[]={
372 "arg",
373 "annotation",
374};
375static PyTypeObject *NestedArgs_type;
376static char *NestedArgs_fields[]={
377 "args",
378};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000379static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000380static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000381static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000382 "arg",
383 "value",
384};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000385static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000386static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000387static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000388 "name",
389 "asname",
390};
391
392
393static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
394{
395 PyObject *fnames, *result;
396 int i;
397 if (num_fields) {
398 fnames = PyTuple_New(num_fields);
399 if (!fnames) return NULL;
400 } else {
401 fnames = Py_None;
402 Py_INCREF(Py_None);
403 }
404 for(i=0; i < num_fields; i++) {
405 PyObject *field = PyString_FromString(fields[i]);
406 if (!field) {
407 Py_DECREF(fnames);
408 return NULL;
409 }
410 PyTuple_SET_ITEM(fnames, i, field);
411 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000412 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000413 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000414 Py_DECREF(fnames);
415 return (PyTypeObject*)result;
416}
417
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000418static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
419{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000420 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000421 PyObject *s, *l = PyList_New(num_fields);
422 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000423 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000424 s = PyString_FromString(attrs[i]);
425 if (!s) {
426 Py_DECREF(l);
427 return 0;
428 }
429 PyList_SET_ITEM(l, i, s);
430 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000431 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
432 Py_DECREF(l);
433 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000434}
435
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000436static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
437{
438 int i, n = asdl_seq_LEN(seq);
439 PyObject *result = PyList_New(n);
440 PyObject *value;
441 if (!result)
442 return NULL;
443 for (i = 0; i < n; i++) {
444 value = func(asdl_seq_GET(seq, i));
445 if (!value) {
446 Py_DECREF(result);
447 return NULL;
448 }
449 PyList_SET_ITEM(result, i, value);
450 }
451 return result;
452}
453
454static PyObject* ast2obj_object(void *o)
455{
456 if (!o)
457 o = Py_None;
458 Py_INCREF((PyObject*)o);
459 return (PyObject*)o;
460}
461#define ast2obj_identifier ast2obj_object
462#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000464static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000465{
466 return PyInt_FromLong(b);
467}
468
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469static int init_types(void)
470{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000471 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
474 mod_type = make_type("mod", AST_type, NULL, 0);
475 if (!mod_type) return 0;
476 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Interactive_type = make_type("Interactive", mod_type,
480 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Expression_type = make_type("Expression", mod_type, Expression_fields,
483 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000484 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!Suite_type) return 0;
487 stmt_type = make_type("stmt", AST_type, NULL, 0);
488 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000489 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000491 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!FunctionDef_type) return 0;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000493 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000509 With_type = make_type("With", stmt_type, With_fields, 3);
510 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000511 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000512 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000513 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000515 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
516 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000523 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000527 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
528 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000531 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000533 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000535 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Continue_type) return 0;
537 expr_type = make_type("expr", AST_type, NULL, 0);
538 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000539 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000548 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000552 Set_type = make_type("Set", expr_type, Set_fields, 1);
553 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000556 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
557 if (!SetComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 GeneratorExp_type = make_type("GeneratorExp", expr_type,
559 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000560 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000561 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000562 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000563 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000564 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000565 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000567 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000569 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000571 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
572 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000573 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
574 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000575 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Subscript_type) return 0;
Guido van Rossum0368b722007-05-11 16:50:42 +0000579 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
580 if (!Starred_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Tuple_type) return 0;
587 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
588 if (!expr_context_type) return 0;
589 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000594 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000598 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000600 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000602 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000604 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000606 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000607 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000608 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000609 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000610 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000611 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000612 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!Param_singleton) return 0;
614 slice_type = make_type("slice", AST_type, NULL, 0);
615 if (!slice_type) return 0;
616 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000619 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Index_type) return 0;
623 boolop_type = make_type("boolop", AST_type, NULL, 0);
624 if (!boolop_type) return 0;
625 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000626 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000628 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000630 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000632 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Or_singleton) return 0;
634 operator_type = make_type("operator", AST_type, NULL, 0);
635 if (!operator_type) return 0;
636 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000637 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000639 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000645 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000647 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000649 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000651 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000653 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000655 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000656 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000657 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000658 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000659 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000660 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000661 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000662 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000663 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000664 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000665 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000667 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!FloorDiv_singleton) return 0;
685 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
686 if (!unaryop_type) return 0;
687 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000688 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000690 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000692 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000694 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000696 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000698 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000700 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!USub_singleton) return 0;
704 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
705 if (!cmpop_type) return 0;
706 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000707 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000709 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000711 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000713 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000715 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000717 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000719 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000721 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000722 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000723 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000724 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000725 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000727 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000728 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000729 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000730 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000731 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000732 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000733 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000734 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000735 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000736 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000737 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000738 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000739 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000740 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000741 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000742 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000743 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000744 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000745 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000746 if (!NotIn_singleton) return 0;
747 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000748 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000749 if (!comprehension_type) return 0;
750 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000751 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000752 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000753 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000754 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000755 arg_type = make_type("arg", AST_type, NULL, 0);
756 if (!arg_type) return 0;
757 if (!add_attributes(arg_type, NULL, 0)) return 0;
758 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
759 if (!SimpleArg_type) return 0;
760 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
761 1);
762 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000763 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
764 if (!keyword_type) return 0;
765 alias_type = make_type("alias", AST_type, alias_fields, 2);
766 if (!alias_type) return 0;
767 initialized = 1;
768 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000769}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000770
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000772Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000773{
774 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000775 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000776 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000777 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778 p->kind = Module_kind;
779 p->v.Module.body = body;
780 return p;
781}
782
783mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000784Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000785{
786 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000787 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000788 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000789 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000790 p->kind = Interactive_kind;
791 p->v.Interactive.body = body;
792 return p;
793}
794
795mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000796Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000797{
798 mod_ty p;
799 if (!body) {
800 PyErr_SetString(PyExc_ValueError,
801 "field body is required for Expression");
802 return NULL;
803 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000804 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000805 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000806 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000807 p->kind = Expression_kind;
808 p->v.Expression.body = body;
809 return p;
810}
811
812mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000813Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000814{
815 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000816 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000817 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000818 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000819 p->kind = Suite_kind;
820 p->v.Suite.body = body;
821 return p;
822}
823
824stmt_ty
825FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000826 decorators, expr_ty returns, int lineno, int col_offset, PyArena
827 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000828{
829 stmt_ty p;
830 if (!name) {
831 PyErr_SetString(PyExc_ValueError,
832 "field name is required for FunctionDef");
833 return NULL;
834 }
835 if (!args) {
836 PyErr_SetString(PyExc_ValueError,
837 "field args is required for FunctionDef");
838 return NULL;
839 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000840 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000841 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 p->kind = FunctionDef_kind;
844 p->v.FunctionDef.name = name;
845 p->v.FunctionDef.args = args;
846 p->v.FunctionDef.body = body;
847 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000848 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 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
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000855ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
856 starargs, expr_ty kwargs, asdl_seq * body, int lineno, int col_offset,
857 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858{
859 stmt_ty p;
860 if (!name) {
861 PyErr_SetString(PyExc_ValueError,
862 "field name is required for ClassDef");
863 return NULL;
864 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000865 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000866 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868 p->kind = ClassDef_kind;
869 p->v.ClassDef.name = name;
870 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000871 p->v.ClassDef.keywords = keywords;
872 p->v.ClassDef.starargs = starargs;
873 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 p->v.ClassDef.body = body;
875 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000876 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877 return p;
878}
879
880stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882{
883 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000884 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000885 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000886 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887 p->kind = Return_kind;
888 p->v.Return.value = value;
889 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000890 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000891 return p;
892}
893
894stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000895Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896{
897 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000898 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000899 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000900 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000901 p->kind = Delete_kind;
902 p->v.Delete.targets = targets;
903 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000904 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000905 return p;
906}
907
908stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000909Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
910 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000911{
912 stmt_ty p;
913 if (!value) {
914 PyErr_SetString(PyExc_ValueError,
915 "field value is required for Assign");
916 return NULL;
917 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000918 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000919 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000920 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000921 p->kind = Assign_kind;
922 p->v.Assign.targets = targets;
923 p->v.Assign.value = value;
924 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000925 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000926 return p;
927}
928
929stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000930AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
931 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000932{
933 stmt_ty p;
934 if (!target) {
935 PyErr_SetString(PyExc_ValueError,
936 "field target is required for AugAssign");
937 return NULL;
938 }
939 if (!op) {
940 PyErr_SetString(PyExc_ValueError,
941 "field op is required for AugAssign");
942 return NULL;
943 }
944 if (!value) {
945 PyErr_SetString(PyExc_ValueError,
946 "field value is required for AugAssign");
947 return NULL;
948 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000949 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000950 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000952 p->kind = AugAssign_kind;
953 p->v.AugAssign.target = target;
954 p->v.AugAssign.op = op;
955 p->v.AugAssign.value = value;
956 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000957 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000958 return p;
959}
960
961stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000962For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000963 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964{
965 stmt_ty p;
966 if (!target) {
967 PyErr_SetString(PyExc_ValueError,
968 "field target is required for For");
969 return NULL;
970 }
971 if (!iter) {
972 PyErr_SetString(PyExc_ValueError,
973 "field iter is required for For");
974 return NULL;
975 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000976 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000977 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000978 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 p->kind = For_kind;
980 p->v.For.target = target;
981 p->v.For.iter = iter;
982 p->v.For.body = body;
983 p->v.For.orelse = orelse;
984 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000985 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000986 return p;
987}
988
989stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000990While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
991 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000992{
993 stmt_ty p;
994 if (!test) {
995 PyErr_SetString(PyExc_ValueError,
996 "field test is required for While");
997 return NULL;
998 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000999 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001000 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001002 p->kind = While_kind;
1003 p->v.While.test = test;
1004 p->v.While.body = body;
1005 p->v.While.orelse = orelse;
1006 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001007 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001008 return p;
1009}
1010
1011stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001012If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1013 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001014{
1015 stmt_ty p;
1016 if (!test) {
1017 PyErr_SetString(PyExc_ValueError,
1018 "field test is required for If");
1019 return NULL;
1020 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001021 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001022 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001023 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001024 p->kind = If_kind;
1025 p->v.If.test = test;
1026 p->v.If.body = body;
1027 p->v.If.orelse = orelse;
1028 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001029 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001030 return p;
1031}
1032
1033stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001034With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001035 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001036{
1037 stmt_ty p;
1038 if (!context_expr) {
1039 PyErr_SetString(PyExc_ValueError,
1040 "field context_expr is required for With");
1041 return NULL;
1042 }
1043 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001044 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001045 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001046 p->kind = With_kind;
1047 p->v.With.context_expr = context_expr;
1048 p->v.With.optional_vars = optional_vars;
1049 p->v.With.body = body;
1050 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001051 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001052 return p;
1053}
1054
1055stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001056Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1057 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001058{
1059 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001060 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001061 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063 p->kind = Raise_kind;
1064 p->v.Raise.type = type;
1065 p->v.Raise.inst = inst;
1066 p->v.Raise.tback = tback;
1067 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001068 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001069 return p;
1070}
1071
1072stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001073TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001074 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075{
1076 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001077 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001078 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001080 p->kind = TryExcept_kind;
1081 p->v.TryExcept.body = body;
1082 p->v.TryExcept.handlers = handlers;
1083 p->v.TryExcept.orelse = orelse;
1084 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001085 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001086 return p;
1087}
1088
1089stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001090TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1091 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092{
1093 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001094 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001095 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001097 p->kind = TryFinally_kind;
1098 p->v.TryFinally.body = body;
1099 p->v.TryFinally.finalbody = finalbody;
1100 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001101 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001102 return p;
1103}
1104
1105stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001106Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107{
1108 stmt_ty p;
1109 if (!test) {
1110 PyErr_SetString(PyExc_ValueError,
1111 "field test is required for Assert");
1112 return NULL;
1113 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001114 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001115 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001117 p->kind = Assert_kind;
1118 p->v.Assert.test = test;
1119 p->v.Assert.msg = msg;
1120 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001121 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return p;
1123}
1124
1125stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001126Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001127{
1128 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001129 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001130 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001132 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));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001150 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001152 p->kind = ImportFrom_kind;
1153 p->v.ImportFrom.module = module;
1154 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001155 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001156 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001157 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001158 return p;
1159}
1160
1161stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001162Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163{
1164 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001165 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001166 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168 p->kind = Global_kind;
1169 p->v.Global.names = names;
1170 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001171 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001172 return p;
1173}
1174
1175stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001176Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1177{
1178 stmt_ty p;
1179 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1180 if (!p)
1181 return NULL;
1182 p->kind = Nonlocal_kind;
1183 p->v.Nonlocal.names = names;
1184 p->lineno = lineno;
1185 p->col_offset = col_offset;
1186 return p;
1187}
1188
1189stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001190Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191{
1192 stmt_ty p;
1193 if (!value) {
1194 PyErr_SetString(PyExc_ValueError,
1195 "field value is required for Expr");
1196 return NULL;
1197 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001198 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001199 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201 p->kind = Expr_kind;
1202 p->v.Expr.value = value;
1203 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001204 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001205 return p;
1206}
1207
1208stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001209Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210{
1211 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001212 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001213 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001215 p->kind = Pass_kind;
1216 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001217 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return p;
1219}
1220
1221stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001222Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223{
1224 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001225 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001226 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001228 p->kind = Break_kind;
1229 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001230 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231 return p;
1232}
1233
1234stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001235Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236{
1237 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001238 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001239 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001240 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001241 p->kind = Continue_kind;
1242 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001243 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244 return p;
1245}
1246
1247expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001248BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1249 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250{
1251 expr_ty p;
1252 if (!op) {
1253 PyErr_SetString(PyExc_ValueError,
1254 "field op is required for BoolOp");
1255 return NULL;
1256 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001257 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001258 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001260 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));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001289 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001291 p->kind = BinOp_kind;
1292 p->v.BinOp.left = left;
1293 p->v.BinOp.op = op;
1294 p->v.BinOp.right = right;
1295 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001296 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001297 return p;
1298}
1299
1300expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001301UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1302 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001303{
1304 expr_ty p;
1305 if (!op) {
1306 PyErr_SetString(PyExc_ValueError,
1307 "field op is required for UnaryOp");
1308 return NULL;
1309 }
1310 if (!operand) {
1311 PyErr_SetString(PyExc_ValueError,
1312 "field operand is required for UnaryOp");
1313 return NULL;
1314 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001315 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001316 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001317 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318 p->kind = UnaryOp_kind;
1319 p->v.UnaryOp.op = op;
1320 p->v.UnaryOp.operand = operand;
1321 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001322 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001323 return p;
1324}
1325
1326expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001327Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1328 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001329{
1330 expr_ty p;
1331 if (!args) {
1332 PyErr_SetString(PyExc_ValueError,
1333 "field args is required for Lambda");
1334 return NULL;
1335 }
1336 if (!body) {
1337 PyErr_SetString(PyExc_ValueError,
1338 "field body is required for Lambda");
1339 return NULL;
1340 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001341 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001342 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001343 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001344 p->kind = Lambda_kind;
1345 p->v.Lambda.args = args;
1346 p->v.Lambda.body = body;
1347 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001348 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 return p;
1350}
1351
1352expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001353IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1354 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001355{
1356 expr_ty p;
1357 if (!test) {
1358 PyErr_SetString(PyExc_ValueError,
1359 "field test is required for IfExp");
1360 return NULL;
1361 }
1362 if (!body) {
1363 PyErr_SetString(PyExc_ValueError,
1364 "field body is required for IfExp");
1365 return NULL;
1366 }
1367 if (!orelse) {
1368 PyErr_SetString(PyExc_ValueError,
1369 "field orelse is required for IfExp");
1370 return NULL;
1371 }
1372 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001373 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001374 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001375 p->kind = IfExp_kind;
1376 p->v.IfExp.test = test;
1377 p->v.IfExp.body = body;
1378 p->v.IfExp.orelse = orelse;
1379 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001380 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001381 return p;
1382}
1383
1384expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001385Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1386 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001387{
1388 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001389 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001390 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001391 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001392 p->kind = Dict_kind;
1393 p->v.Dict.keys = keys;
1394 p->v.Dict.values = values;
1395 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001396 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001397 return p;
1398}
1399
1400expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001401Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1402{
1403 expr_ty p;
1404 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001405 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001406 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001407 p->kind = Set_kind;
1408 p->v.Set.elts = elts;
1409 p->lineno = lineno;
1410 p->col_offset = col_offset;
1411 return p;
1412}
1413
1414expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1416 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001417{
1418 expr_ty p;
1419 if (!elt) {
1420 PyErr_SetString(PyExc_ValueError,
1421 "field elt is required for ListComp");
1422 return NULL;
1423 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001424 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001425 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 p->kind = ListComp_kind;
1428 p->v.ListComp.elt = elt;
1429 p->v.ListComp.generators = generators;
1430 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001431 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001432 return p;
1433}
1434
1435expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001436SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1437 *arena)
1438{
1439 expr_ty p;
1440 if (!elt) {
1441 PyErr_SetString(PyExc_ValueError,
1442 "field elt is required for SetComp");
1443 return NULL;
1444 }
1445 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1446 if (!p)
1447 return NULL;
1448 p->kind = SetComp_kind;
1449 p->v.SetComp.elt = elt;
1450 p->v.SetComp.generators = generators;
1451 p->lineno = lineno;
1452 p->col_offset = col_offset;
1453 return p;
1454}
1455
1456expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001457GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1458 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001459{
1460 expr_ty p;
1461 if (!elt) {
1462 PyErr_SetString(PyExc_ValueError,
1463 "field elt is required for GeneratorExp");
1464 return NULL;
1465 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001466 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001467 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001468 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469 p->kind = GeneratorExp_kind;
1470 p->v.GeneratorExp.elt = elt;
1471 p->v.GeneratorExp.generators = generators;
1472 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001473 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001474 return p;
1475}
1476
1477expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001478Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479{
1480 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001481 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001482 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001483 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001484 p->kind = Yield_kind;
1485 p->v.Yield.value = value;
1486 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001487 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001488 return p;
1489}
1490
1491expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001492Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1493 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494{
1495 expr_ty p;
1496 if (!left) {
1497 PyErr_SetString(PyExc_ValueError,
1498 "field left is required for Compare");
1499 return NULL;
1500 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001501 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001502 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001503 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001504 p->kind = Compare_kind;
1505 p->v.Compare.left = left;
1506 p->v.Compare.ops = ops;
1507 p->v.Compare.comparators = comparators;
1508 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001509 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 return p;
1511}
1512
1513expr_ty
1514Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001515 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516{
1517 expr_ty p;
1518 if (!func) {
1519 PyErr_SetString(PyExc_ValueError,
1520 "field func is required for Call");
1521 return NULL;
1522 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001523 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001524 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001525 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 p->kind = Call_kind;
1527 p->v.Call.func = func;
1528 p->v.Call.args = args;
1529 p->v.Call.keywords = keywords;
1530 p->v.Call.starargs = starargs;
1531 p->v.Call.kwargs = kwargs;
1532 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001533 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001534 return p;
1535}
1536
1537expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001538Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001539{
1540 expr_ty p;
1541 if (!n) {
1542 PyErr_SetString(PyExc_ValueError,
1543 "field n is required for Num");
1544 return NULL;
1545 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001546 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001547 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549 p->kind = Num_kind;
1550 p->v.Num.n = n;
1551 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001552 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001553 return p;
1554}
1555
1556expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001557Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001558{
1559 expr_ty p;
1560 if (!s) {
1561 PyErr_SetString(PyExc_ValueError,
1562 "field s is required for Str");
1563 return NULL;
1564 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001565 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001566 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001568 p->kind = Str_kind;
1569 p->v.Str.s = s;
1570 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001571 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572 return p;
1573}
1574
1575expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001576Bytes(string s, int lineno, int col_offset, PyArena *arena)
1577{
1578 expr_ty p;
1579 if (!s) {
1580 PyErr_SetString(PyExc_ValueError,
1581 "field s is required for Bytes");
1582 return NULL;
1583 }
1584 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001585 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001586 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001587 p->kind = Bytes_kind;
1588 p->v.Bytes.s = s;
1589 p->lineno = lineno;
1590 p->col_offset = col_offset;
1591 return p;
1592}
1593
1594expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001595Ellipsis(int lineno, int col_offset, PyArena *arena)
1596{
1597 expr_ty p;
1598 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001599 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001600 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001601 p->kind = Ellipsis_kind;
1602 p->lineno = lineno;
1603 p->col_offset = col_offset;
1604 return p;
1605}
1606
1607expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001608Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1609 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001610{
1611 expr_ty p;
1612 if (!value) {
1613 PyErr_SetString(PyExc_ValueError,
1614 "field value is required for Attribute");
1615 return NULL;
1616 }
1617 if (!attr) {
1618 PyErr_SetString(PyExc_ValueError,
1619 "field attr is required for Attribute");
1620 return NULL;
1621 }
1622 if (!ctx) {
1623 PyErr_SetString(PyExc_ValueError,
1624 "field ctx is required for Attribute");
1625 return NULL;
1626 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001627 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001628 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001629 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001630 p->kind = Attribute_kind;
1631 p->v.Attribute.value = value;
1632 p->v.Attribute.attr = attr;
1633 p->v.Attribute.ctx = ctx;
1634 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001635 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001636 return p;
1637}
1638
1639expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001640Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1641 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001642{
1643 expr_ty p;
1644 if (!value) {
1645 PyErr_SetString(PyExc_ValueError,
1646 "field value is required for Subscript");
1647 return NULL;
1648 }
1649 if (!slice) {
1650 PyErr_SetString(PyExc_ValueError,
1651 "field slice is required for Subscript");
1652 return NULL;
1653 }
1654 if (!ctx) {
1655 PyErr_SetString(PyExc_ValueError,
1656 "field ctx is required for Subscript");
1657 return NULL;
1658 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001659 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001660 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001661 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001662 p->kind = Subscript_kind;
1663 p->v.Subscript.value = value;
1664 p->v.Subscript.slice = slice;
1665 p->v.Subscript.ctx = ctx;
1666 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001667 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668 return p;
1669}
1670
1671expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00001672Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
1673 *arena)
1674{
1675 expr_ty p;
1676 if (!value) {
1677 PyErr_SetString(PyExc_ValueError,
1678 "field value is required for Starred");
1679 return NULL;
1680 }
1681 if (!ctx) {
1682 PyErr_SetString(PyExc_ValueError,
1683 "field ctx is required for Starred");
1684 return NULL;
1685 }
1686 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1687 if (!p)
1688 return NULL;
1689 p->kind = Starred_kind;
1690 p->v.Starred.value = value;
1691 p->v.Starred.ctx = ctx;
1692 p->lineno = lineno;
1693 p->col_offset = col_offset;
1694 return p;
1695}
1696
1697expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001698Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1699 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001700{
1701 expr_ty p;
1702 if (!id) {
1703 PyErr_SetString(PyExc_ValueError,
1704 "field id is required for Name");
1705 return NULL;
1706 }
1707 if (!ctx) {
1708 PyErr_SetString(PyExc_ValueError,
1709 "field ctx is required for Name");
1710 return NULL;
1711 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001712 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001713 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001714 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 p->kind = Name_kind;
1716 p->v.Name.id = id;
1717 p->v.Name.ctx = ctx;
1718 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001719 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720 return p;
1721}
1722
1723expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001724List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1725 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726{
1727 expr_ty p;
1728 if (!ctx) {
1729 PyErr_SetString(PyExc_ValueError,
1730 "field ctx is required for List");
1731 return NULL;
1732 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001733 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001734 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001735 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001736 p->kind = List_kind;
1737 p->v.List.elts = elts;
1738 p->v.List.ctx = ctx;
1739 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001740 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001741 return p;
1742}
1743
1744expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001745Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1746 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001747{
1748 expr_ty p;
1749 if (!ctx) {
1750 PyErr_SetString(PyExc_ValueError,
1751 "field ctx is required for Tuple");
1752 return NULL;
1753 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001754 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001755 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757 p->kind = Tuple_kind;
1758 p->v.Tuple.elts = elts;
1759 p->v.Tuple.ctx = ctx;
1760 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001761 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762 return p;
1763}
1764
1765slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001766Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767{
1768 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001769 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001770 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772 p->kind = Slice_kind;
1773 p->v.Slice.lower = lower;
1774 p->v.Slice.upper = upper;
1775 p->v.Slice.step = step;
1776 return p;
1777}
1778
1779slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001780ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001781{
1782 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001783 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001784 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001785 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001786 p->kind = ExtSlice_kind;
1787 p->v.ExtSlice.dims = dims;
1788 return p;
1789}
1790
1791slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001792Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001793{
1794 slice_ty p;
1795 if (!value) {
1796 PyErr_SetString(PyExc_ValueError,
1797 "field value is required for Index");
1798 return NULL;
1799 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001800 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001801 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001802 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803 p->kind = Index_kind;
1804 p->v.Index.value = value;
1805 return p;
1806}
1807
1808comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001809comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001810{
1811 comprehension_ty p;
1812 if (!target) {
1813 PyErr_SetString(PyExc_ValueError,
1814 "field target is required for comprehension");
1815 return NULL;
1816 }
1817 if (!iter) {
1818 PyErr_SetString(PyExc_ValueError,
1819 "field iter is required for comprehension");
1820 return NULL;
1821 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001822 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001823 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001824 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001825 p->target = target;
1826 p->iter = iter;
1827 p->ifs = ifs;
1828 return p;
1829}
1830
1831excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001832excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001833 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001834{
1835 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001836 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001837 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001838 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001839 p->type = type;
1840 p->name = name;
1841 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001842 p->lineno = lineno;
1843 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001844 return p;
1845}
1846
1847arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001848arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1849 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1850 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001851{
1852 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001853 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001854 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001856 p->args = args;
1857 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001858 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001859 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001860 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001861 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001863 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864 return p;
1865}
1866
Neal Norwitzc1505362006-12-28 06:47:50 +00001867arg_ty
1868SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1869{
1870 arg_ty p;
1871 if (!arg) {
1872 PyErr_SetString(PyExc_ValueError,
1873 "field arg is required for SimpleArg");
1874 return NULL;
1875 }
1876 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001877 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001878 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001879 p->kind = SimpleArg_kind;
1880 p->v.SimpleArg.arg = arg;
1881 p->v.SimpleArg.annotation = annotation;
1882 return p;
1883}
1884
1885arg_ty
1886NestedArgs(asdl_seq * args, PyArena *arena)
1887{
1888 arg_ty p;
1889 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001890 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001891 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001892 p->kind = NestedArgs_kind;
1893 p->v.NestedArgs.args = args;
1894 return p;
1895}
1896
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001898keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899{
1900 keyword_ty p;
1901 if (!arg) {
1902 PyErr_SetString(PyExc_ValueError,
1903 "field arg is required for keyword");
1904 return NULL;
1905 }
1906 if (!value) {
1907 PyErr_SetString(PyExc_ValueError,
1908 "field value is required for keyword");
1909 return NULL;
1910 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001911 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001912 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001914 p->arg = arg;
1915 p->value = value;
1916 return p;
1917}
1918
1919alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001920alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001921{
1922 alias_ty p;
1923 if (!name) {
1924 PyErr_SetString(PyExc_ValueError,
1925 "field name is required for alias");
1926 return NULL;
1927 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001928 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001929 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001930 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931 p->name = name;
1932 p->asname = asname;
1933 return p;
1934}
1935
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001936
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001937PyObject*
1938ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001939{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001940 mod_ty o = (mod_ty)_o;
1941 PyObject *result = NULL, *value = NULL;
1942 if (!o) {
1943 Py_INCREF(Py_None);
1944 return Py_None;
1945 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001946
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947 switch (o->kind) {
1948 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001949 result = PyType_GenericNew(Module_type, NULL, NULL);
1950 if (!result) goto failed;
1951 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "body", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001956 break;
1957 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001958 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1959 if (!result) goto failed;
1960 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "body", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001965 break;
1966 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001967 result = PyType_GenericNew(Expression_type, NULL, NULL);
1968 if (!result) goto failed;
1969 value = ast2obj_expr(o->v.Expression.body);
1970 if (!value) goto failed;
1971 if (PyObject_SetAttrString(result, "body", value) == -1)
1972 goto failed;
1973 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001974 break;
1975 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001976 result = PyType_GenericNew(Suite_type, NULL, NULL);
1977 if (!result) goto failed;
1978 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1979 if (!value) goto failed;
1980 if (PyObject_SetAttrString(result, "body", value) == -1)
1981 goto failed;
1982 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001983 break;
1984 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001985 return result;
1986failed:
1987 Py_XDECREF(value);
1988 Py_XDECREF(result);
1989 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001990}
1991
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001992PyObject*
1993ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001994{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001995 stmt_ty o = (stmt_ty)_o;
1996 PyObject *result = NULL, *value = NULL;
1997 if (!o) {
1998 Py_INCREF(Py_None);
1999 return Py_None;
2000 }
2001
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002002 switch (o->kind) {
2003 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002004 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2005 if (!result) goto failed;
2006 value = ast2obj_identifier(o->v.FunctionDef.name);
2007 if (!value) goto failed;
2008 if (PyObject_SetAttrString(result, "name", value) == -1)
2009 goto failed;
2010 Py_DECREF(value);
2011 value = ast2obj_arguments(o->v.FunctionDef.args);
2012 if (!value) goto failed;
2013 if (PyObject_SetAttrString(result, "args", value) == -1)
2014 goto failed;
2015 Py_DECREF(value);
2016 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2017 if (!value) goto failed;
2018 if (PyObject_SetAttrString(result, "body", value) == -1)
2019 goto failed;
2020 Py_DECREF(value);
2021 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002026 value = ast2obj_expr(o->v.FunctionDef.returns);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "returns", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002031 break;
2032 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002033 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2034 if (!result) goto failed;
2035 value = ast2obj_identifier(o->v.ClassDef.name);
2036 if (!value) goto failed;
2037 if (PyObject_SetAttrString(result, "name", value) == -1)
2038 goto failed;
2039 Py_DECREF(value);
2040 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "bases", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002045 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
2050 value = ast2obj_expr(o->v.ClassDef.starargs);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
2055 value = ast2obj_expr(o->v.ClassDef.kwargs);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002060 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2061 if (!value) goto failed;
2062 if (PyObject_SetAttrString(result, "body", value) == -1)
2063 goto failed;
2064 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002065 break;
2066 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002067 result = PyType_GenericNew(Return_type, NULL, NULL);
2068 if (!result) goto failed;
2069 value = ast2obj_expr(o->v.Return.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 Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002076 result = PyType_GenericNew(Delete_type, NULL, NULL);
2077 if (!result) goto failed;
2078 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "targets", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002083 break;
2084 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002085 result = PyType_GenericNew(Assign_type, NULL, NULL);
2086 if (!result) goto failed;
2087 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "targets", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_expr(o->v.Assign.value);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "value", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002097 break;
2098 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002099 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2100 if (!result) goto failed;
2101 value = ast2obj_expr(o->v.AugAssign.target);
2102 if (!value) goto failed;
2103 if (PyObject_SetAttrString(result, "target", value) == -1)
2104 goto failed;
2105 Py_DECREF(value);
2106 value = ast2obj_operator(o->v.AugAssign.op);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "op", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_expr(o->v.AugAssign.value);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "value", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002116 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002117 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002118 result = PyType_GenericNew(For_type, NULL, NULL);
2119 if (!result) goto failed;
2120 value = ast2obj_expr(o->v.For.target);
2121 if (!value) goto failed;
2122 if (PyObject_SetAttrString(result, "target", value) == -1)
2123 goto failed;
2124 Py_DECREF(value);
2125 value = ast2obj_expr(o->v.For.iter);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "iter", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "body", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002140 break;
2141 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002142 result = PyType_GenericNew(While_type, NULL, NULL);
2143 if (!result) goto failed;
2144 value = ast2obj_expr(o->v.While.test);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "test", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "body", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002159 break;
2160 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002161 result = PyType_GenericNew(If_type, NULL, NULL);
2162 if (!result) goto failed;
2163 value = ast2obj_expr(o->v.If.test);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "test", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "body", value) == -1)
2171 goto failed;
2172 Py_DECREF(value);
2173 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2174 if (!value) goto failed;
2175 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2176 goto failed;
2177 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002178 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002179 case With_kind:
2180 result = PyType_GenericNew(With_type, NULL, NULL);
2181 if (!result) goto failed;
2182 value = ast2obj_expr(o->v.With.context_expr);
2183 if (!value) goto failed;
2184 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2185 goto failed;
2186 Py_DECREF(value);
2187 value = ast2obj_expr(o->v.With.optional_vars);
2188 if (!value) goto failed;
2189 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2190 -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2194 if (!value) goto failed;
2195 if (PyObject_SetAttrString(result, "body", value) == -1)
2196 goto failed;
2197 Py_DECREF(value);
2198 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002200 result = PyType_GenericNew(Raise_type, NULL, NULL);
2201 if (!result) goto failed;
2202 value = ast2obj_expr(o->v.Raise.type);
2203 if (!value) goto failed;
2204 if (PyObject_SetAttrString(result, "type", value) == -1)
2205 goto failed;
2206 Py_DECREF(value);
2207 value = ast2obj_expr(o->v.Raise.inst);
2208 if (!value) goto failed;
2209 if (PyObject_SetAttrString(result, "inst", value) == -1)
2210 goto failed;
2211 Py_DECREF(value);
2212 value = ast2obj_expr(o->v.Raise.tback);
2213 if (!value) goto failed;
2214 if (PyObject_SetAttrString(result, "tback", value) == -1)
2215 goto failed;
2216 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002217 break;
2218 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002219 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2220 if (!result) goto failed;
2221 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2222 if (!value) goto failed;
2223 if (PyObject_SetAttrString(result, "body", value) == -1)
2224 goto failed;
2225 Py_DECREF(value);
2226 value = ast2obj_list(o->v.TryExcept.handlers,
2227 ast2obj_excepthandler);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
2232 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2233 if (!value) goto failed;
2234 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2235 goto failed;
2236 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002237 break;
2238 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002239 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2240 if (!result) goto failed;
2241 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "body", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
2246 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2249 goto failed;
2250 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 break;
2252 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002253 result = PyType_GenericNew(Assert_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_expr(o->v.Assert.test);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "test", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
2260 value = ast2obj_expr(o->v.Assert.msg);
2261 if (!value) goto failed;
2262 if (PyObject_SetAttrString(result, "msg", value) == -1)
2263 goto failed;
2264 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002265 break;
2266 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002267 result = PyType_GenericNew(Import_type, NULL, NULL);
2268 if (!result) goto failed;
2269 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "names", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002274 break;
2275 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002276 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2277 if (!result) goto failed;
2278 value = ast2obj_identifier(o->v.ImportFrom.module);
2279 if (!value) goto failed;
2280 if (PyObject_SetAttrString(result, "module", value) == -1)
2281 goto failed;
2282 Py_DECREF(value);
2283 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "names", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002288 value = ast2obj_int(o->v.ImportFrom.level);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "level", value) == -1)
2291 goto failed;
2292 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002293 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002294 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002295 result = PyType_GenericNew(Global_type, NULL, NULL);
2296 if (!result) goto failed;
2297 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "names", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002302 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002303 case Nonlocal_kind:
2304 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2305 if (!result) goto failed;
2306 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "names", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
2311 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002312 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002313 result = PyType_GenericNew(Expr_type, NULL, NULL);
2314 if (!result) goto failed;
2315 value = ast2obj_expr(o->v.Expr.value);
2316 if (!value) goto failed;
2317 if (PyObject_SetAttrString(result, "value", value) == -1)
2318 goto failed;
2319 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002320 break;
2321 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002322 result = PyType_GenericNew(Pass_type, NULL, NULL);
2323 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324 break;
2325 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002326 result = PyType_GenericNew(Break_type, NULL, NULL);
2327 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002328 break;
2329 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002330 result = PyType_GenericNew(Continue_type, NULL, NULL);
2331 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002332 break;
2333 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002334 value = ast2obj_int(o->lineno);
2335 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002336 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2337 goto failed;
2338 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002339 value = ast2obj_int(o->col_offset);
2340 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002341 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2342 goto failed;
2343 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 return result;
2345failed:
2346 Py_XDECREF(value);
2347 Py_XDECREF(result);
2348 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002349}
2350
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002351PyObject*
2352ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002353{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 expr_ty o = (expr_ty)_o;
2355 PyObject *result = NULL, *value = NULL;
2356 if (!o) {
2357 Py_INCREF(Py_None);
2358 return Py_None;
2359 }
2360
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002361 switch (o->kind) {
2362 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002363 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2364 if (!result) goto failed;
2365 value = ast2obj_boolop(o->v.BoolOp.op);
2366 if (!value) goto failed;
2367 if (PyObject_SetAttrString(result, "op", value) == -1)
2368 goto failed;
2369 Py_DECREF(value);
2370 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "values", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375 break;
2376 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002377 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2378 if (!result) goto failed;
2379 value = ast2obj_expr(o->v.BinOp.left);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "left", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 value = ast2obj_operator(o->v.BinOp.op);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "op", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
2389 value = ast2obj_expr(o->v.BinOp.right);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "right", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002394 break;
2395 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002396 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2397 if (!result) goto failed;
2398 value = ast2obj_unaryop(o->v.UnaryOp.op);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "op", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 value = ast2obj_expr(o->v.UnaryOp.operand);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "operand", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002408 break;
2409 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_arguments(o->v.Lambda.args);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "args", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 value = ast2obj_expr(o->v.Lambda.body);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "body", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002422 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002423 case IfExp_kind:
2424 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2425 if (!result) goto failed;
2426 value = ast2obj_expr(o->v.IfExp.test);
2427 if (!value) goto failed;
2428 if (PyObject_SetAttrString(result, "test", value) == -1)
2429 goto failed;
2430 Py_DECREF(value);
2431 value = ast2obj_expr(o->v.IfExp.body);
2432 if (!value) goto failed;
2433 if (PyObject_SetAttrString(result, "body", value) == -1)
2434 goto failed;
2435 Py_DECREF(value);
2436 value = ast2obj_expr(o->v.IfExp.orelse);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
2441 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002443 result = PyType_GenericNew(Dict_type, NULL, NULL);
2444 if (!result) goto failed;
2445 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2446 if (!value) goto failed;
2447 if (PyObject_SetAttrString(result, "keys", value) == -1)
2448 goto failed;
2449 Py_DECREF(value);
2450 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "values", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002456 case Set_kind:
2457 result = PyType_GenericNew(Set_type, NULL, NULL);
2458 if (!result) goto failed;
2459 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2460 if (!value) goto failed;
2461 if (PyObject_SetAttrString(result, "elts", value) == -1)
2462 goto failed;
2463 Py_DECREF(value);
2464 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002465 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002466 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2467 if (!result) goto failed;
2468 value = ast2obj_expr(o->v.ListComp.elt);
2469 if (!value) goto failed;
2470 if (PyObject_SetAttrString(result, "elt", value) == -1)
2471 goto failed;
2472 Py_DECREF(value);
2473 value = ast2obj_list(o->v.ListComp.generators,
2474 ast2obj_comprehension);
2475 if (!value) goto failed;
2476 if (PyObject_SetAttrString(result, "generators", value) == -1)
2477 goto failed;
2478 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002480 case SetComp_kind:
2481 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2482 if (!result) goto failed;
2483 value = ast2obj_expr(o->v.SetComp.elt);
2484 if (!value) goto failed;
2485 if (PyObject_SetAttrString(result, "elt", value) == -1)
2486 goto failed;
2487 Py_DECREF(value);
2488 value = ast2obj_list(o->v.SetComp.generators,
2489 ast2obj_comprehension);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "generators", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2494 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002495 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002496 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2497 if (!result) goto failed;
2498 value = ast2obj_expr(o->v.GeneratorExp.elt);
2499 if (!value) goto failed;
2500 if (PyObject_SetAttrString(result, "elt", value) == -1)
2501 goto failed;
2502 Py_DECREF(value);
2503 value = ast2obj_list(o->v.GeneratorExp.generators,
2504 ast2obj_comprehension);
2505 if (!value) goto failed;
2506 if (PyObject_SetAttrString(result, "generators", value) == -1)
2507 goto failed;
2508 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002509 break;
2510 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002511 result = PyType_GenericNew(Yield_type, NULL, NULL);
2512 if (!result) goto failed;
2513 value = ast2obj_expr(o->v.Yield.value);
2514 if (!value) goto failed;
2515 if (PyObject_SetAttrString(result, "value", value) == -1)
2516 goto failed;
2517 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002518 break;
2519 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002520 result = PyType_GenericNew(Compare_type, NULL, NULL);
2521 if (!result) goto failed;
2522 value = ast2obj_expr(o->v.Compare.left);
2523 if (!value) goto failed;
2524 if (PyObject_SetAttrString(result, "left", value) == -1)
2525 goto failed;
2526 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002527 {
2528 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2529 value = PyList_New(n);
2530 if (!value) goto failed;
2531 for(i = 0; i < n; i++)
2532 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2533 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002534 if (!value) goto failed;
2535 if (PyObject_SetAttrString(result, "ops", value) == -1)
2536 goto failed;
2537 Py_DECREF(value);
2538 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002543 break;
2544 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002545 result = PyType_GenericNew(Call_type, NULL, NULL);
2546 if (!result) goto failed;
2547 value = ast2obj_expr(o->v.Call.func);
2548 if (!value) goto failed;
2549 if (PyObject_SetAttrString(result, "func", value) == -1)
2550 goto failed;
2551 Py_DECREF(value);
2552 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "args", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
2557 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2558 if (!value) goto failed;
2559 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2560 goto failed;
2561 Py_DECREF(value);
2562 value = ast2obj_expr(o->v.Call.starargs);
2563 if (!value) goto failed;
2564 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2565 goto failed;
2566 Py_DECREF(value);
2567 value = ast2obj_expr(o->v.Call.kwargs);
2568 if (!value) goto failed;
2569 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2570 goto failed;
2571 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002572 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002573 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002574 result = PyType_GenericNew(Num_type, NULL, NULL);
2575 if (!result) goto failed;
2576 value = ast2obj_object(o->v.Num.n);
2577 if (!value) goto failed;
2578 if (PyObject_SetAttrString(result, "n", value) == -1)
2579 goto failed;
2580 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002581 break;
2582 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002583 result = PyType_GenericNew(Str_type, NULL, NULL);
2584 if (!result) goto failed;
2585 value = ast2obj_string(o->v.Str.s);
2586 if (!value) goto failed;
2587 if (PyObject_SetAttrString(result, "s", value) == -1)
2588 goto failed;
2589 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002590 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002591 case Bytes_kind:
2592 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2593 if (!result) goto failed;
2594 value = ast2obj_string(o->v.Bytes.s);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "s", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002600 case Ellipsis_kind:
2601 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2602 if (!result) goto failed;
2603 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002604 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002605 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2606 if (!result) goto failed;
2607 value = ast2obj_expr(o->v.Attribute.value);
2608 if (!value) goto failed;
2609 if (PyObject_SetAttrString(result, "value", value) == -1)
2610 goto failed;
2611 Py_DECREF(value);
2612 value = ast2obj_identifier(o->v.Attribute.attr);
2613 if (!value) goto failed;
2614 if (PyObject_SetAttrString(result, "attr", value) == -1)
2615 goto failed;
2616 Py_DECREF(value);
2617 value = ast2obj_expr_context(o->v.Attribute.ctx);
2618 if (!value) goto failed;
2619 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2620 goto failed;
2621 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002622 break;
2623 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002624 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2625 if (!result) goto failed;
2626 value = ast2obj_expr(o->v.Subscript.value);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "value", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
2631 value = ast2obj_slice(o->v.Subscript.slice);
2632 if (!value) goto failed;
2633 if (PyObject_SetAttrString(result, "slice", value) == -1)
2634 goto failed;
2635 Py_DECREF(value);
2636 value = ast2obj_expr_context(o->v.Subscript.ctx);
2637 if (!value) goto failed;
2638 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2639 goto failed;
2640 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002641 break;
Guido van Rossum0368b722007-05-11 16:50:42 +00002642 case Starred_kind:
2643 result = PyType_GenericNew(Starred_type, NULL, NULL);
2644 if (!result) goto failed;
2645 value = ast2obj_expr(o->v.Starred.value);
2646 if (!value) goto failed;
2647 if (PyObject_SetAttrString(result, "value", value) == -1)
2648 goto failed;
2649 Py_DECREF(value);
2650 value = ast2obj_expr_context(o->v.Starred.ctx);
2651 if (!value) goto failed;
2652 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2653 goto failed;
2654 Py_DECREF(value);
2655 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002657 result = PyType_GenericNew(Name_type, NULL, NULL);
2658 if (!result) goto failed;
2659 value = ast2obj_identifier(o->v.Name.id);
2660 if (!value) goto failed;
2661 if (PyObject_SetAttrString(result, "id", value) == -1)
2662 goto failed;
2663 Py_DECREF(value);
2664 value = ast2obj_expr_context(o->v.Name.ctx);
2665 if (!value) goto failed;
2666 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2667 goto failed;
2668 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002669 break;
2670 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002671 result = PyType_GenericNew(List_type, NULL, NULL);
2672 if (!result) goto failed;
2673 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2674 if (!value) goto failed;
2675 if (PyObject_SetAttrString(result, "elts", value) == -1)
2676 goto failed;
2677 Py_DECREF(value);
2678 value = ast2obj_expr_context(o->v.List.ctx);
2679 if (!value) goto failed;
2680 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2681 goto failed;
2682 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002683 break;
2684 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002685 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2686 if (!result) goto failed;
2687 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2688 if (!value) goto failed;
2689 if (PyObject_SetAttrString(result, "elts", value) == -1)
2690 goto failed;
2691 Py_DECREF(value);
2692 value = ast2obj_expr_context(o->v.Tuple.ctx);
2693 if (!value) goto failed;
2694 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2695 goto failed;
2696 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002697 break;
2698 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002699 value = ast2obj_int(o->lineno);
2700 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002701 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2702 goto failed;
2703 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002704 value = ast2obj_int(o->col_offset);
2705 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002706 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2707 goto failed;
2708 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002709 return result;
2710failed:
2711 Py_XDECREF(value);
2712 Py_XDECREF(result);
2713 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002714}
2715
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002716PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002718 switch(o) {
2719 case Load:
2720 Py_INCREF(Load_singleton);
2721 return Load_singleton;
2722 case Store:
2723 Py_INCREF(Store_singleton);
2724 return Store_singleton;
2725 case Del:
2726 Py_INCREF(Del_singleton);
2727 return Del_singleton;
2728 case AugLoad:
2729 Py_INCREF(AugLoad_singleton);
2730 return AugLoad_singleton;
2731 case AugStore:
2732 Py_INCREF(AugStore_singleton);
2733 return AugStore_singleton;
2734 case Param:
2735 Py_INCREF(Param_singleton);
2736 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002737 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002738 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002739}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002740PyObject*
2741ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002742{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002743 slice_ty o = (slice_ty)_o;
2744 PyObject *result = NULL, *value = NULL;
2745 if (!o) {
2746 Py_INCREF(Py_None);
2747 return Py_None;
2748 }
2749
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002750 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002751 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002752 result = PyType_GenericNew(Slice_type, NULL, NULL);
2753 if (!result) goto failed;
2754 value = ast2obj_expr(o->v.Slice.lower);
2755 if (!value) goto failed;
2756 if (PyObject_SetAttrString(result, "lower", value) == -1)
2757 goto failed;
2758 Py_DECREF(value);
2759 value = ast2obj_expr(o->v.Slice.upper);
2760 if (!value) goto failed;
2761 if (PyObject_SetAttrString(result, "upper", value) == -1)
2762 goto failed;
2763 Py_DECREF(value);
2764 value = ast2obj_expr(o->v.Slice.step);
2765 if (!value) goto failed;
2766 if (PyObject_SetAttrString(result, "step", value) == -1)
2767 goto failed;
2768 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002769 break;
2770 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002771 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2772 if (!result) goto failed;
2773 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2774 if (!value) goto failed;
2775 if (PyObject_SetAttrString(result, "dims", value) == -1)
2776 goto failed;
2777 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002778 break;
2779 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002780 result = PyType_GenericNew(Index_type, NULL, NULL);
2781 if (!result) goto failed;
2782 value = ast2obj_expr(o->v.Index.value);
2783 if (!value) goto failed;
2784 if (PyObject_SetAttrString(result, "value", value) == -1)
2785 goto failed;
2786 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002787 break;
2788 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002789 return result;
2790failed:
2791 Py_XDECREF(value);
2792 Py_XDECREF(result);
2793 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002794}
2795
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002796PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002797{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002798 switch(o) {
2799 case And:
2800 Py_INCREF(And_singleton);
2801 return And_singleton;
2802 case Or:
2803 Py_INCREF(Or_singleton);
2804 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002805 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002806 return NULL; /* cannot happen */
2807}
2808PyObject* ast2obj_operator(operator_ty o)
2809{
2810 switch(o) {
2811 case Add:
2812 Py_INCREF(Add_singleton);
2813 return Add_singleton;
2814 case Sub:
2815 Py_INCREF(Sub_singleton);
2816 return Sub_singleton;
2817 case Mult:
2818 Py_INCREF(Mult_singleton);
2819 return Mult_singleton;
2820 case Div:
2821 Py_INCREF(Div_singleton);
2822 return Div_singleton;
2823 case Mod:
2824 Py_INCREF(Mod_singleton);
2825 return Mod_singleton;
2826 case Pow:
2827 Py_INCREF(Pow_singleton);
2828 return Pow_singleton;
2829 case LShift:
2830 Py_INCREF(LShift_singleton);
2831 return LShift_singleton;
2832 case RShift:
2833 Py_INCREF(RShift_singleton);
2834 return RShift_singleton;
2835 case BitOr:
2836 Py_INCREF(BitOr_singleton);
2837 return BitOr_singleton;
2838 case BitXor:
2839 Py_INCREF(BitXor_singleton);
2840 return BitXor_singleton;
2841 case BitAnd:
2842 Py_INCREF(BitAnd_singleton);
2843 return BitAnd_singleton;
2844 case FloorDiv:
2845 Py_INCREF(FloorDiv_singleton);
2846 return FloorDiv_singleton;
2847 }
2848 return NULL; /* cannot happen */
2849}
2850PyObject* ast2obj_unaryop(unaryop_ty o)
2851{
2852 switch(o) {
2853 case Invert:
2854 Py_INCREF(Invert_singleton);
2855 return Invert_singleton;
2856 case Not:
2857 Py_INCREF(Not_singleton);
2858 return Not_singleton;
2859 case UAdd:
2860 Py_INCREF(UAdd_singleton);
2861 return UAdd_singleton;
2862 case USub:
2863 Py_INCREF(USub_singleton);
2864 return USub_singleton;
2865 }
2866 return NULL; /* cannot happen */
2867}
2868PyObject* ast2obj_cmpop(cmpop_ty o)
2869{
2870 switch(o) {
2871 case Eq:
2872 Py_INCREF(Eq_singleton);
2873 return Eq_singleton;
2874 case NotEq:
2875 Py_INCREF(NotEq_singleton);
2876 return NotEq_singleton;
2877 case Lt:
2878 Py_INCREF(Lt_singleton);
2879 return Lt_singleton;
2880 case LtE:
2881 Py_INCREF(LtE_singleton);
2882 return LtE_singleton;
2883 case Gt:
2884 Py_INCREF(Gt_singleton);
2885 return Gt_singleton;
2886 case GtE:
2887 Py_INCREF(GtE_singleton);
2888 return GtE_singleton;
2889 case Is:
2890 Py_INCREF(Is_singleton);
2891 return Is_singleton;
2892 case IsNot:
2893 Py_INCREF(IsNot_singleton);
2894 return IsNot_singleton;
2895 case In:
2896 Py_INCREF(In_singleton);
2897 return In_singleton;
2898 case NotIn:
2899 Py_INCREF(NotIn_singleton);
2900 return NotIn_singleton;
2901 }
2902 return NULL; /* cannot happen */
2903}
2904PyObject*
2905ast2obj_comprehension(void* _o)
2906{
2907 comprehension_ty o = (comprehension_ty)_o;
2908 PyObject *result = NULL, *value = NULL;
2909 if (!o) {
2910 Py_INCREF(Py_None);
2911 return Py_None;
2912 }
2913
2914 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2915 if (!result) return NULL;
2916 value = ast2obj_expr(o->target);
2917 if (!value) goto failed;
2918 if (PyObject_SetAttrString(result, "target", value) == -1)
2919 goto failed;
2920 Py_DECREF(value);
2921 value = ast2obj_expr(o->iter);
2922 if (!value) goto failed;
2923 if (PyObject_SetAttrString(result, "iter", value) == -1)
2924 goto failed;
2925 Py_DECREF(value);
2926 value = ast2obj_list(o->ifs, ast2obj_expr);
2927 if (!value) goto failed;
2928 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2929 goto failed;
2930 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002931 return result;
2932failed:
2933 Py_XDECREF(value);
2934 Py_XDECREF(result);
2935 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002936}
2937
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002938PyObject*
2939ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002940{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002941 excepthandler_ty o = (excepthandler_ty)_o;
2942 PyObject *result = NULL, *value = NULL;
2943 if (!o) {
2944 Py_INCREF(Py_None);
2945 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002946 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002947
2948 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2949 if (!result) return NULL;
2950 value = ast2obj_expr(o->type);
2951 if (!value) goto failed;
2952 if (PyObject_SetAttrString(result, "type", value) == -1)
2953 goto failed;
2954 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002955 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002956 if (!value) goto failed;
2957 if (PyObject_SetAttrString(result, "name", value) == -1)
2958 goto failed;
2959 Py_DECREF(value);
2960 value = ast2obj_list(o->body, ast2obj_stmt);
2961 if (!value) goto failed;
2962 if (PyObject_SetAttrString(result, "body", value) == -1)
2963 goto failed;
2964 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002965 value = ast2obj_int(o->lineno);
2966 if (!value) goto failed;
2967 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2968 goto failed;
2969 Py_DECREF(value);
2970 value = ast2obj_int(o->col_offset);
2971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2973 goto failed;
2974 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002975 return result;
2976failed:
2977 Py_XDECREF(value);
2978 Py_XDECREF(result);
2979 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002980}
2981
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002982PyObject*
2983ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002984{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002985 arguments_ty o = (arguments_ty)_o;
2986 PyObject *result = NULL, *value = NULL;
2987 if (!o) {
2988 Py_INCREF(Py_None);
2989 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002990 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002991
2992 result = PyType_GenericNew(arguments_type, NULL, NULL);
2993 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002994 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002995 if (!value) goto failed;
2996 if (PyObject_SetAttrString(result, "args", value) == -1)
2997 goto failed;
2998 Py_DECREF(value);
2999 value = ast2obj_identifier(o->vararg);
3000 if (!value) goto failed;
3001 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003004 value = ast2obj_expr(o->varargannotation);
3005 if (!value) goto failed;
3006 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
3007 goto failed;
3008 Py_DECREF(value);
3009 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003010 if (!value) goto failed;
3011 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
3012 goto failed;
3013 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003014 value = ast2obj_identifier(o->kwarg);
3015 if (!value) goto failed;
3016 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3017 goto failed;
3018 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003019 value = ast2obj_expr(o->kwargannotation);
3020 if (!value) goto failed;
3021 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
3022 goto failed;
3023 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003024 value = ast2obj_list(o->defaults, ast2obj_expr);
3025 if (!value) goto failed;
3026 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3027 goto failed;
3028 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003029 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3030 if (!value) goto failed;
3031 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3032 goto failed;
3033 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003034 return result;
3035failed:
3036 Py_XDECREF(value);
3037 Py_XDECREF(result);
3038 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003039}
3040
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003041PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003042ast2obj_arg(void* _o)
3043{
3044 arg_ty o = (arg_ty)_o;
3045 PyObject *result = NULL, *value = NULL;
3046 if (!o) {
3047 Py_INCREF(Py_None);
3048 return Py_None;
3049 }
3050
3051 switch (o->kind) {
3052 case SimpleArg_kind:
3053 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
3054 if (!result) goto failed;
3055 value = ast2obj_identifier(o->v.SimpleArg.arg);
3056 if (!value) goto failed;
3057 if (PyObject_SetAttrString(result, "arg", value) == -1)
3058 goto failed;
3059 Py_DECREF(value);
3060 value = ast2obj_expr(o->v.SimpleArg.annotation);
3061 if (!value) goto failed;
3062 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3063 goto failed;
3064 Py_DECREF(value);
3065 break;
3066 case NestedArgs_kind:
3067 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
3068 if (!result) goto failed;
3069 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3070 if (!value) goto failed;
3071 if (PyObject_SetAttrString(result, "args", value) == -1)
3072 goto failed;
3073 Py_DECREF(value);
3074 break;
3075 }
3076 return result;
3077failed:
3078 Py_XDECREF(value);
3079 Py_XDECREF(result);
3080 return NULL;
3081}
3082
3083PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003084ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003085{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003086 keyword_ty o = (keyword_ty)_o;
3087 PyObject *result = NULL, *value = NULL;
3088 if (!o) {
3089 Py_INCREF(Py_None);
3090 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003091 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003092
3093 result = PyType_GenericNew(keyword_type, NULL, NULL);
3094 if (!result) return NULL;
3095 value = ast2obj_identifier(o->arg);
3096 if (!value) goto failed;
3097 if (PyObject_SetAttrString(result, "arg", value) == -1)
3098 goto failed;
3099 Py_DECREF(value);
3100 value = ast2obj_expr(o->value);
3101 if (!value) goto failed;
3102 if (PyObject_SetAttrString(result, "value", value) == -1)
3103 goto failed;
3104 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003105 return result;
3106failed:
3107 Py_XDECREF(value);
3108 Py_XDECREF(result);
3109 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003110}
3111
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003112PyObject*
3113ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003114{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003115 alias_ty o = (alias_ty)_o;
3116 PyObject *result = NULL, *value = NULL;
3117 if (!o) {
3118 Py_INCREF(Py_None);
3119 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003120 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003121
3122 result = PyType_GenericNew(alias_type, NULL, NULL);
3123 if (!result) return NULL;
3124 value = ast2obj_identifier(o->name);
3125 if (!value) goto failed;
3126 if (PyObject_SetAttrString(result, "name", value) == -1)
3127 goto failed;
3128 Py_DECREF(value);
3129 value = ast2obj_identifier(o->asname);
3130 if (!value) goto failed;
3131 if (PyObject_SetAttrString(result, "asname", value) == -1)
3132 goto failed;
3133 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003134 return result;
3135failed:
3136 Py_XDECREF(value);
3137 Py_XDECREF(result);
3138 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003139}
3140
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003141
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003142PyMODINIT_FUNC
3143init_ast(void)
3144{
3145 PyObject *m, *d;
3146 if (!init_types()) return;
3147 m = Py_InitModule3("_ast", NULL, NULL);
3148 if (!m) return;
3149 d = PyModule_GetDict(m);
3150 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3151 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3152 return;
Guido van Rossum8981ad02007-04-16 17:02:00 +00003153 if (PyModule_AddStringConstant(m, "__version__", "54835") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003154 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003155 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3156 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3157 return;
3158 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3159 < 0) return;
3160 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3161 0) return;
3162 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3163 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3164 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3165 < 0) return;
3166 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3167 return;
3168 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3169 return;
3170 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3171 return;
3172 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3173 return;
3174 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3175 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003176 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3177 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3178 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3179 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3180 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3181 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3182 0) return;
3183 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3184 0) return;
3185 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3186 return;
3187 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3188 return;
3189 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3190 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003191 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3192 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003193 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3194 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003195 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3196 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3197 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3198 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3199 return;
3200 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3201 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3202 return;
3203 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3204 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3205 return;
3206 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3207 return;
3208 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3209 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003210 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003211 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3212 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003213 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3214 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003215 if (PyDict_SetItemString(d, "GeneratorExp",
3216 (PyObject*)GeneratorExp_type) < 0) return;
3217 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3218 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3219 return;
3220 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003221 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3222 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003223 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003224 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3225 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003226 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3227 0) return;
3228 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3229 0) return;
Guido van Rossum0368b722007-05-11 16:50:42 +00003230 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
3231 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003232 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3233 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3234 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3235 if (PyDict_SetItemString(d, "expr_context",
3236 (PyObject*)expr_context_type) < 0) return;
3237 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3238 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3239 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3240 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3241 return;
3242 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3243 return;
3244 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3245 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003246 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3247 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3248 return;
3249 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3250 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3251 return;
3252 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3253 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3254 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3255 return;
3256 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3257 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3258 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3259 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3260 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3261 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3262 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3263 return;
3264 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3265 return;
3266 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3267 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3268 return;
3269 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3270 return;
3271 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3272 return;
3273 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3274 return;
3275 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3276 return;
3277 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3278 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3279 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3280 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3281 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3282 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3283 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3284 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3285 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3286 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3287 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3288 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3289 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3290 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3291 if (PyDict_SetItemString(d, "comprehension",
3292 (PyObject*)comprehension_type) < 0) return;
3293 if (PyDict_SetItemString(d, "excepthandler",
3294 (PyObject*)excepthandler_type) < 0) return;
3295 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3296 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003297 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3298 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3299 0) return;
3300 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3301 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003302 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3303 return;
3304 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003305}
3306
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003307
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003308PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003309{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003310 init_types();
3311 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003312}
3313
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003314