blob: 070c2dbd9ad7428ed41b1cbc9622a5276cc246b2 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum514a0f22007-05-15 20:34:04 +00005 __version__ 55343.
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*);
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000370static char *arg_fields[]={
Neal Norwitzc1505362006-12-28 06:47:50 +0000371 "arg",
372 "annotation",
373};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000374static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000375static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000376static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000377 "arg",
378 "value",
379};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000380static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000381static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000382static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000383 "name",
384 "asname",
385};
386
387
388static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
389{
390 PyObject *fnames, *result;
391 int i;
392 if (num_fields) {
393 fnames = PyTuple_New(num_fields);
394 if (!fnames) return NULL;
395 } else {
396 fnames = Py_None;
397 Py_INCREF(Py_None);
398 }
399 for(i=0; i < num_fields; i++) {
400 PyObject *field = PyString_FromString(fields[i]);
401 if (!field) {
402 Py_DECREF(fnames);
403 return NULL;
404 }
405 PyTuple_SET_ITEM(fnames, i, field);
406 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000407 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000408 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000409 Py_DECREF(fnames);
410 return (PyTypeObject*)result;
411}
412
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000413static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
414{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000415 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000416 PyObject *s, *l = PyList_New(num_fields);
417 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000418 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000419 s = PyString_FromString(attrs[i]);
420 if (!s) {
421 Py_DECREF(l);
422 return 0;
423 }
424 PyList_SET_ITEM(l, i, s);
425 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000426 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
427 Py_DECREF(l);
428 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000429}
430
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000431static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
432{
433 int i, n = asdl_seq_LEN(seq);
434 PyObject *result = PyList_New(n);
435 PyObject *value;
436 if (!result)
437 return NULL;
438 for (i = 0; i < n; i++) {
439 value = func(asdl_seq_GET(seq, i));
440 if (!value) {
441 Py_DECREF(result);
442 return NULL;
443 }
444 PyList_SET_ITEM(result, i, value);
445 }
446 return result;
447}
448
449static PyObject* ast2obj_object(void *o)
450{
451 if (!o)
452 o = Py_None;
453 Py_INCREF((PyObject*)o);
454 return (PyObject*)o;
455}
456#define ast2obj_identifier ast2obj_object
457#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000458
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000459static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460{
461 return PyInt_FromLong(b);
462}
463
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464static int init_types(void)
465{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000466 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
469 mod_type = make_type("mod", AST_type, NULL, 0);
470 if (!mod_type) return 0;
471 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000474 Interactive_type = make_type("Interactive", mod_type,
475 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Expression_type = make_type("Expression", mod_type, Expression_fields,
478 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!Suite_type) return 0;
482 stmt_type = make_type("stmt", AST_type, NULL, 0);
483 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000484 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000486 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!FunctionDef_type) return 0;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000488 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000497 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000503 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000504 With_type = make_type("With", stmt_type, With_fields, 3);
505 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
511 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000512 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000513 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000515 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000516 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000517 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000518 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000522 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
523 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000526 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000528 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000529 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000530 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!Continue_type) return 0;
532 expr_type = make_type("expr", AST_type, NULL, 0);
533 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000534 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000543 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000547 Set_type = make_type("Set", expr_type, Set_fields, 1);
548 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000551 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
552 if (!SetComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553 GeneratorExp_type = make_type("GeneratorExp", expr_type,
554 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000566 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
567 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000568 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
569 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Subscript_type) return 0;
Guido van Rossum0368b722007-05-11 16:50:42 +0000574 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
575 if (!Starred_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000576 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000580 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000581 if (!Tuple_type) return 0;
582 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
583 if (!expr_context_type) return 0;
584 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000585 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000589 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000591 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000592 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000593 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000595 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000597 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000599 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Param_singleton) return 0;
609 slice_type = make_type("slice", AST_type, NULL, 0);
610 if (!slice_type) return 0;
611 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000612 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000614 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000616 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!Index_type) return 0;
618 boolop_type = make_type("boolop", AST_type, NULL, 0);
619 if (!boolop_type) return 0;
620 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000621 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000625 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000627 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!Or_singleton) return 0;
629 operator_type = make_type("operator", AST_type, NULL, 0);
630 if (!operator_type) return 0;
631 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000632 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000634 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000636 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000638 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000640 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000642 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000644 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000646 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000664 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000666 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000668 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000670 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000671 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000672 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000673 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000674 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000676 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000678 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000679 if (!FloorDiv_singleton) return 0;
680 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
681 if (!unaryop_type) return 0;
682 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000683 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000687 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000689 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000691 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000693 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000695 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000697 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!USub_singleton) return 0;
699 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
700 if (!cmpop_type) return 0;
701 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000702 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000704 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000706 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000708 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000710 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000714 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000716 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000718 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000720 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000722 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000724 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000725 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000726 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000728 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000730 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000731 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000732 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000733 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000734 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000736 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000737 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000738 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000739 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000740 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000741 if (!NotIn_singleton) return 0;
742 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000743 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000744 if (!comprehension_type) return 0;
745 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000746 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000747 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000748 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000749 if (!arguments_type) return 0;
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000750 arg_type = make_type("arg", AST_type, arg_fields, 2);
Neal Norwitzc1505362006-12-28 06:47:50 +0000751 if (!arg_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000752 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
753 if (!keyword_type) return 0;
754 alias_type = make_type("alias", AST_type, alias_fields, 2);
755 if (!alias_type) return 0;
756 initialized = 1;
757 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000758}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000759
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000760mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000761Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000762{
763 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000764 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000765 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 p->kind = Module_kind;
768 p->v.Module.body = body;
769 return p;
770}
771
772mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000773Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000774{
775 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000776 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000777 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000779 p->kind = Interactive_kind;
780 p->v.Interactive.body = body;
781 return p;
782}
783
784mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000785Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000786{
787 mod_ty p;
788 if (!body) {
789 PyErr_SetString(PyExc_ValueError,
790 "field body is required for Expression");
791 return NULL;
792 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000793 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000794 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000795 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000796 p->kind = Expression_kind;
797 p->v.Expression.body = body;
798 return p;
799}
800
801mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000802Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000803{
804 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000805 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000806 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000807 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000808 p->kind = Suite_kind;
809 p->v.Suite.body = body;
810 return p;
811}
812
813stmt_ty
814FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000815 decorators, expr_ty returns, int lineno, int col_offset, PyArena
816 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817{
818 stmt_ty p;
819 if (!name) {
820 PyErr_SetString(PyExc_ValueError,
821 "field name is required for FunctionDef");
822 return NULL;
823 }
824 if (!args) {
825 PyErr_SetString(PyExc_ValueError,
826 "field args is required for FunctionDef");
827 return NULL;
828 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000829 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000830 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000831 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 p->kind = FunctionDef_kind;
833 p->v.FunctionDef.name = name;
834 p->v.FunctionDef.args = args;
835 p->v.FunctionDef.body = body;
836 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000837 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000838 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000839 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840 return p;
841}
842
843stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000844ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
845 starargs, expr_ty kwargs, asdl_seq * body, int lineno, int col_offset,
846 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847{
848 stmt_ty p;
849 if (!name) {
850 PyErr_SetString(PyExc_ValueError,
851 "field name is required for ClassDef");
852 return NULL;
853 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000854 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000855 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000857 p->kind = ClassDef_kind;
858 p->v.ClassDef.name = name;
859 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000860 p->v.ClassDef.keywords = keywords;
861 p->v.ClassDef.starargs = starargs;
862 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000863 p->v.ClassDef.body = body;
864 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000865 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 return p;
867}
868
869stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000870Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871{
872 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000873 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000874 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 p->kind = Return_kind;
877 p->v.Return.value = value;
878 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000879 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000880 return p;
881}
882
883stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000884Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885{
886 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000887 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000888 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000889 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890 p->kind = Delete_kind;
891 p->v.Delete.targets = targets;
892 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000893 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894 return p;
895}
896
897stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000898Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
899 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000900{
901 stmt_ty p;
902 if (!value) {
903 PyErr_SetString(PyExc_ValueError,
904 "field value is required for Assign");
905 return NULL;
906 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000907 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000908 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000909 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000910 p->kind = Assign_kind;
911 p->v.Assign.targets = targets;
912 p->v.Assign.value = value;
913 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000914 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000915 return p;
916}
917
918stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000919AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
920 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000921{
922 stmt_ty p;
923 if (!target) {
924 PyErr_SetString(PyExc_ValueError,
925 "field target is required for AugAssign");
926 return NULL;
927 }
928 if (!op) {
929 PyErr_SetString(PyExc_ValueError,
930 "field op is required for AugAssign");
931 return NULL;
932 }
933 if (!value) {
934 PyErr_SetString(PyExc_ValueError,
935 "field value is required for AugAssign");
936 return NULL;
937 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000938 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000939 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000940 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941 p->kind = AugAssign_kind;
942 p->v.AugAssign.target = target;
943 p->v.AugAssign.op = op;
944 p->v.AugAssign.value = value;
945 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000946 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000947 return p;
948}
949
950stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000952 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000953{
954 stmt_ty p;
955 if (!target) {
956 PyErr_SetString(PyExc_ValueError,
957 "field target is required for For");
958 return NULL;
959 }
960 if (!iter) {
961 PyErr_SetString(PyExc_ValueError,
962 "field iter is required for For");
963 return NULL;
964 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000965 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000966 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000967 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000968 p->kind = For_kind;
969 p->v.For.target = target;
970 p->v.For.iter = iter;
971 p->v.For.body = body;
972 p->v.For.orelse = orelse;
973 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000974 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000975 return p;
976}
977
978stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000979While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
980 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000981{
982 stmt_ty p;
983 if (!test) {
984 PyErr_SetString(PyExc_ValueError,
985 "field test is required for While");
986 return NULL;
987 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000988 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000989 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000990 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991 p->kind = While_kind;
992 p->v.While.test = test;
993 p->v.While.body = body;
994 p->v.While.orelse = orelse;
995 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000996 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000997 return p;
998}
999
1000stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001001If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1002 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003{
1004 stmt_ty p;
1005 if (!test) {
1006 PyErr_SetString(PyExc_ValueError,
1007 "field test is required for If");
1008 return NULL;
1009 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001010 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001011 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001012 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013 p->kind = If_kind;
1014 p->v.If.test = test;
1015 p->v.If.body = body;
1016 p->v.If.orelse = orelse;
1017 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001018 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001019 return p;
1020}
1021
1022stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001023With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001024 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025{
1026 stmt_ty p;
1027 if (!context_expr) {
1028 PyErr_SetString(PyExc_ValueError,
1029 "field context_expr is required for With");
1030 return NULL;
1031 }
1032 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001033 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001034 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001035 p->kind = With_kind;
1036 p->v.With.context_expr = context_expr;
1037 p->v.With.optional_vars = optional_vars;
1038 p->v.With.body = body;
1039 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001040 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001041 return p;
1042}
1043
1044stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001045Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1046 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001047{
1048 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001049 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001050 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001051 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001052 p->kind = Raise_kind;
1053 p->v.Raise.type = type;
1054 p->v.Raise.inst = inst;
1055 p->v.Raise.tback = tback;
1056 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001057 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001058 return p;
1059}
1060
1061stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001062TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001063 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001064{
1065 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001066 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001067 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001069 p->kind = TryExcept_kind;
1070 p->v.TryExcept.body = body;
1071 p->v.TryExcept.handlers = handlers;
1072 p->v.TryExcept.orelse = orelse;
1073 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001074 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return p;
1076}
1077
1078stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001079TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1080 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081{
1082 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001083 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001084 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001086 p->kind = TryFinally_kind;
1087 p->v.TryFinally.body = body;
1088 p->v.TryFinally.finalbody = finalbody;
1089 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001090 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001091 return p;
1092}
1093
1094stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001095Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096{
1097 stmt_ty p;
1098 if (!test) {
1099 PyErr_SetString(PyExc_ValueError,
1100 "field test is required for Assert");
1101 return NULL;
1102 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001103 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001104 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001105 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106 p->kind = Assert_kind;
1107 p->v.Assert.test = test;
1108 p->v.Assert.msg = msg;
1109 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001110 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001111 return p;
1112}
1113
1114stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001115Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116{
1117 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001118 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001119 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001121 p->kind = Import_kind;
1122 p->v.Import.names = names;
1123 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001124 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 return p;
1126}
1127
1128stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001129ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1130 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131{
1132 stmt_ty p;
1133 if (!module) {
1134 PyErr_SetString(PyExc_ValueError,
1135 "field module is required for ImportFrom");
1136 return NULL;
1137 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001138 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001139 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001140 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001141 p->kind = ImportFrom_kind;
1142 p->v.ImportFrom.module = module;
1143 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001144 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001146 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147 return p;
1148}
1149
1150stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001151Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001152{
1153 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001154 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001155 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001156 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 p->kind = Global_kind;
1158 p->v.Global.names = names;
1159 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001160 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 return p;
1162}
1163
1164stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001165Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1166{
1167 stmt_ty p;
1168 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1169 if (!p)
1170 return NULL;
1171 p->kind = Nonlocal_kind;
1172 p->v.Nonlocal.names = names;
1173 p->lineno = lineno;
1174 p->col_offset = col_offset;
1175 return p;
1176}
1177
1178stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001179Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001180{
1181 stmt_ty p;
1182 if (!value) {
1183 PyErr_SetString(PyExc_ValueError,
1184 "field value is required for Expr");
1185 return NULL;
1186 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001187 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001188 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001189 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190 p->kind = Expr_kind;
1191 p->v.Expr.value = value;
1192 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001193 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194 return p;
1195}
1196
1197stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001198Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199{
1200 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001201 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001202 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204 p->kind = Pass_kind;
1205 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001206 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 return p;
1208}
1209
1210stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001211Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001212{
1213 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001214 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001215 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001216 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217 p->kind = Break_kind;
1218 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001219 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 return p;
1221}
1222
1223stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001224Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001225{
1226 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001227 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001228 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230 p->kind = Continue_kind;
1231 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001232 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001233 return p;
1234}
1235
1236expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001237BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1238 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239{
1240 expr_ty p;
1241 if (!op) {
1242 PyErr_SetString(PyExc_ValueError,
1243 "field op is required for BoolOp");
1244 return NULL;
1245 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001246 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001247 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001248 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 p->kind = BoolOp_kind;
1250 p->v.BoolOp.op = op;
1251 p->v.BoolOp.values = values;
1252 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001253 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001254 return p;
1255}
1256
1257expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001258BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1259 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001260{
1261 expr_ty p;
1262 if (!left) {
1263 PyErr_SetString(PyExc_ValueError,
1264 "field left is required for BinOp");
1265 return NULL;
1266 }
1267 if (!op) {
1268 PyErr_SetString(PyExc_ValueError,
1269 "field op is required for BinOp");
1270 return NULL;
1271 }
1272 if (!right) {
1273 PyErr_SetString(PyExc_ValueError,
1274 "field right is required for BinOp");
1275 return NULL;
1276 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001277 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001278 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001279 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001280 p->kind = BinOp_kind;
1281 p->v.BinOp.left = left;
1282 p->v.BinOp.op = op;
1283 p->v.BinOp.right = right;
1284 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001285 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001286 return p;
1287}
1288
1289expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001290UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1291 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292{
1293 expr_ty p;
1294 if (!op) {
1295 PyErr_SetString(PyExc_ValueError,
1296 "field op is required for UnaryOp");
1297 return NULL;
1298 }
1299 if (!operand) {
1300 PyErr_SetString(PyExc_ValueError,
1301 "field operand is required for UnaryOp");
1302 return NULL;
1303 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001304 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001305 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001306 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001307 p->kind = UnaryOp_kind;
1308 p->v.UnaryOp.op = op;
1309 p->v.UnaryOp.operand = operand;
1310 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001311 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001312 return p;
1313}
1314
1315expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001316Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1317 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318{
1319 expr_ty p;
1320 if (!args) {
1321 PyErr_SetString(PyExc_ValueError,
1322 "field args is required for Lambda");
1323 return NULL;
1324 }
1325 if (!body) {
1326 PyErr_SetString(PyExc_ValueError,
1327 "field body is required for Lambda");
1328 return NULL;
1329 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001330 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001331 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001332 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001333 p->kind = Lambda_kind;
1334 p->v.Lambda.args = args;
1335 p->v.Lambda.body = body;
1336 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001337 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001338 return p;
1339}
1340
1341expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001342IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1343 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001344{
1345 expr_ty p;
1346 if (!test) {
1347 PyErr_SetString(PyExc_ValueError,
1348 "field test is required for IfExp");
1349 return NULL;
1350 }
1351 if (!body) {
1352 PyErr_SetString(PyExc_ValueError,
1353 "field body is required for IfExp");
1354 return NULL;
1355 }
1356 if (!orelse) {
1357 PyErr_SetString(PyExc_ValueError,
1358 "field orelse is required for IfExp");
1359 return NULL;
1360 }
1361 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001362 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001363 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001364 p->kind = IfExp_kind;
1365 p->v.IfExp.test = test;
1366 p->v.IfExp.body = body;
1367 p->v.IfExp.orelse = orelse;
1368 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001369 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001370 return p;
1371}
1372
1373expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001374Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1375 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001376{
1377 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001378 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001379 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001380 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001381 p->kind = Dict_kind;
1382 p->v.Dict.keys = keys;
1383 p->v.Dict.values = values;
1384 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001385 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001386 return p;
1387}
1388
1389expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001390Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1391{
1392 expr_ty p;
1393 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001394 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001395 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001396 p->kind = Set_kind;
1397 p->v.Set.elts = elts;
1398 p->lineno = lineno;
1399 p->col_offset = col_offset;
1400 return p;
1401}
1402
1403expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001404ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1405 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001406{
1407 expr_ty p;
1408 if (!elt) {
1409 PyErr_SetString(PyExc_ValueError,
1410 "field elt is required for ListComp");
1411 return NULL;
1412 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001413 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001414 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001415 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001416 p->kind = ListComp_kind;
1417 p->v.ListComp.elt = elt;
1418 p->v.ListComp.generators = generators;
1419 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001420 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001421 return p;
1422}
1423
1424expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001425SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1426 *arena)
1427{
1428 expr_ty p;
1429 if (!elt) {
1430 PyErr_SetString(PyExc_ValueError,
1431 "field elt is required for SetComp");
1432 return NULL;
1433 }
1434 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1435 if (!p)
1436 return NULL;
1437 p->kind = SetComp_kind;
1438 p->v.SetComp.elt = elt;
1439 p->v.SetComp.generators = generators;
1440 p->lineno = lineno;
1441 p->col_offset = col_offset;
1442 return p;
1443}
1444
1445expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001446GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1447 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001448{
1449 expr_ty p;
1450 if (!elt) {
1451 PyErr_SetString(PyExc_ValueError,
1452 "field elt is required for GeneratorExp");
1453 return NULL;
1454 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001455 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001456 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001457 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001458 p->kind = GeneratorExp_kind;
1459 p->v.GeneratorExp.elt = elt;
1460 p->v.GeneratorExp.generators = generators;
1461 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001462 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 return p;
1464}
1465
1466expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001467Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001468{
1469 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001470 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001471 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001473 p->kind = Yield_kind;
1474 p->v.Yield.value = value;
1475 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001476 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 return p;
1478}
1479
1480expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001481Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1482 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001483{
1484 expr_ty p;
1485 if (!left) {
1486 PyErr_SetString(PyExc_ValueError,
1487 "field left is required for Compare");
1488 return NULL;
1489 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001490 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001491 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001493 p->kind = Compare_kind;
1494 p->v.Compare.left = left;
1495 p->v.Compare.ops = ops;
1496 p->v.Compare.comparators = comparators;
1497 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001498 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001499 return p;
1500}
1501
1502expr_ty
1503Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001504 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001505{
1506 expr_ty p;
1507 if (!func) {
1508 PyErr_SetString(PyExc_ValueError,
1509 "field func is required for Call");
1510 return NULL;
1511 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001512 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001513 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001515 p->kind = Call_kind;
1516 p->v.Call.func = func;
1517 p->v.Call.args = args;
1518 p->v.Call.keywords = keywords;
1519 p->v.Call.starargs = starargs;
1520 p->v.Call.kwargs = kwargs;
1521 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001522 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001523 return p;
1524}
1525
1526expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001527Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001528{
1529 expr_ty p;
1530 if (!n) {
1531 PyErr_SetString(PyExc_ValueError,
1532 "field n is required for Num");
1533 return NULL;
1534 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001535 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001536 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001537 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 p->kind = Num_kind;
1539 p->v.Num.n = n;
1540 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001541 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542 return p;
1543}
1544
1545expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001546Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001547{
1548 expr_ty p;
1549 if (!s) {
1550 PyErr_SetString(PyExc_ValueError,
1551 "field s is required for Str");
1552 return NULL;
1553 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001554 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001555 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001556 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001557 p->kind = Str_kind;
1558 p->v.Str.s = s;
1559 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001560 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561 return p;
1562}
1563
1564expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001565Bytes(string s, int lineno, int col_offset, PyArena *arena)
1566{
1567 expr_ty p;
1568 if (!s) {
1569 PyErr_SetString(PyExc_ValueError,
1570 "field s is required for Bytes");
1571 return NULL;
1572 }
1573 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001574 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001575 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001576 p->kind = Bytes_kind;
1577 p->v.Bytes.s = s;
1578 p->lineno = lineno;
1579 p->col_offset = col_offset;
1580 return p;
1581}
1582
1583expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001584Ellipsis(int lineno, int col_offset, PyArena *arena)
1585{
1586 expr_ty p;
1587 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001588 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001589 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001590 p->kind = Ellipsis_kind;
1591 p->lineno = lineno;
1592 p->col_offset = col_offset;
1593 return p;
1594}
1595
1596expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001597Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1598 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001599{
1600 expr_ty p;
1601 if (!value) {
1602 PyErr_SetString(PyExc_ValueError,
1603 "field value is required for Attribute");
1604 return NULL;
1605 }
1606 if (!attr) {
1607 PyErr_SetString(PyExc_ValueError,
1608 "field attr is required for Attribute");
1609 return NULL;
1610 }
1611 if (!ctx) {
1612 PyErr_SetString(PyExc_ValueError,
1613 "field ctx is required for Attribute");
1614 return NULL;
1615 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001616 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001617 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001618 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001619 p->kind = Attribute_kind;
1620 p->v.Attribute.value = value;
1621 p->v.Attribute.attr = attr;
1622 p->v.Attribute.ctx = ctx;
1623 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001624 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001625 return p;
1626}
1627
1628expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001629Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1630 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001631{
1632 expr_ty p;
1633 if (!value) {
1634 PyErr_SetString(PyExc_ValueError,
1635 "field value is required for Subscript");
1636 return NULL;
1637 }
1638 if (!slice) {
1639 PyErr_SetString(PyExc_ValueError,
1640 "field slice is required for Subscript");
1641 return NULL;
1642 }
1643 if (!ctx) {
1644 PyErr_SetString(PyExc_ValueError,
1645 "field ctx is required for Subscript");
1646 return NULL;
1647 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001648 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001649 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001650 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001651 p->kind = Subscript_kind;
1652 p->v.Subscript.value = value;
1653 p->v.Subscript.slice = slice;
1654 p->v.Subscript.ctx = ctx;
1655 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001656 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001657 return p;
1658}
1659
1660expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00001661Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
1662 *arena)
1663{
1664 expr_ty p;
1665 if (!value) {
1666 PyErr_SetString(PyExc_ValueError,
1667 "field value is required for Starred");
1668 return NULL;
1669 }
1670 if (!ctx) {
1671 PyErr_SetString(PyExc_ValueError,
1672 "field ctx is required for Starred");
1673 return NULL;
1674 }
1675 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1676 if (!p)
1677 return NULL;
1678 p->kind = Starred_kind;
1679 p->v.Starred.value = value;
1680 p->v.Starred.ctx = ctx;
1681 p->lineno = lineno;
1682 p->col_offset = col_offset;
1683 return p;
1684}
1685
1686expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001687Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1688 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001689{
1690 expr_ty p;
1691 if (!id) {
1692 PyErr_SetString(PyExc_ValueError,
1693 "field id is required for Name");
1694 return NULL;
1695 }
1696 if (!ctx) {
1697 PyErr_SetString(PyExc_ValueError,
1698 "field ctx is required for Name");
1699 return NULL;
1700 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001701 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001702 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001704 p->kind = Name_kind;
1705 p->v.Name.id = id;
1706 p->v.Name.ctx = ctx;
1707 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001708 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001709 return p;
1710}
1711
1712expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001713List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1714 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715{
1716 expr_ty p;
1717 if (!ctx) {
1718 PyErr_SetString(PyExc_ValueError,
1719 "field ctx is required for List");
1720 return NULL;
1721 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001722 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001723 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001724 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725 p->kind = List_kind;
1726 p->v.List.elts = elts;
1727 p->v.List.ctx = ctx;
1728 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001729 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730 return p;
1731}
1732
1733expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001734Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1735 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001736{
1737 expr_ty p;
1738 if (!ctx) {
1739 PyErr_SetString(PyExc_ValueError,
1740 "field ctx is required for Tuple");
1741 return NULL;
1742 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001743 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001744 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001745 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001746 p->kind = Tuple_kind;
1747 p->v.Tuple.elts = elts;
1748 p->v.Tuple.ctx = ctx;
1749 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001750 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001751 return p;
1752}
1753
1754slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001755Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756{
1757 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001758 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001759 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 p->kind = Slice_kind;
1762 p->v.Slice.lower = lower;
1763 p->v.Slice.upper = upper;
1764 p->v.Slice.step = step;
1765 return p;
1766}
1767
1768slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001769ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770{
1771 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001772 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001773 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001774 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001775 p->kind = ExtSlice_kind;
1776 p->v.ExtSlice.dims = dims;
1777 return p;
1778}
1779
1780slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001781Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001782{
1783 slice_ty p;
1784 if (!value) {
1785 PyErr_SetString(PyExc_ValueError,
1786 "field value is required for Index");
1787 return NULL;
1788 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001789 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001790 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001792 p->kind = Index_kind;
1793 p->v.Index.value = value;
1794 return p;
1795}
1796
1797comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001798comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001799{
1800 comprehension_ty p;
1801 if (!target) {
1802 PyErr_SetString(PyExc_ValueError,
1803 "field target is required for comprehension");
1804 return NULL;
1805 }
1806 if (!iter) {
1807 PyErr_SetString(PyExc_ValueError,
1808 "field iter is required for comprehension");
1809 return NULL;
1810 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001811 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001812 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001814 p->target = target;
1815 p->iter = iter;
1816 p->ifs = ifs;
1817 return p;
1818}
1819
1820excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001821excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001822 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001823{
1824 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001825 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001826 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001827 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001828 p->type = type;
1829 p->name = name;
1830 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001831 p->lineno = lineno;
1832 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833 return p;
1834}
1835
1836arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001837arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1838 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1839 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001840{
1841 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001842 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001843 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001844 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845 p->args = args;
1846 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001847 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001848 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001849 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001850 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001851 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001852 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 return p;
1854}
1855
Neal Norwitzc1505362006-12-28 06:47:50 +00001856arg_ty
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001857arg(identifier arg, expr_ty annotation, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00001858{
1859 arg_ty p;
1860 if (!arg) {
1861 PyErr_SetString(PyExc_ValueError,
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001862 "field arg is required for arg");
Neal Norwitzc1505362006-12-28 06:47:50 +00001863 return NULL;
1864 }
1865 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001866 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001867 return NULL;
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001868 p->arg = arg;
1869 p->annotation = annotation;
Neal Norwitzc1505362006-12-28 06:47:50 +00001870 return p;
1871}
1872
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001873keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001874keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001875{
1876 keyword_ty p;
1877 if (!arg) {
1878 PyErr_SetString(PyExc_ValueError,
1879 "field arg is required for keyword");
1880 return NULL;
1881 }
1882 if (!value) {
1883 PyErr_SetString(PyExc_ValueError,
1884 "field value is required for keyword");
1885 return NULL;
1886 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001887 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001888 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001889 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001890 p->arg = arg;
1891 p->value = value;
1892 return p;
1893}
1894
1895alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001896alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897{
1898 alias_ty p;
1899 if (!name) {
1900 PyErr_SetString(PyExc_ValueError,
1901 "field name is required for alias");
1902 return NULL;
1903 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001904 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001905 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001907 p->name = name;
1908 p->asname = asname;
1909 return p;
1910}
1911
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001912
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001913PyObject*
1914ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001915{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001916 mod_ty o = (mod_ty)_o;
1917 PyObject *result = NULL, *value = NULL;
1918 if (!o) {
1919 Py_INCREF(Py_None);
1920 return Py_None;
1921 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001922
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923 switch (o->kind) {
1924 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001925 result = PyType_GenericNew(Module_type, NULL, NULL);
1926 if (!result) goto failed;
1927 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "body", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001932 break;
1933 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001934 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1935 if (!result) goto failed;
1936 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1937 if (!value) goto failed;
1938 if (PyObject_SetAttrString(result, "body", value) == -1)
1939 goto failed;
1940 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 break;
1942 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001943 result = PyType_GenericNew(Expression_type, NULL, NULL);
1944 if (!result) goto failed;
1945 value = ast2obj_expr(o->v.Expression.body);
1946 if (!value) goto failed;
1947 if (PyObject_SetAttrString(result, "body", value) == -1)
1948 goto failed;
1949 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001950 break;
1951 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001952 result = PyType_GenericNew(Suite_type, NULL, NULL);
1953 if (!result) goto failed;
1954 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1955 if (!value) goto failed;
1956 if (PyObject_SetAttrString(result, "body", value) == -1)
1957 goto failed;
1958 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001959 break;
1960 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001961 return result;
1962failed:
1963 Py_XDECREF(value);
1964 Py_XDECREF(result);
1965 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966}
1967
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968PyObject*
1969ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001970{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001971 stmt_ty o = (stmt_ty)_o;
1972 PyObject *result = NULL, *value = NULL;
1973 if (!o) {
1974 Py_INCREF(Py_None);
1975 return Py_None;
1976 }
1977
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978 switch (o->kind) {
1979 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001980 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1981 if (!result) goto failed;
1982 value = ast2obj_identifier(o->v.FunctionDef.name);
1983 if (!value) goto failed;
1984 if (PyObject_SetAttrString(result, "name", value) == -1)
1985 goto failed;
1986 Py_DECREF(value);
1987 value = ast2obj_arguments(o->v.FunctionDef.args);
1988 if (!value) goto failed;
1989 if (PyObject_SetAttrString(result, "args", value) == -1)
1990 goto failed;
1991 Py_DECREF(value);
1992 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1993 if (!value) goto failed;
1994 if (PyObject_SetAttrString(result, "body", value) == -1)
1995 goto failed;
1996 Py_DECREF(value);
1997 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1998 if (!value) goto failed;
1999 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2000 goto failed;
2001 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002002 value = ast2obj_expr(o->v.FunctionDef.returns);
2003 if (!value) goto failed;
2004 if (PyObject_SetAttrString(result, "returns", value) == -1)
2005 goto failed;
2006 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002007 break;
2008 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002009 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2010 if (!result) goto failed;
2011 value = ast2obj_identifier(o->v.ClassDef.name);
2012 if (!value) goto failed;
2013 if (PyObject_SetAttrString(result, "name", value) == -1)
2014 goto failed;
2015 Py_DECREF(value);
2016 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2017 if (!value) goto failed;
2018 if (PyObject_SetAttrString(result, "bases", value) == -1)
2019 goto failed;
2020 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002021 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
2026 value = ast2obj_expr(o->v.ClassDef.starargs);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
2031 value = ast2obj_expr(o->v.ClassDef.kwargs);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002036 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "body", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041 break;
2042 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002043 result = PyType_GenericNew(Return_type, NULL, NULL);
2044 if (!result) goto failed;
2045 value = ast2obj_expr(o->v.Return.value);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "value", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002050 break;
2051 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002052 result = PyType_GenericNew(Delete_type, NULL, NULL);
2053 if (!result) goto failed;
2054 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "targets", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002059 break;
2060 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002061 result = PyType_GenericNew(Assign_type, NULL, NULL);
2062 if (!result) goto failed;
2063 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2064 if (!value) goto failed;
2065 if (PyObject_SetAttrString(result, "targets", value) == -1)
2066 goto failed;
2067 Py_DECREF(value);
2068 value = ast2obj_expr(o->v.Assign.value);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "value", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002073 break;
2074 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002075 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2076 if (!result) goto failed;
2077 value = ast2obj_expr(o->v.AugAssign.target);
2078 if (!value) goto failed;
2079 if (PyObject_SetAttrString(result, "target", value) == -1)
2080 goto failed;
2081 Py_DECREF(value);
2082 value = ast2obj_operator(o->v.AugAssign.op);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "op", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
2087 value = ast2obj_expr(o->v.AugAssign.value);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "value", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002092 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002093 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002094 result = PyType_GenericNew(For_type, NULL, NULL);
2095 if (!result) goto failed;
2096 value = ast2obj_expr(o->v.For.target);
2097 if (!value) goto failed;
2098 if (PyObject_SetAttrString(result, "target", value) == -1)
2099 goto failed;
2100 Py_DECREF(value);
2101 value = ast2obj_expr(o->v.For.iter);
2102 if (!value) goto failed;
2103 if (PyObject_SetAttrString(result, "iter", value) == -1)
2104 goto failed;
2105 Py_DECREF(value);
2106 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "body", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002116 break;
2117 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002118 result = PyType_GenericNew(While_type, NULL, NULL);
2119 if (!result) goto failed;
2120 value = ast2obj_expr(o->v.While.test);
2121 if (!value) goto failed;
2122 if (PyObject_SetAttrString(result, "test", value) == -1)
2123 goto failed;
2124 Py_DECREF(value);
2125 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "body", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002135 break;
2136 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002137 result = PyType_GenericNew(If_type, NULL, NULL);
2138 if (!result) goto failed;
2139 value = ast2obj_expr(o->v.If.test);
2140 if (!value) goto failed;
2141 if (PyObject_SetAttrString(result, "test", value) == -1)
2142 goto failed;
2143 Py_DECREF(value);
2144 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "body", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002154 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002155 case With_kind:
2156 result = PyType_GenericNew(With_type, NULL, NULL);
2157 if (!result) goto failed;
2158 value = ast2obj_expr(o->v.With.context_expr);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
2163 value = ast2obj_expr(o->v.With.optional_vars);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2166 -1)
2167 goto failed;
2168 Py_DECREF(value);
2169 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2170 if (!value) goto failed;
2171 if (PyObject_SetAttrString(result, "body", value) == -1)
2172 goto failed;
2173 Py_DECREF(value);
2174 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002175 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002176 result = PyType_GenericNew(Raise_type, NULL, NULL);
2177 if (!result) goto failed;
2178 value = ast2obj_expr(o->v.Raise.type);
2179 if (!value) goto failed;
2180 if (PyObject_SetAttrString(result, "type", value) == -1)
2181 goto failed;
2182 Py_DECREF(value);
2183 value = ast2obj_expr(o->v.Raise.inst);
2184 if (!value) goto failed;
2185 if (PyObject_SetAttrString(result, "inst", value) == -1)
2186 goto failed;
2187 Py_DECREF(value);
2188 value = ast2obj_expr(o->v.Raise.tback);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "tback", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002193 break;
2194 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002195 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2196 if (!result) goto failed;
2197 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2198 if (!value) goto failed;
2199 if (PyObject_SetAttrString(result, "body", value) == -1)
2200 goto failed;
2201 Py_DECREF(value);
2202 value = ast2obj_list(o->v.TryExcept.handlers,
2203 ast2obj_excepthandler);
2204 if (!value) goto failed;
2205 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2206 goto failed;
2207 Py_DECREF(value);
2208 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002213 break;
2214 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002215 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2216 if (!result) goto failed;
2217 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2218 if (!value) goto failed;
2219 if (PyObject_SetAttrString(result, "body", value) == -1)
2220 goto failed;
2221 Py_DECREF(value);
2222 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002227 break;
2228 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002229 result = PyType_GenericNew(Assert_type, NULL, NULL);
2230 if (!result) goto failed;
2231 value = ast2obj_expr(o->v.Assert.test);
2232 if (!value) goto failed;
2233 if (PyObject_SetAttrString(result, "test", value) == -1)
2234 goto failed;
2235 Py_DECREF(value);
2236 value = ast2obj_expr(o->v.Assert.msg);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "msg", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241 break;
2242 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002243 result = PyType_GenericNew(Import_type, NULL, NULL);
2244 if (!result) goto failed;
2245 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "names", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002250 break;
2251 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002252 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2253 if (!result) goto failed;
2254 value = ast2obj_identifier(o->v.ImportFrom.module);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "module", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
2259 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "names", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002264 value = ast2obj_int(o->v.ImportFrom.level);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "level", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002269 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002270 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002271 result = PyType_GenericNew(Global_type, NULL, NULL);
2272 if (!result) goto failed;
2273 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2274 if (!value) goto failed;
2275 if (PyObject_SetAttrString(result, "names", value) == -1)
2276 goto failed;
2277 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002278 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002279 case Nonlocal_kind:
2280 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2281 if (!result) goto failed;
2282 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2283 if (!value) goto failed;
2284 if (PyObject_SetAttrString(result, "names", value) == -1)
2285 goto failed;
2286 Py_DECREF(value);
2287 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002289 result = PyType_GenericNew(Expr_type, NULL, NULL);
2290 if (!result) goto failed;
2291 value = ast2obj_expr(o->v.Expr.value);
2292 if (!value) goto failed;
2293 if (PyObject_SetAttrString(result, "value", value) == -1)
2294 goto failed;
2295 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002296 break;
2297 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002298 result = PyType_GenericNew(Pass_type, NULL, NULL);
2299 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002300 break;
2301 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002302 result = PyType_GenericNew(Break_type, NULL, NULL);
2303 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002304 break;
2305 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002306 result = PyType_GenericNew(Continue_type, NULL, NULL);
2307 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002308 break;
2309 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002310 value = ast2obj_int(o->lineno);
2311 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002312 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2313 goto failed;
2314 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002315 value = ast2obj_int(o->col_offset);
2316 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002317 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2318 goto failed;
2319 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002320 return result;
2321failed:
2322 Py_XDECREF(value);
2323 Py_XDECREF(result);
2324 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325}
2326
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002327PyObject*
2328ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002329{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002330 expr_ty o = (expr_ty)_o;
2331 PyObject *result = NULL, *value = NULL;
2332 if (!o) {
2333 Py_INCREF(Py_None);
2334 return Py_None;
2335 }
2336
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002337 switch (o->kind) {
2338 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002339 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2340 if (!result) goto failed;
2341 value = ast2obj_boolop(o->v.BoolOp.op);
2342 if (!value) goto failed;
2343 if (PyObject_SetAttrString(result, "op", value) == -1)
2344 goto failed;
2345 Py_DECREF(value);
2346 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2347 if (!value) goto failed;
2348 if (PyObject_SetAttrString(result, "values", value) == -1)
2349 goto failed;
2350 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002351 break;
2352 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002353 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2354 if (!result) goto failed;
2355 value = ast2obj_expr(o->v.BinOp.left);
2356 if (!value) goto failed;
2357 if (PyObject_SetAttrString(result, "left", value) == -1)
2358 goto failed;
2359 Py_DECREF(value);
2360 value = ast2obj_operator(o->v.BinOp.op);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "op", value) == -1)
2363 goto failed;
2364 Py_DECREF(value);
2365 value = ast2obj_expr(o->v.BinOp.right);
2366 if (!value) goto failed;
2367 if (PyObject_SetAttrString(result, "right", value) == -1)
2368 goto failed;
2369 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002370 break;
2371 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002372 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2373 if (!result) goto failed;
2374 value = ast2obj_unaryop(o->v.UnaryOp.op);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "op", value) == -1)
2377 goto failed;
2378 Py_DECREF(value);
2379 value = ast2obj_expr(o->v.UnaryOp.operand);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "operand", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002384 break;
2385 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002386 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2387 if (!result) goto failed;
2388 value = ast2obj_arguments(o->v.Lambda.args);
2389 if (!value) goto failed;
2390 if (PyObject_SetAttrString(result, "args", value) == -1)
2391 goto failed;
2392 Py_DECREF(value);
2393 value = ast2obj_expr(o->v.Lambda.body);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "body", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002398 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002399 case IfExp_kind:
2400 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2401 if (!result) goto failed;
2402 value = ast2obj_expr(o->v.IfExp.test);
2403 if (!value) goto failed;
2404 if (PyObject_SetAttrString(result, "test", value) == -1)
2405 goto failed;
2406 Py_DECREF(value);
2407 value = ast2obj_expr(o->v.IfExp.body);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "body", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
2412 value = ast2obj_expr(o->v.IfExp.orelse);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002418 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002419 result = PyType_GenericNew(Dict_type, NULL, NULL);
2420 if (!result) goto failed;
2421 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2422 if (!value) goto failed;
2423 if (PyObject_SetAttrString(result, "keys", value) == -1)
2424 goto failed;
2425 Py_DECREF(value);
2426 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2427 if (!value) goto failed;
2428 if (PyObject_SetAttrString(result, "values", value) == -1)
2429 goto failed;
2430 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002431 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002432 case Set_kind:
2433 result = PyType_GenericNew(Set_type, NULL, NULL);
2434 if (!result) goto failed;
2435 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "elts", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002441 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002442 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2443 if (!result) goto failed;
2444 value = ast2obj_expr(o->v.ListComp.elt);
2445 if (!value) goto failed;
2446 if (PyObject_SetAttrString(result, "elt", value) == -1)
2447 goto failed;
2448 Py_DECREF(value);
2449 value = ast2obj_list(o->v.ListComp.generators,
2450 ast2obj_comprehension);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "generators", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002456 case SetComp_kind:
2457 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2458 if (!result) goto failed;
2459 value = ast2obj_expr(o->v.SetComp.elt);
2460 if (!value) goto failed;
2461 if (PyObject_SetAttrString(result, "elt", value) == -1)
2462 goto failed;
2463 Py_DECREF(value);
2464 value = ast2obj_list(o->v.SetComp.generators,
2465 ast2obj_comprehension);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "generators", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002472 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2473 if (!result) goto failed;
2474 value = ast2obj_expr(o->v.GeneratorExp.elt);
2475 if (!value) goto failed;
2476 if (PyObject_SetAttrString(result, "elt", value) == -1)
2477 goto failed;
2478 Py_DECREF(value);
2479 value = ast2obj_list(o->v.GeneratorExp.generators,
2480 ast2obj_comprehension);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "generators", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002485 break;
2486 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002487 result = PyType_GenericNew(Yield_type, NULL, NULL);
2488 if (!result) goto failed;
2489 value = ast2obj_expr(o->v.Yield.value);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "value", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002494 break;
2495 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002496 result = PyType_GenericNew(Compare_type, NULL, NULL);
2497 if (!result) goto failed;
2498 value = ast2obj_expr(o->v.Compare.left);
2499 if (!value) goto failed;
2500 if (PyObject_SetAttrString(result, "left", value) == -1)
2501 goto failed;
2502 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002503 {
2504 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2505 value = PyList_New(n);
2506 if (!value) goto failed;
2507 for(i = 0; i < n; i++)
2508 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2509 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "ops", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
2514 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002519 break;
2520 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002521 result = PyType_GenericNew(Call_type, NULL, NULL);
2522 if (!result) goto failed;
2523 value = ast2obj_expr(o->v.Call.func);
2524 if (!value) goto failed;
2525 if (PyObject_SetAttrString(result, "func", value) == -1)
2526 goto failed;
2527 Py_DECREF(value);
2528 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2529 if (!value) goto failed;
2530 if (PyObject_SetAttrString(result, "args", value) == -1)
2531 goto failed;
2532 Py_DECREF(value);
2533 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2534 if (!value) goto failed;
2535 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2536 goto failed;
2537 Py_DECREF(value);
2538 value = ast2obj_expr(o->v.Call.starargs);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
2543 value = ast2obj_expr(o->v.Call.kwargs);
2544 if (!value) goto failed;
2545 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2546 goto failed;
2547 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002548 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002549 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002550 result = PyType_GenericNew(Num_type, NULL, NULL);
2551 if (!result) goto failed;
2552 value = ast2obj_object(o->v.Num.n);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "n", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557 break;
2558 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002559 result = PyType_GenericNew(Str_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_string(o->v.Str.s);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "s", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002566 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002567 case Bytes_kind:
2568 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2569 if (!result) goto failed;
2570 value = ast2obj_string(o->v.Bytes.s);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "s", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
2575 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002576 case Ellipsis_kind:
2577 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2578 if (!result) goto failed;
2579 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002580 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002581 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2582 if (!result) goto failed;
2583 value = ast2obj_expr(o->v.Attribute.value);
2584 if (!value) goto failed;
2585 if (PyObject_SetAttrString(result, "value", value) == -1)
2586 goto failed;
2587 Py_DECREF(value);
2588 value = ast2obj_identifier(o->v.Attribute.attr);
2589 if (!value) goto failed;
2590 if (PyObject_SetAttrString(result, "attr", value) == -1)
2591 goto failed;
2592 Py_DECREF(value);
2593 value = ast2obj_expr_context(o->v.Attribute.ctx);
2594 if (!value) goto failed;
2595 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2596 goto failed;
2597 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002598 break;
2599 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002600 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2601 if (!result) goto failed;
2602 value = ast2obj_expr(o->v.Subscript.value);
2603 if (!value) goto failed;
2604 if (PyObject_SetAttrString(result, "value", value) == -1)
2605 goto failed;
2606 Py_DECREF(value);
2607 value = ast2obj_slice(o->v.Subscript.slice);
2608 if (!value) goto failed;
2609 if (PyObject_SetAttrString(result, "slice", value) == -1)
2610 goto failed;
2611 Py_DECREF(value);
2612 value = ast2obj_expr_context(o->v.Subscript.ctx);
2613 if (!value) goto failed;
2614 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2615 goto failed;
2616 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002617 break;
Guido van Rossum0368b722007-05-11 16:50:42 +00002618 case Starred_kind:
2619 result = PyType_GenericNew(Starred_type, NULL, NULL);
2620 if (!result) goto failed;
2621 value = ast2obj_expr(o->v.Starred.value);
2622 if (!value) goto failed;
2623 if (PyObject_SetAttrString(result, "value", value) == -1)
2624 goto failed;
2625 Py_DECREF(value);
2626 value = ast2obj_expr_context(o->v.Starred.ctx);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
2631 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002633 result = PyType_GenericNew(Name_type, NULL, NULL);
2634 if (!result) goto failed;
2635 value = ast2obj_identifier(o->v.Name.id);
2636 if (!value) goto failed;
2637 if (PyObject_SetAttrString(result, "id", value) == -1)
2638 goto failed;
2639 Py_DECREF(value);
2640 value = ast2obj_expr_context(o->v.Name.ctx);
2641 if (!value) goto failed;
2642 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2643 goto failed;
2644 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002645 break;
2646 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002647 result = PyType_GenericNew(List_type, NULL, NULL);
2648 if (!result) goto failed;
2649 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2650 if (!value) goto failed;
2651 if (PyObject_SetAttrString(result, "elts", value) == -1)
2652 goto failed;
2653 Py_DECREF(value);
2654 value = ast2obj_expr_context(o->v.List.ctx);
2655 if (!value) goto failed;
2656 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2657 goto failed;
2658 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002659 break;
2660 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002661 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2662 if (!result) goto failed;
2663 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2664 if (!value) goto failed;
2665 if (PyObject_SetAttrString(result, "elts", value) == -1)
2666 goto failed;
2667 Py_DECREF(value);
2668 value = ast2obj_expr_context(o->v.Tuple.ctx);
2669 if (!value) goto failed;
2670 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2671 goto failed;
2672 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002673 break;
2674 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002675 value = ast2obj_int(o->lineno);
2676 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002677 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2678 goto failed;
2679 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002680 value = ast2obj_int(o->col_offset);
2681 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002682 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2683 goto failed;
2684 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002685 return result;
2686failed:
2687 Py_XDECREF(value);
2688 Py_XDECREF(result);
2689 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690}
2691
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002692PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 switch(o) {
2695 case Load:
2696 Py_INCREF(Load_singleton);
2697 return Load_singleton;
2698 case Store:
2699 Py_INCREF(Store_singleton);
2700 return Store_singleton;
2701 case Del:
2702 Py_INCREF(Del_singleton);
2703 return Del_singleton;
2704 case AugLoad:
2705 Py_INCREF(AugLoad_singleton);
2706 return AugLoad_singleton;
2707 case AugStore:
2708 Py_INCREF(AugStore_singleton);
2709 return AugStore_singleton;
2710 case Param:
2711 Py_INCREF(Param_singleton);
2712 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002713 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002714 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002716PyObject*
2717ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002718{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002719 slice_ty o = (slice_ty)_o;
2720 PyObject *result = NULL, *value = NULL;
2721 if (!o) {
2722 Py_INCREF(Py_None);
2723 return Py_None;
2724 }
2725
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002726 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002727 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002728 result = PyType_GenericNew(Slice_type, NULL, NULL);
2729 if (!result) goto failed;
2730 value = ast2obj_expr(o->v.Slice.lower);
2731 if (!value) goto failed;
2732 if (PyObject_SetAttrString(result, "lower", value) == -1)
2733 goto failed;
2734 Py_DECREF(value);
2735 value = ast2obj_expr(o->v.Slice.upper);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "upper", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
2740 value = ast2obj_expr(o->v.Slice.step);
2741 if (!value) goto failed;
2742 if (PyObject_SetAttrString(result, "step", value) == -1)
2743 goto failed;
2744 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002745 break;
2746 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002747 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2748 if (!result) goto failed;
2749 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2750 if (!value) goto failed;
2751 if (PyObject_SetAttrString(result, "dims", value) == -1)
2752 goto failed;
2753 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002754 break;
2755 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002756 result = PyType_GenericNew(Index_type, NULL, NULL);
2757 if (!result) goto failed;
2758 value = ast2obj_expr(o->v.Index.value);
2759 if (!value) goto failed;
2760 if (PyObject_SetAttrString(result, "value", value) == -1)
2761 goto failed;
2762 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002763 break;
2764 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002765 return result;
2766failed:
2767 Py_XDECREF(value);
2768 Py_XDECREF(result);
2769 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002770}
2771
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002772PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002773{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002774 switch(o) {
2775 case And:
2776 Py_INCREF(And_singleton);
2777 return And_singleton;
2778 case Or:
2779 Py_INCREF(Or_singleton);
2780 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002781 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002782 return NULL; /* cannot happen */
2783}
2784PyObject* ast2obj_operator(operator_ty o)
2785{
2786 switch(o) {
2787 case Add:
2788 Py_INCREF(Add_singleton);
2789 return Add_singleton;
2790 case Sub:
2791 Py_INCREF(Sub_singleton);
2792 return Sub_singleton;
2793 case Mult:
2794 Py_INCREF(Mult_singleton);
2795 return Mult_singleton;
2796 case Div:
2797 Py_INCREF(Div_singleton);
2798 return Div_singleton;
2799 case Mod:
2800 Py_INCREF(Mod_singleton);
2801 return Mod_singleton;
2802 case Pow:
2803 Py_INCREF(Pow_singleton);
2804 return Pow_singleton;
2805 case LShift:
2806 Py_INCREF(LShift_singleton);
2807 return LShift_singleton;
2808 case RShift:
2809 Py_INCREF(RShift_singleton);
2810 return RShift_singleton;
2811 case BitOr:
2812 Py_INCREF(BitOr_singleton);
2813 return BitOr_singleton;
2814 case BitXor:
2815 Py_INCREF(BitXor_singleton);
2816 return BitXor_singleton;
2817 case BitAnd:
2818 Py_INCREF(BitAnd_singleton);
2819 return BitAnd_singleton;
2820 case FloorDiv:
2821 Py_INCREF(FloorDiv_singleton);
2822 return FloorDiv_singleton;
2823 }
2824 return NULL; /* cannot happen */
2825}
2826PyObject* ast2obj_unaryop(unaryop_ty o)
2827{
2828 switch(o) {
2829 case Invert:
2830 Py_INCREF(Invert_singleton);
2831 return Invert_singleton;
2832 case Not:
2833 Py_INCREF(Not_singleton);
2834 return Not_singleton;
2835 case UAdd:
2836 Py_INCREF(UAdd_singleton);
2837 return UAdd_singleton;
2838 case USub:
2839 Py_INCREF(USub_singleton);
2840 return USub_singleton;
2841 }
2842 return NULL; /* cannot happen */
2843}
2844PyObject* ast2obj_cmpop(cmpop_ty o)
2845{
2846 switch(o) {
2847 case Eq:
2848 Py_INCREF(Eq_singleton);
2849 return Eq_singleton;
2850 case NotEq:
2851 Py_INCREF(NotEq_singleton);
2852 return NotEq_singleton;
2853 case Lt:
2854 Py_INCREF(Lt_singleton);
2855 return Lt_singleton;
2856 case LtE:
2857 Py_INCREF(LtE_singleton);
2858 return LtE_singleton;
2859 case Gt:
2860 Py_INCREF(Gt_singleton);
2861 return Gt_singleton;
2862 case GtE:
2863 Py_INCREF(GtE_singleton);
2864 return GtE_singleton;
2865 case Is:
2866 Py_INCREF(Is_singleton);
2867 return Is_singleton;
2868 case IsNot:
2869 Py_INCREF(IsNot_singleton);
2870 return IsNot_singleton;
2871 case In:
2872 Py_INCREF(In_singleton);
2873 return In_singleton;
2874 case NotIn:
2875 Py_INCREF(NotIn_singleton);
2876 return NotIn_singleton;
2877 }
2878 return NULL; /* cannot happen */
2879}
2880PyObject*
2881ast2obj_comprehension(void* _o)
2882{
2883 comprehension_ty o = (comprehension_ty)_o;
2884 PyObject *result = NULL, *value = NULL;
2885 if (!o) {
2886 Py_INCREF(Py_None);
2887 return Py_None;
2888 }
2889
2890 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2891 if (!result) return NULL;
2892 value = ast2obj_expr(o->target);
2893 if (!value) goto failed;
2894 if (PyObject_SetAttrString(result, "target", value) == -1)
2895 goto failed;
2896 Py_DECREF(value);
2897 value = ast2obj_expr(o->iter);
2898 if (!value) goto failed;
2899 if (PyObject_SetAttrString(result, "iter", value) == -1)
2900 goto failed;
2901 Py_DECREF(value);
2902 value = ast2obj_list(o->ifs, ast2obj_expr);
2903 if (!value) goto failed;
2904 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2905 goto failed;
2906 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002907 return result;
2908failed:
2909 Py_XDECREF(value);
2910 Py_XDECREF(result);
2911 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002912}
2913
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002914PyObject*
2915ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002916{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002917 excepthandler_ty o = (excepthandler_ty)_o;
2918 PyObject *result = NULL, *value = NULL;
2919 if (!o) {
2920 Py_INCREF(Py_None);
2921 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002922 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002923
2924 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2925 if (!result) return NULL;
2926 value = ast2obj_expr(o->type);
2927 if (!value) goto failed;
2928 if (PyObject_SetAttrString(result, "type", value) == -1)
2929 goto failed;
2930 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002931 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002932 if (!value) goto failed;
2933 if (PyObject_SetAttrString(result, "name", value) == -1)
2934 goto failed;
2935 Py_DECREF(value);
2936 value = ast2obj_list(o->body, ast2obj_stmt);
2937 if (!value) goto failed;
2938 if (PyObject_SetAttrString(result, "body", value) == -1)
2939 goto failed;
2940 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002941 value = ast2obj_int(o->lineno);
2942 if (!value) goto failed;
2943 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2944 goto failed;
2945 Py_DECREF(value);
2946 value = ast2obj_int(o->col_offset);
2947 if (!value) goto failed;
2948 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2949 goto failed;
2950 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951 return result;
2952failed:
2953 Py_XDECREF(value);
2954 Py_XDECREF(result);
2955 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002956}
2957
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002958PyObject*
2959ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002960{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002961 arguments_ty o = (arguments_ty)_o;
2962 PyObject *result = NULL, *value = NULL;
2963 if (!o) {
2964 Py_INCREF(Py_None);
2965 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002966 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002967
2968 result = PyType_GenericNew(arguments_type, NULL, NULL);
2969 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002970 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "args", value) == -1)
2973 goto failed;
2974 Py_DECREF(value);
2975 value = ast2obj_identifier(o->vararg);
2976 if (!value) goto failed;
2977 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2978 goto failed;
2979 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002980 value = ast2obj_expr(o->varargannotation);
2981 if (!value) goto failed;
2982 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2983 goto failed;
2984 Py_DECREF(value);
2985 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002986 if (!value) goto failed;
2987 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2988 goto failed;
2989 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002990 value = ast2obj_identifier(o->kwarg);
2991 if (!value) goto failed;
2992 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2993 goto failed;
2994 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002995 value = ast2obj_expr(o->kwargannotation);
2996 if (!value) goto failed;
2997 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2998 goto failed;
2999 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003000 value = ast2obj_list(o->defaults, ast2obj_expr);
3001 if (!value) goto failed;
3002 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3003 goto failed;
3004 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003005 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3006 if (!value) goto failed;
3007 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3008 goto failed;
3009 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003010 return result;
3011failed:
3012 Py_XDECREF(value);
3013 Py_XDECREF(result);
3014 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003015}
3016
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003017PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003018ast2obj_arg(void* _o)
3019{
3020 arg_ty o = (arg_ty)_o;
3021 PyObject *result = NULL, *value = NULL;
3022 if (!o) {
3023 Py_INCREF(Py_None);
3024 return Py_None;
3025 }
3026
Guido van Rossum1bc535d2007-05-15 18:46:22 +00003027 result = PyType_GenericNew(arg_type, NULL, NULL);
3028 if (!result) return NULL;
3029 value = ast2obj_identifier(o->arg);
3030 if (!value) goto failed;
3031 if (PyObject_SetAttrString(result, "arg", value) == -1)
3032 goto failed;
3033 Py_DECREF(value);
3034 value = ast2obj_expr(o->annotation);
3035 if (!value) goto failed;
3036 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3037 goto failed;
3038 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003039 return result;
3040failed:
3041 Py_XDECREF(value);
3042 Py_XDECREF(result);
3043 return NULL;
3044}
3045
3046PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003047ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003048{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003049 keyword_ty o = (keyword_ty)_o;
3050 PyObject *result = NULL, *value = NULL;
3051 if (!o) {
3052 Py_INCREF(Py_None);
3053 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003054 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003055
3056 result = PyType_GenericNew(keyword_type, NULL, NULL);
3057 if (!result) return NULL;
3058 value = ast2obj_identifier(o->arg);
3059 if (!value) goto failed;
3060 if (PyObject_SetAttrString(result, "arg", value) == -1)
3061 goto failed;
3062 Py_DECREF(value);
3063 value = ast2obj_expr(o->value);
3064 if (!value) goto failed;
3065 if (PyObject_SetAttrString(result, "value", value) == -1)
3066 goto failed;
3067 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003068 return result;
3069failed:
3070 Py_XDECREF(value);
3071 Py_XDECREF(result);
3072 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003073}
3074
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003075PyObject*
3076ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003077{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003078 alias_ty o = (alias_ty)_o;
3079 PyObject *result = NULL, *value = NULL;
3080 if (!o) {
3081 Py_INCREF(Py_None);
3082 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003083 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003084
3085 result = PyType_GenericNew(alias_type, NULL, NULL);
3086 if (!result) return NULL;
3087 value = ast2obj_identifier(o->name);
3088 if (!value) goto failed;
3089 if (PyObject_SetAttrString(result, "name", value) == -1)
3090 goto failed;
3091 Py_DECREF(value);
3092 value = ast2obj_identifier(o->asname);
3093 if (!value) goto failed;
3094 if (PyObject_SetAttrString(result, "asname", value) == -1)
3095 goto failed;
3096 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003097 return result;
3098failed:
3099 Py_XDECREF(value);
3100 Py_XDECREF(result);
3101 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003102}
3103
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003104
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003105PyMODINIT_FUNC
3106init_ast(void)
3107{
3108 PyObject *m, *d;
3109 if (!init_types()) return;
3110 m = Py_InitModule3("_ast", NULL, NULL);
3111 if (!m) return;
3112 d = PyModule_GetDict(m);
3113 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3114 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3115 return;
Guido van Rossum514a0f22007-05-15 20:34:04 +00003116 if (PyModule_AddStringConstant(m, "__version__", "55343") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003117 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003118 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3120 return;
3121 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3122 < 0) return;
3123 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3124 0) return;
3125 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3126 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3127 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3128 < 0) return;
3129 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3130 return;
3131 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3132 return;
3133 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3134 return;
3135 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3136 return;
3137 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3138 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003139 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3140 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3141 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3142 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3143 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3144 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3145 0) return;
3146 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3147 0) return;
3148 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3149 return;
3150 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3151 return;
3152 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3153 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003154 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3155 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003156 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3157 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003158 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3159 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3160 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3161 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3162 return;
3163 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3164 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3165 return;
3166 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3167 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3168 return;
3169 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3170 return;
3171 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3172 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003173 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003174 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3175 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003176 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3177 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003178 if (PyDict_SetItemString(d, "GeneratorExp",
3179 (PyObject*)GeneratorExp_type) < 0) return;
3180 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3181 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3182 return;
3183 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003184 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3185 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003186 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003187 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3188 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003189 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3190 0) return;
3191 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3192 0) return;
Guido van Rossum0368b722007-05-11 16:50:42 +00003193 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
3194 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003195 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3196 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3197 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3198 if (PyDict_SetItemString(d, "expr_context",
3199 (PyObject*)expr_context_type) < 0) return;
3200 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3201 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3202 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3203 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3204 return;
3205 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3206 return;
3207 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3208 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003209 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3210 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3211 return;
3212 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3213 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3214 return;
3215 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3216 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3217 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3218 return;
3219 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3220 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3221 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3222 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3223 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3224 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3225 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3226 return;
3227 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3228 return;
3229 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3230 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3231 return;
3232 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3233 return;
3234 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3235 return;
3236 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3237 return;
3238 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3239 return;
3240 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3241 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3242 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3243 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3244 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3245 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3246 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3247 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3248 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3249 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3250 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3251 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3252 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3253 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3254 if (PyDict_SetItemString(d, "comprehension",
3255 (PyObject*)comprehension_type) < 0) return;
3256 if (PyDict_SetItemString(d, "excepthandler",
3257 (PyObject*)excepthandler_type) < 0) return;
3258 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3259 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003260 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003261 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3262 return;
3263 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003264}
3265
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003266
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003267PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003268{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003269 init_types();
3270 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003271}
3272
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003273