blob: c46176cb6aba7f7c81f47a6f780856682422b62d [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum71d4a342007-08-31 04:03:25 +00005 __version__ 57783.
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",
Guido van Rossumd59da4b2007-05-22 18:11:13 +000045 "decorator_list",
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",
Guido van Rossumd59da4b2007-05-22 18:11:13 +000056 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000057};
Neal Norwitz53d960c2006-02-28 22:47:29 +000058static PyTypeObject *Return_type;
59static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000060 "value",
61};
Neal Norwitz53d960c2006-02-28 22:47:29 +000062static PyTypeObject *Delete_type;
63static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000064 "targets",
65};
Neal Norwitz53d960c2006-02-28 22:47:29 +000066static PyTypeObject *Assign_type;
67static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000068 "targets",
69 "value",
70};
Neal Norwitz53d960c2006-02-28 22:47:29 +000071static PyTypeObject *AugAssign_type;
72static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000073 "target",
74 "op",
75 "value",
76};
Neal Norwitz53d960c2006-02-28 22:47:29 +000077static PyTypeObject *For_type;
78static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000079 "target",
80 "iter",
81 "body",
82 "orelse",
83};
Neal Norwitz53d960c2006-02-28 22:47:29 +000084static PyTypeObject *While_type;
85static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000086 "test",
87 "body",
88 "orelse",
89};
Neal Norwitz53d960c2006-02-28 22:47:29 +000090static PyTypeObject *If_type;
91static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000092 "test",
93 "body",
94 "orelse",
95};
Neal Norwitz53d960c2006-02-28 22:47:29 +000096static PyTypeObject *With_type;
97static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000098 "context_expr",
99 "optional_vars",
100 "body",
101};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000102static PyTypeObject *Raise_type;
103static char *Raise_fields[]={
Collin Winter828f04a2007-08-31 00:04:24 +0000104 "exc",
105 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000106};
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};
Guido van Rossum992d4a32007-07-11 13:09:30 +0000200static PyTypeObject *DictComp_type;
201static char *DictComp_fields[]={
202 "key",
203 "value",
204 "generators",
205};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000206static PyTypeObject *GeneratorExp_type;
207static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000208 "elt",
209 "generators",
210};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000211static PyTypeObject *Yield_type;
212static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213 "value",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Compare_type;
216static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "left",
218 "ops",
219 "comparators",
220};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000221static PyTypeObject *Call_type;
222static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000223 "func",
224 "args",
225 "keywords",
226 "starargs",
227 "kwargs",
228};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000229static PyTypeObject *Num_type;
230static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000231 "n",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *Str_type;
234static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "s",
236};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000237static PyTypeObject *Bytes_type;
238static char *Bytes_fields[]={
239 "s",
240};
Georg Brandl52318d62006-09-06 07:06:08 +0000241static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Attribute_type;
243static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244 "value",
245 "attr",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *Subscript_type;
249static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000250 "value",
251 "slice",
252 "ctx",
253};
Guido van Rossum0368b722007-05-11 16:50:42 +0000254static PyTypeObject *Starred_type;
255static char *Starred_fields[]={
256 "value",
257 "ctx",
258};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000259static PyTypeObject *Name_type;
260static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000261 "id",
262 "ctx",
263};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000264static PyTypeObject *List_type;
265static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000266 "elts",
267 "ctx",
268};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *Tuple_type;
270static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271 "elts",
272 "ctx",
273};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000274static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000275static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
276*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
277static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000278static PyTypeObject *Load_type;
279static PyTypeObject *Store_type;
280static PyTypeObject *Del_type;
281static PyTypeObject *AugLoad_type;
282static PyTypeObject *AugStore_type;
283static PyTypeObject *Param_type;
284static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000285static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000286static PyTypeObject *Slice_type;
287static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000288 "lower",
289 "upper",
290 "step",
291};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000292static PyTypeObject *ExtSlice_type;
293static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000294 "dims",
295};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000296static PyTypeObject *Index_type;
297static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000298 "value",
299};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000300static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000301static PyObject *And_singleton, *Or_singleton;
302static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000303static PyTypeObject *And_type;
304static PyTypeObject *Or_type;
305static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000306static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
307*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
308*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
309*FloorDiv_singleton;
310static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Add_type;
312static PyTypeObject *Sub_type;
313static PyTypeObject *Mult_type;
314static PyTypeObject *Div_type;
315static PyTypeObject *Mod_type;
316static PyTypeObject *Pow_type;
317static PyTypeObject *LShift_type;
318static PyTypeObject *RShift_type;
319static PyTypeObject *BitOr_type;
320static PyTypeObject *BitXor_type;
321static PyTypeObject *BitAnd_type;
322static PyTypeObject *FloorDiv_type;
323static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
325*USub_singleton;
326static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000327static PyTypeObject *Invert_type;
328static PyTypeObject *Not_type;
329static PyTypeObject *UAdd_type;
330static PyTypeObject *USub_type;
331static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000332static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
333*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
334*NotIn_singleton;
335static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000336static PyTypeObject *Eq_type;
337static PyTypeObject *NotEq_type;
338static PyTypeObject *Lt_type;
339static PyTypeObject *LtE_type;
340static PyTypeObject *Gt_type;
341static PyTypeObject *GtE_type;
342static PyTypeObject *Is_type;
343static PyTypeObject *IsNot_type;
344static PyTypeObject *In_type;
345static PyTypeObject *NotIn_type;
346static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000347static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000348static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000349 "target",
350 "iter",
351 "ifs",
352};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000353static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000354static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000355static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000356 "type",
357 "name",
358 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000359 "lineno",
360 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000361};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000362static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000363static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000364static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000365 "args",
366 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000367 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000368 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000369 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000370 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000371 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000372 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000373};
Neal Norwitzc1505362006-12-28 06:47:50 +0000374static PyTypeObject *arg_type;
375static PyObject* ast2obj_arg(void*);
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000376static char *arg_fields[]={
Neal Norwitzc1505362006-12-28 06:47:50 +0000377 "arg",
378 "annotation",
379};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000380static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000381static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000382static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000383 "arg",
384 "value",
385};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000386static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000387static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000388static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000389 "name",
390 "asname",
391};
392
393
394static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
395{
396 PyObject *fnames, *result;
397 int i;
398 if (num_fields) {
399 fnames = PyTuple_New(num_fields);
400 if (!fnames) return NULL;
401 } else {
402 fnames = Py_None;
403 Py_INCREF(Py_None);
404 }
405 for(i=0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000406 PyObject *field = PyUnicode_FromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000407 if (!field) {
408 Py_DECREF(fnames);
409 return NULL;
410 }
411 PyTuple_SET_ITEM(fnames, i, field);
412 }
Guido van Rossume845c0f2007-11-02 23:07:07 +0000413 result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000414 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000415 Py_DECREF(fnames);
416 return (PyTypeObject*)result;
417}
418
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000419static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
420{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000421 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000422 PyObject *s, *l = PyList_New(num_fields);
423 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000424 for(i = 0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000425 s = PyUnicode_FromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000426 if (!s) {
427 Py_DECREF(l);
428 return 0;
429 }
430 PyList_SET_ITEM(l, i, s);
431 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000432 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
433 Py_DECREF(l);
434 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000435}
436
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000437static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
438{
439 int i, n = asdl_seq_LEN(seq);
440 PyObject *result = PyList_New(n);
441 PyObject *value;
442 if (!result)
443 return NULL;
444 for (i = 0; i < n; i++) {
445 value = func(asdl_seq_GET(seq, i));
446 if (!value) {
447 Py_DECREF(result);
448 return NULL;
449 }
450 PyList_SET_ITEM(result, i, value);
451 }
452 return result;
453}
454
455static PyObject* ast2obj_object(void *o)
456{
457 if (!o)
458 o = Py_None;
459 Py_INCREF((PyObject*)o);
460 return (PyObject*)o;
461}
462#define ast2obj_identifier ast2obj_object
463#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000465static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466{
Christian Heimes217cfd12007-12-02 14:31:20 +0000467 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468}
469
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000470static int init_types(void)
471{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000472 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
475 mod_type = make_type("mod", AST_type, NULL, 0);
476 if (!mod_type) return 0;
477 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000478 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 Interactive_type = make_type("Interactive", mod_type,
481 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 Expression_type = make_type("Expression", mod_type, Expression_fields,
484 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Suite_type) return 0;
488 stmt_type = make_type("stmt", AST_type, NULL, 0);
489 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000490 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000492 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!FunctionDef_type) return 0;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000494 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000497 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000503 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000504 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000505 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000510 With_type = make_type("With", stmt_type, With_fields, 3);
511 if (!With_type) return 0;
Collin Winter828f04a2007-08-31 00:04:24 +0000512 Raise_type = make_type("Raise", stmt_type, Raise_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
517 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000518 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000519 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000520 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000521 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000523 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000524 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000528 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
529 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000530 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000532 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000533 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000534 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000535 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000536 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000537 if (!Continue_type) return 0;
538 expr_type = make_type("expr", AST_type, NULL, 0);
539 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000540 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000547 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000549 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000551 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000552 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000553 Set_type = make_type("Set", expr_type, Set_fields, 1);
554 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000555 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000556 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000557 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
558 if (!SetComp_type) return 0;
Guido van Rossum992d4a32007-07-11 13:09:30 +0000559 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
560 if (!DictComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000561 GeneratorExp_type = make_type("GeneratorExp", expr_type,
562 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000574 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
575 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000576 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
577 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000580 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000581 if (!Subscript_type) return 0;
Guido van Rossum0368b722007-05-11 16:50:42 +0000582 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
583 if (!Starred_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000584 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000585 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000586 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000588 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!Tuple_type) return 0;
590 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
591 if (!expr_context_type) return 0;
592 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000593 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000595 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000597 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000599 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000609 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000611 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000613 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Param_singleton) return 0;
617 slice_type = make_type("slice", AST_type, NULL, 0);
618 if (!slice_type) return 0;
619 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000620 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000622 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000624 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!Index_type) return 0;
626 boolop_type = make_type("boolop", AST_type, NULL, 0);
627 if (!boolop_type) return 0;
628 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000629 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000631 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000633 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000635 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!Or_singleton) return 0;
637 operator_type = make_type("operator", AST_type, NULL, 0);
638 if (!operator_type) return 0;
639 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000640 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000642 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000644 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000646 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000664 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000666 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000668 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000670 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000671 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000672 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000673 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000674 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000676 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000678 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000679 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000680 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000681 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000682 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000683 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000684 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000686 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!FloorDiv_singleton) return 0;
688 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
689 if (!unaryop_type) return 0;
690 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000691 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000693 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000695 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000697 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000699 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000701 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000703 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!USub_singleton) return 0;
707 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
708 if (!cmpop_type) return 0;
709 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000710 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000714 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000716 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000718 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000720 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000722 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000724 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000725 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000726 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000728 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000730 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000731 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000732 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000733 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000734 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000736 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000737 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000738 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000739 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000740 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000741 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000742 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000743 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000744 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000745 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000746 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000747 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000748 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000749 if (!NotIn_singleton) return 0;
750 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000751 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000752 if (!comprehension_type) return 0;
753 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000754 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000755 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000756 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000757 if (!arguments_type) return 0;
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000758 arg_type = make_type("arg", AST_type, arg_fields, 2);
Neal Norwitzc1505362006-12-28 06:47:50 +0000759 if (!arg_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000760 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
761 if (!keyword_type) return 0;
762 alias_type = make_type("alias", AST_type, alias_fields, 2);
763 if (!alias_type) return 0;
764 initialized = 1;
765 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000766}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000767
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000768mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000769Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000770{
771 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000772 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000773 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000774 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 p->kind = Module_kind;
776 p->v.Module.body = body;
777 return p;
778}
779
780mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000781Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000782{
783 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000784 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000785 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000786 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787 p->kind = Interactive_kind;
788 p->v.Interactive.body = body;
789 return p;
790}
791
792mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000793Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000794{
795 mod_ty p;
796 if (!body) {
797 PyErr_SetString(PyExc_ValueError,
798 "field body is required for Expression");
799 return NULL;
800 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000801 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000802 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000803 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 p->kind = Expression_kind;
805 p->v.Expression.body = body;
806 return p;
807}
808
809mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000810Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811{
812 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000813 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000814 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000815 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000816 p->kind = Suite_kind;
817 p->v.Suite.body = body;
818 return p;
819}
820
821stmt_ty
822FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000823 decorator_list, expr_ty returns, int lineno, int col_offset,
824 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825{
826 stmt_ty p;
827 if (!name) {
828 PyErr_SetString(PyExc_ValueError,
829 "field name is required for FunctionDef");
830 return NULL;
831 }
832 if (!args) {
833 PyErr_SetString(PyExc_ValueError,
834 "field args is required for FunctionDef");
835 return NULL;
836 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000837 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000838 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000839 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840 p->kind = FunctionDef_kind;
841 p->v.FunctionDef.name = name;
842 p->v.FunctionDef.args = args;
843 p->v.FunctionDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000844 p->v.FunctionDef.decorator_list = decorator_list;
Neal Norwitzc1505362006-12-28 06:47:50 +0000845 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000846 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000847 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000848 return p;
849}
850
851stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000852ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000853 starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list,
854 int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000855{
856 stmt_ty p;
857 if (!name) {
858 PyErr_SetString(PyExc_ValueError,
859 "field name is required for ClassDef");
860 return NULL;
861 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000862 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000863 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 p->kind = ClassDef_kind;
866 p->v.ClassDef.name = name;
867 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000868 p->v.ClassDef.keywords = keywords;
869 p->v.ClassDef.starargs = starargs;
870 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871 p->v.ClassDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000872 p->v.ClassDef.decorator_list = decorator_list;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000874 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875 return p;
876}
877
878stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000879Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000880{
881 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000882 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000883 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000884 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885 p->kind = Return_kind;
886 p->v.Return.value = value;
887 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000888 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000889 return p;
890}
891
892stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000893Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894{
895 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000896 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000897 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 p->kind = Delete_kind;
900 p->v.Delete.targets = targets;
901 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000902 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000903 return p;
904}
905
906stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000907Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
908 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000909{
910 stmt_ty p;
911 if (!value) {
912 PyErr_SetString(PyExc_ValueError,
913 "field value is required for Assign");
914 return NULL;
915 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000916 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000917 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000918 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000919 p->kind = Assign_kind;
920 p->v.Assign.targets = targets;
921 p->v.Assign.value = value;
922 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000923 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000924 return p;
925}
926
927stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000928AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
929 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930{
931 stmt_ty p;
932 if (!target) {
933 PyErr_SetString(PyExc_ValueError,
934 "field target is required for AugAssign");
935 return NULL;
936 }
937 if (!op) {
938 PyErr_SetString(PyExc_ValueError,
939 "field op is required for AugAssign");
940 return NULL;
941 }
942 if (!value) {
943 PyErr_SetString(PyExc_ValueError,
944 "field value is required for AugAssign");
945 return NULL;
946 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000947 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000948 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000950 p->kind = AugAssign_kind;
951 p->v.AugAssign.target = target;
952 p->v.AugAssign.op = op;
953 p->v.AugAssign.value = value;
954 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000955 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000956 return p;
957}
958
959stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000960For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000961 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000962{
963 stmt_ty p;
964 if (!target) {
965 PyErr_SetString(PyExc_ValueError,
966 "field target is required for For");
967 return NULL;
968 }
969 if (!iter) {
970 PyErr_SetString(PyExc_ValueError,
971 "field iter is required for For");
972 return NULL;
973 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000974 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000975 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000976 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 p->kind = For_kind;
978 p->v.For.target = target;
979 p->v.For.iter = iter;
980 p->v.For.body = body;
981 p->v.For.orelse = orelse;
982 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000983 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000984 return p;
985}
986
987stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000988While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
989 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000990{
991 stmt_ty p;
992 if (!test) {
993 PyErr_SetString(PyExc_ValueError,
994 "field test is required for While");
995 return NULL;
996 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000997 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000998 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000999 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001000 p->kind = While_kind;
1001 p->v.While.test = test;
1002 p->v.While.body = body;
1003 p->v.While.orelse = orelse;
1004 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001005 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001006 return p;
1007}
1008
1009stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001010If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1011 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001012{
1013 stmt_ty p;
1014 if (!test) {
1015 PyErr_SetString(PyExc_ValueError,
1016 "field test is required for If");
1017 return NULL;
1018 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001019 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001020 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001021 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001022 p->kind = If_kind;
1023 p->v.If.test = test;
1024 p->v.If.body = body;
1025 p->v.If.orelse = orelse;
1026 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001027 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001028 return p;
1029}
1030
1031stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001032With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001033 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001034{
1035 stmt_ty p;
1036 if (!context_expr) {
1037 PyErr_SetString(PyExc_ValueError,
1038 "field context_expr is required for With");
1039 return NULL;
1040 }
1041 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001042 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001043 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001044 p->kind = With_kind;
1045 p->v.With.context_expr = context_expr;
1046 p->v.With.optional_vars = optional_vars;
1047 p->v.With.body = body;
1048 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001049 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001050 return p;
1051}
1052
1053stmt_ty
Collin Winter828f04a2007-08-31 00:04:24 +00001054Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001055{
1056 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001057 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001058 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001059 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001060 p->kind = Raise_kind;
Collin Winter828f04a2007-08-31 00:04:24 +00001061 p->v.Raise.exc = exc;
1062 p->v.Raise.cause = cause;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001064 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001065 return p;
1066}
1067
1068stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001069TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001070 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071{
1072 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001073 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001074 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076 p->kind = TryExcept_kind;
1077 p->v.TryExcept.body = body;
1078 p->v.TryExcept.handlers = handlers;
1079 p->v.TryExcept.orelse = orelse;
1080 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001081 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001082 return p;
1083}
1084
1085stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001086TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1087 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001088{
1089 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001090 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001091 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001093 p->kind = TryFinally_kind;
1094 p->v.TryFinally.body = body;
1095 p->v.TryFinally.finalbody = finalbody;
1096 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001097 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 return p;
1099}
1100
1101stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001102Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001103{
1104 stmt_ty p;
1105 if (!test) {
1106 PyErr_SetString(PyExc_ValueError,
1107 "field test is required for Assert");
1108 return NULL;
1109 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001110 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001111 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001112 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113 p->kind = Assert_kind;
1114 p->v.Assert.test = test;
1115 p->v.Assert.msg = msg;
1116 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001117 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118 return p;
1119}
1120
1121stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001122Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001123{
1124 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001125 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001126 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001127 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128 p->kind = Import_kind;
1129 p->v.Import.names = names;
1130 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001131 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001132 return p;
1133}
1134
1135stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001136ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1137 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001138{
1139 stmt_ty p;
1140 if (!module) {
1141 PyErr_SetString(PyExc_ValueError,
1142 "field module is required for ImportFrom");
1143 return NULL;
1144 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001145 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001146 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001148 p->kind = ImportFrom_kind;
1149 p->v.ImportFrom.module = module;
1150 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001151 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001152 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001153 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154 return p;
1155}
1156
1157stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001158Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159{
1160 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001161 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001162 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001164 p->kind = Global_kind;
1165 p->v.Global.names = names;
1166 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001167 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168 return p;
1169}
1170
1171stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001172Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1173{
1174 stmt_ty p;
1175 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1176 if (!p)
1177 return NULL;
1178 p->kind = Nonlocal_kind;
1179 p->v.Nonlocal.names = names;
1180 p->lineno = lineno;
1181 p->col_offset = col_offset;
1182 return p;
1183}
1184
1185stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001186Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001187{
1188 stmt_ty p;
1189 if (!value) {
1190 PyErr_SetString(PyExc_ValueError,
1191 "field value is required for Expr");
1192 return NULL;
1193 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001194 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001195 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001196 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 p->kind = Expr_kind;
1198 p->v.Expr.value = value;
1199 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001200 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201 return p;
1202}
1203
1204stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001205Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206{
1207 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001208 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001209 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001211 p->kind = Pass_kind;
1212 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001213 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214 return p;
1215}
1216
1217stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001218Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001219{
1220 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001221 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001222 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001224 p->kind = Break_kind;
1225 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001226 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 return p;
1228}
1229
1230stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001231Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232{
1233 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001234 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001235 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001237 p->kind = Continue_kind;
1238 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001239 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001240 return p;
1241}
1242
1243expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001244BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1245 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001246{
1247 expr_ty p;
1248 if (!op) {
1249 PyErr_SetString(PyExc_ValueError,
1250 "field op is required for BoolOp");
1251 return NULL;
1252 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001253 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001254 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001255 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001256 p->kind = BoolOp_kind;
1257 p->v.BoolOp.op = op;
1258 p->v.BoolOp.values = values;
1259 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001260 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001261 return p;
1262}
1263
1264expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001265BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1266 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001267{
1268 expr_ty p;
1269 if (!left) {
1270 PyErr_SetString(PyExc_ValueError,
1271 "field left is required for BinOp");
1272 return NULL;
1273 }
1274 if (!op) {
1275 PyErr_SetString(PyExc_ValueError,
1276 "field op is required for BinOp");
1277 return NULL;
1278 }
1279 if (!right) {
1280 PyErr_SetString(PyExc_ValueError,
1281 "field right is required for BinOp");
1282 return NULL;
1283 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001284 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001285 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001286 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001287 p->kind = BinOp_kind;
1288 p->v.BinOp.left = left;
1289 p->v.BinOp.op = op;
1290 p->v.BinOp.right = right;
1291 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001292 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001293 return p;
1294}
1295
1296expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001297UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1298 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001299{
1300 expr_ty p;
1301 if (!op) {
1302 PyErr_SetString(PyExc_ValueError,
1303 "field op is required for UnaryOp");
1304 return NULL;
1305 }
1306 if (!operand) {
1307 PyErr_SetString(PyExc_ValueError,
1308 "field operand is required for UnaryOp");
1309 return NULL;
1310 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001311 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001312 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001313 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001314 p->kind = UnaryOp_kind;
1315 p->v.UnaryOp.op = op;
1316 p->v.UnaryOp.operand = operand;
1317 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001318 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001319 return p;
1320}
1321
1322expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001323Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1324 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001325{
1326 expr_ty p;
1327 if (!args) {
1328 PyErr_SetString(PyExc_ValueError,
1329 "field args is required for Lambda");
1330 return NULL;
1331 }
1332 if (!body) {
1333 PyErr_SetString(PyExc_ValueError,
1334 "field body is required for Lambda");
1335 return NULL;
1336 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001337 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001338 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001339 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001340 p->kind = Lambda_kind;
1341 p->v.Lambda.args = args;
1342 p->v.Lambda.body = body;
1343 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001344 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001345 return p;
1346}
1347
1348expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001349IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1350 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001351{
1352 expr_ty p;
1353 if (!test) {
1354 PyErr_SetString(PyExc_ValueError,
1355 "field test is required for IfExp");
1356 return NULL;
1357 }
1358 if (!body) {
1359 PyErr_SetString(PyExc_ValueError,
1360 "field body is required for IfExp");
1361 return NULL;
1362 }
1363 if (!orelse) {
1364 PyErr_SetString(PyExc_ValueError,
1365 "field orelse is required for IfExp");
1366 return NULL;
1367 }
1368 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001369 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001370 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001371 p->kind = IfExp_kind;
1372 p->v.IfExp.test = test;
1373 p->v.IfExp.body = body;
1374 p->v.IfExp.orelse = orelse;
1375 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001376 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001377 return p;
1378}
1379
1380expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001381Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1382 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001383{
1384 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001385 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001386 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001387 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001388 p->kind = Dict_kind;
1389 p->v.Dict.keys = keys;
1390 p->v.Dict.values = values;
1391 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001392 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001393 return p;
1394}
1395
1396expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001397Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1398{
1399 expr_ty p;
1400 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001401 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001402 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001403 p->kind = Set_kind;
1404 p->v.Set.elts = elts;
1405 p->lineno = lineno;
1406 p->col_offset = col_offset;
1407 return p;
1408}
1409
1410expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001411ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1412 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001413{
1414 expr_ty p;
1415 if (!elt) {
1416 PyErr_SetString(PyExc_ValueError,
1417 "field elt is required for ListComp");
1418 return NULL;
1419 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001420 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001421 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001423 p->kind = ListComp_kind;
1424 p->v.ListComp.elt = elt;
1425 p->v.ListComp.generators = generators;
1426 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001427 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001428 return p;
1429}
1430
1431expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001432SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1433 *arena)
1434{
1435 expr_ty p;
1436 if (!elt) {
1437 PyErr_SetString(PyExc_ValueError,
1438 "field elt is required for SetComp");
1439 return NULL;
1440 }
1441 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1442 if (!p)
1443 return NULL;
1444 p->kind = SetComp_kind;
1445 p->v.SetComp.elt = elt;
1446 p->v.SetComp.generators = generators;
1447 p->lineno = lineno;
1448 p->col_offset = col_offset;
1449 return p;
1450}
1451
1452expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00001453DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1454 col_offset, PyArena *arena)
1455{
1456 expr_ty p;
1457 if (!key) {
1458 PyErr_SetString(PyExc_ValueError,
1459 "field key is required for DictComp");
1460 return NULL;
1461 }
1462 if (!value) {
1463 PyErr_SetString(PyExc_ValueError,
1464 "field value is required for DictComp");
1465 return NULL;
1466 }
1467 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1468 if (!p)
1469 return NULL;
1470 p->kind = DictComp_kind;
1471 p->v.DictComp.key = key;
1472 p->v.DictComp.value = value;
1473 p->v.DictComp.generators = generators;
1474 p->lineno = lineno;
1475 p->col_offset = col_offset;
1476 return p;
1477}
1478
1479expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001480GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1481 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001482{
1483 expr_ty p;
1484 if (!elt) {
1485 PyErr_SetString(PyExc_ValueError,
1486 "field elt is required for GeneratorExp");
1487 return NULL;
1488 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001489 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001490 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 p->kind = GeneratorExp_kind;
1493 p->v.GeneratorExp.elt = elt;
1494 p->v.GeneratorExp.generators = generators;
1495 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001496 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001497 return p;
1498}
1499
1500expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001501Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001502{
1503 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001504 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001505 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001507 p->kind = Yield_kind;
1508 p->v.Yield.value = value;
1509 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001510 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001511 return p;
1512}
1513
1514expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001515Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1516 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001517{
1518 expr_ty p;
1519 if (!left) {
1520 PyErr_SetString(PyExc_ValueError,
1521 "field left is required for Compare");
1522 return NULL;
1523 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001524 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001525 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001527 p->kind = Compare_kind;
1528 p->v.Compare.left = left;
1529 p->v.Compare.ops = ops;
1530 p->v.Compare.comparators = comparators;
1531 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001532 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001533 return p;
1534}
1535
1536expr_ty
1537Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001538 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001539{
1540 expr_ty p;
1541 if (!func) {
1542 PyErr_SetString(PyExc_ValueError,
1543 "field func is required for Call");
1544 return NULL;
1545 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001546 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001547 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549 p->kind = Call_kind;
1550 p->v.Call.func = func;
1551 p->v.Call.args = args;
1552 p->v.Call.keywords = keywords;
1553 p->v.Call.starargs = starargs;
1554 p->v.Call.kwargs = kwargs;
1555 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001556 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001557 return p;
1558}
1559
1560expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001561Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001562{
1563 expr_ty p;
1564 if (!n) {
1565 PyErr_SetString(PyExc_ValueError,
1566 "field n is required for Num");
1567 return NULL;
1568 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001569 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001570 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001571 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572 p->kind = Num_kind;
1573 p->v.Num.n = n;
1574 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001575 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001576 return p;
1577}
1578
1579expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001580Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001581{
1582 expr_ty p;
1583 if (!s) {
1584 PyErr_SetString(PyExc_ValueError,
1585 "field s is required for Str");
1586 return NULL;
1587 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001588 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001589 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001590 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001591 p->kind = Str_kind;
1592 p->v.Str.s = s;
1593 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001594 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001595 return p;
1596}
1597
1598expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001599Bytes(string s, int lineno, int col_offset, PyArena *arena)
1600{
1601 expr_ty p;
1602 if (!s) {
1603 PyErr_SetString(PyExc_ValueError,
1604 "field s is required for Bytes");
1605 return NULL;
1606 }
1607 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001608 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001609 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001610 p->kind = Bytes_kind;
1611 p->v.Bytes.s = s;
1612 p->lineno = lineno;
1613 p->col_offset = col_offset;
1614 return p;
1615}
1616
1617expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001618Ellipsis(int lineno, int col_offset, PyArena *arena)
1619{
1620 expr_ty p;
1621 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001622 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001623 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001624 p->kind = Ellipsis_kind;
1625 p->lineno = lineno;
1626 p->col_offset = col_offset;
1627 return p;
1628}
1629
1630expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001631Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1632 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001633{
1634 expr_ty p;
1635 if (!value) {
1636 PyErr_SetString(PyExc_ValueError,
1637 "field value is required for Attribute");
1638 return NULL;
1639 }
1640 if (!attr) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field attr is required for Attribute");
1643 return NULL;
1644 }
1645 if (!ctx) {
1646 PyErr_SetString(PyExc_ValueError,
1647 "field ctx is required for Attribute");
1648 return NULL;
1649 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001650 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001651 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 p->kind = Attribute_kind;
1654 p->v.Attribute.value = value;
1655 p->v.Attribute.attr = attr;
1656 p->v.Attribute.ctx = ctx;
1657 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001658 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659 return p;
1660}
1661
1662expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001663Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1664 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001665{
1666 expr_ty p;
1667 if (!value) {
1668 PyErr_SetString(PyExc_ValueError,
1669 "field value is required for Subscript");
1670 return NULL;
1671 }
1672 if (!slice) {
1673 PyErr_SetString(PyExc_ValueError,
1674 "field slice is required for Subscript");
1675 return NULL;
1676 }
1677 if (!ctx) {
1678 PyErr_SetString(PyExc_ValueError,
1679 "field ctx is required for Subscript");
1680 return NULL;
1681 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001682 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001683 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001685 p->kind = Subscript_kind;
1686 p->v.Subscript.value = value;
1687 p->v.Subscript.slice = slice;
1688 p->v.Subscript.ctx = ctx;
1689 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001690 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001691 return p;
1692}
1693
1694expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00001695Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
1696 *arena)
1697{
1698 expr_ty p;
1699 if (!value) {
1700 PyErr_SetString(PyExc_ValueError,
1701 "field value is required for Starred");
1702 return NULL;
1703 }
1704 if (!ctx) {
1705 PyErr_SetString(PyExc_ValueError,
1706 "field ctx is required for Starred");
1707 return NULL;
1708 }
1709 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1710 if (!p)
1711 return NULL;
1712 p->kind = Starred_kind;
1713 p->v.Starred.value = value;
1714 p->v.Starred.ctx = ctx;
1715 p->lineno = lineno;
1716 p->col_offset = col_offset;
1717 return p;
1718}
1719
1720expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001721Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1722 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001723{
1724 expr_ty p;
1725 if (!id) {
1726 PyErr_SetString(PyExc_ValueError,
1727 "field id is required for Name");
1728 return NULL;
1729 }
1730 if (!ctx) {
1731 PyErr_SetString(PyExc_ValueError,
1732 "field ctx is required for Name");
1733 return NULL;
1734 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001735 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001736 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001737 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 p->kind = Name_kind;
1739 p->v.Name.id = id;
1740 p->v.Name.ctx = ctx;
1741 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001742 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001743 return p;
1744}
1745
1746expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001747List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1748 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001749{
1750 expr_ty p;
1751 if (!ctx) {
1752 PyErr_SetString(PyExc_ValueError,
1753 "field ctx is required for List");
1754 return NULL;
1755 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001756 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001757 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001758 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001759 p->kind = List_kind;
1760 p->v.List.elts = elts;
1761 p->v.List.ctx = ctx;
1762 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001763 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001764 return p;
1765}
1766
1767expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001768Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1769 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770{
1771 expr_ty p;
1772 if (!ctx) {
1773 PyErr_SetString(PyExc_ValueError,
1774 "field ctx is required for Tuple");
1775 return NULL;
1776 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001778 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001779 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 p->kind = Tuple_kind;
1781 p->v.Tuple.elts = elts;
1782 p->v.Tuple.ctx = ctx;
1783 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001784 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001785 return p;
1786}
1787
1788slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001789Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001790{
1791 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001792 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001793 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001795 p->kind = Slice_kind;
1796 p->v.Slice.lower = lower;
1797 p->v.Slice.upper = upper;
1798 p->v.Slice.step = step;
1799 return p;
1800}
1801
1802slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001803ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001804{
1805 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001806 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001807 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001808 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001809 p->kind = ExtSlice_kind;
1810 p->v.ExtSlice.dims = dims;
1811 return p;
1812}
1813
1814slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001815Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001816{
1817 slice_ty p;
1818 if (!value) {
1819 PyErr_SetString(PyExc_ValueError,
1820 "field value is required for Index");
1821 return NULL;
1822 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001823 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001824 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001825 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001826 p->kind = Index_kind;
1827 p->v.Index.value = value;
1828 return p;
1829}
1830
1831comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001832comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833{
1834 comprehension_ty p;
1835 if (!target) {
1836 PyErr_SetString(PyExc_ValueError,
1837 "field target is required for comprehension");
1838 return NULL;
1839 }
1840 if (!iter) {
1841 PyErr_SetString(PyExc_ValueError,
1842 "field iter is required for comprehension");
1843 return NULL;
1844 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001845 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001846 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 p->target = target;
1849 p->iter = iter;
1850 p->ifs = ifs;
1851 return p;
1852}
1853
1854excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001855excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001856 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857{
1858 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001859 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001860 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001861 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 p->type = type;
1863 p->name = name;
1864 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001865 p->lineno = lineno;
1866 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001867 return p;
1868}
1869
1870arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001871arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1872 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1873 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001874{
1875 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001876 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001877 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001878 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879 p->args = args;
1880 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001881 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001882 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001883 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001884 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001885 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001886 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001887 return p;
1888}
1889
Neal Norwitzc1505362006-12-28 06:47:50 +00001890arg_ty
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001891arg(identifier arg, expr_ty annotation, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00001892{
1893 arg_ty p;
1894 if (!arg) {
1895 PyErr_SetString(PyExc_ValueError,
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001896 "field arg is required for arg");
Neal Norwitzc1505362006-12-28 06:47:50 +00001897 return NULL;
1898 }
1899 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001900 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001901 return NULL;
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001902 p->arg = arg;
1903 p->annotation = annotation;
Neal Norwitzc1505362006-12-28 06:47:50 +00001904 return p;
1905}
1906
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001907keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001908keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909{
1910 keyword_ty p;
1911 if (!arg) {
1912 PyErr_SetString(PyExc_ValueError,
1913 "field arg is required for keyword");
1914 return NULL;
1915 }
1916 if (!value) {
1917 PyErr_SetString(PyExc_ValueError,
1918 "field value is required for keyword");
1919 return NULL;
1920 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001921 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001922 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001924 p->arg = arg;
1925 p->value = value;
1926 return p;
1927}
1928
1929alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001930alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931{
1932 alias_ty p;
1933 if (!name) {
1934 PyErr_SetString(PyExc_ValueError,
1935 "field name is required for alias");
1936 return NULL;
1937 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001938 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001939 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001940 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 p->name = name;
1942 p->asname = asname;
1943 return p;
1944}
1945
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001946
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001947PyObject*
1948ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001949{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001950 mod_ty o = (mod_ty)_o;
1951 PyObject *result = NULL, *value = NULL;
1952 if (!o) {
1953 Py_INCREF(Py_None);
1954 return Py_None;
1955 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001956
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001957 switch (o->kind) {
1958 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001959 result = PyType_GenericNew(Module_type, NULL, NULL);
1960 if (!result) goto failed;
1961 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1962 if (!value) goto failed;
1963 if (PyObject_SetAttrString(result, "body", value) == -1)
1964 goto failed;
1965 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 break;
1967 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "body", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Expression_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_expr(o->v.Expression.body);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "body", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(Suite_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "body", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001993 break;
1994 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001995 return result;
1996failed:
1997 Py_XDECREF(value);
1998 Py_XDECREF(result);
1999 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002000}
2001
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002002PyObject*
2003ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002004{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002005 stmt_ty o = (stmt_ty)_o;
2006 PyObject *result = NULL, *value = NULL;
2007 if (!o) {
2008 Py_INCREF(Py_None);
2009 return Py_None;
2010 }
2011
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002012 switch (o->kind) {
2013 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002014 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2015 if (!result) goto failed;
2016 value = ast2obj_identifier(o->v.FunctionDef.name);
2017 if (!value) goto failed;
2018 if (PyObject_SetAttrString(result, "name", value) == -1)
2019 goto failed;
2020 Py_DECREF(value);
2021 value = ast2obj_arguments(o->v.FunctionDef.args);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "args", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
2026 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "body", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002031 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2032 ast2obj_expr);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002033 if (!value) goto failed;
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002034 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2035 -1)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002036 goto failed;
2037 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002038 value = ast2obj_expr(o->v.FunctionDef.returns);
2039 if (!value) goto failed;
2040 if (PyObject_SetAttrString(result, "returns", value) == -1)
2041 goto failed;
2042 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002043 break;
2044 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002045 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2046 if (!result) goto failed;
2047 value = ast2obj_identifier(o->v.ClassDef.name);
2048 if (!value) goto failed;
2049 if (PyObject_SetAttrString(result, "name", value) == -1)
2050 goto failed;
2051 Py_DECREF(value);
2052 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2053 if (!value) goto failed;
2054 if (PyObject_SetAttrString(result, "bases", value) == -1)
2055 goto failed;
2056 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002057 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2058 if (!value) goto failed;
2059 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2060 goto failed;
2061 Py_DECREF(value);
2062 value = ast2obj_expr(o->v.ClassDef.starargs);
2063 if (!value) goto failed;
2064 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2065 goto failed;
2066 Py_DECREF(value);
2067 value = ast2obj_expr(o->v.ClassDef.kwargs);
2068 if (!value) goto failed;
2069 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2070 goto failed;
2071 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002072 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2073 if (!value) goto failed;
2074 if (PyObject_SetAttrString(result, "body", value) == -1)
2075 goto failed;
2076 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002077 value = ast2obj_list(o->v.ClassDef.decorator_list,
2078 ast2obj_expr);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2081 -1)
2082 goto failed;
2083 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002084 break;
2085 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002086 result = PyType_GenericNew(Return_type, NULL, NULL);
2087 if (!result) goto failed;
2088 value = ast2obj_expr(o->v.Return.value);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "value", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002093 break;
2094 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002095 result = PyType_GenericNew(Delete_type, NULL, NULL);
2096 if (!result) goto failed;
2097 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2098 if (!value) goto failed;
2099 if (PyObject_SetAttrString(result, "targets", value) == -1)
2100 goto failed;
2101 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002102 break;
2103 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002104 result = PyType_GenericNew(Assign_type, NULL, NULL);
2105 if (!result) goto failed;
2106 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "targets", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_expr(o->v.Assign.value);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "value", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002116 break;
2117 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002118 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2119 if (!result) goto failed;
2120 value = ast2obj_expr(o->v.AugAssign.target);
2121 if (!value) goto failed;
2122 if (PyObject_SetAttrString(result, "target", value) == -1)
2123 goto failed;
2124 Py_DECREF(value);
2125 value = ast2obj_operator(o->v.AugAssign.op);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "op", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_expr(o->v.AugAssign.value);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "value", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002135 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002136 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002137 result = PyType_GenericNew(For_type, NULL, NULL);
2138 if (!result) goto failed;
2139 value = ast2obj_expr(o->v.For.target);
2140 if (!value) goto failed;
2141 if (PyObject_SetAttrString(result, "target", value) == -1)
2142 goto failed;
2143 Py_DECREF(value);
2144 value = ast2obj_expr(o->v.For.iter);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "iter", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "body", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002159 break;
2160 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002161 result = PyType_GenericNew(While_type, NULL, NULL);
2162 if (!result) goto failed;
2163 value = ast2obj_expr(o->v.While.test);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "test", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "body", value) == -1)
2171 goto failed;
2172 Py_DECREF(value);
2173 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2174 if (!value) goto failed;
2175 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2176 goto failed;
2177 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002178 break;
2179 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002180 result = PyType_GenericNew(If_type, NULL, NULL);
2181 if (!result) goto failed;
2182 value = ast2obj_expr(o->v.If.test);
2183 if (!value) goto failed;
2184 if (PyObject_SetAttrString(result, "test", value) == -1)
2185 goto failed;
2186 Py_DECREF(value);
2187 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2188 if (!value) goto failed;
2189 if (PyObject_SetAttrString(result, "body", value) == -1)
2190 goto failed;
2191 Py_DECREF(value);
2192 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2193 if (!value) goto failed;
2194 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2195 goto failed;
2196 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002197 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002198 case With_kind:
2199 result = PyType_GenericNew(With_type, NULL, NULL);
2200 if (!result) goto failed;
2201 value = ast2obj_expr(o->v.With.context_expr);
2202 if (!value) goto failed;
2203 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2204 goto failed;
2205 Py_DECREF(value);
2206 value = ast2obj_expr(o->v.With.optional_vars);
2207 if (!value) goto failed;
2208 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2209 -1)
2210 goto failed;
2211 Py_DECREF(value);
2212 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2213 if (!value) goto failed;
2214 if (PyObject_SetAttrString(result, "body", value) == -1)
2215 goto failed;
2216 Py_DECREF(value);
2217 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002219 result = PyType_GenericNew(Raise_type, NULL, NULL);
2220 if (!result) goto failed;
Collin Winter828f04a2007-08-31 00:04:24 +00002221 value = ast2obj_expr(o->v.Raise.exc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002222 if (!value) goto failed;
Collin Winter828f04a2007-08-31 00:04:24 +00002223 if (PyObject_SetAttrString(result, "exc", value) == -1)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002224 goto failed;
2225 Py_DECREF(value);
Collin Winter828f04a2007-08-31 00:04:24 +00002226 value = ast2obj_expr(o->v.Raise.cause);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002227 if (!value) goto failed;
Collin Winter828f04a2007-08-31 00:04:24 +00002228 if (PyObject_SetAttrString(result, "cause", value) == -1)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002229 goto failed;
2230 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002231 break;
2232 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002233 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2234 if (!result) goto failed;
2235 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2236 if (!value) goto failed;
2237 if (PyObject_SetAttrString(result, "body", value) == -1)
2238 goto failed;
2239 Py_DECREF(value);
2240 value = ast2obj_list(o->v.TryExcept.handlers,
2241 ast2obj_excepthandler);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
2246 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2249 goto failed;
2250 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 break;
2252 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002253 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "body", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
2260 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2261 if (!value) goto failed;
2262 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2263 goto failed;
2264 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002265 break;
2266 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002267 result = PyType_GenericNew(Assert_type, NULL, NULL);
2268 if (!result) goto failed;
2269 value = ast2obj_expr(o->v.Assert.test);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "test", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
2274 value = ast2obj_expr(o->v.Assert.msg);
2275 if (!value) goto failed;
2276 if (PyObject_SetAttrString(result, "msg", value) == -1)
2277 goto failed;
2278 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002279 break;
2280 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002281 result = PyType_GenericNew(Import_type, NULL, NULL);
2282 if (!result) goto failed;
2283 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "names", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288 break;
2289 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002290 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2291 if (!result) goto failed;
2292 value = ast2obj_identifier(o->v.ImportFrom.module);
2293 if (!value) goto failed;
2294 if (PyObject_SetAttrString(result, "module", value) == -1)
2295 goto failed;
2296 Py_DECREF(value);
2297 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "names", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002302 value = ast2obj_int(o->v.ImportFrom.level);
2303 if (!value) goto failed;
2304 if (PyObject_SetAttrString(result, "level", value) == -1)
2305 goto failed;
2306 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002307 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002308 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002309 result = PyType_GenericNew(Global_type, NULL, NULL);
2310 if (!result) goto failed;
2311 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2312 if (!value) goto failed;
2313 if (PyObject_SetAttrString(result, "names", value) == -1)
2314 goto failed;
2315 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002316 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002317 case Nonlocal_kind:
2318 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2319 if (!result) goto failed;
2320 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2321 if (!value) goto failed;
2322 if (PyObject_SetAttrString(result, "names", value) == -1)
2323 goto failed;
2324 Py_DECREF(value);
2325 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002326 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002327 result = PyType_GenericNew(Expr_type, NULL, NULL);
2328 if (!result) goto failed;
2329 value = ast2obj_expr(o->v.Expr.value);
2330 if (!value) goto failed;
2331 if (PyObject_SetAttrString(result, "value", value) == -1)
2332 goto failed;
2333 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002334 break;
2335 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002336 result = PyType_GenericNew(Pass_type, NULL, NULL);
2337 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002338 break;
2339 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002340 result = PyType_GenericNew(Break_type, NULL, NULL);
2341 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342 break;
2343 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 result = PyType_GenericNew(Continue_type, NULL, NULL);
2345 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346 break;
2347 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002348 value = ast2obj_int(o->lineno);
2349 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002350 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2351 goto failed;
2352 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002353 value = ast2obj_int(o->col_offset);
2354 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002355 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2356 goto failed;
2357 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358 return result;
2359failed:
2360 Py_XDECREF(value);
2361 Py_XDECREF(result);
2362 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002363}
2364
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002365PyObject*
2366ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002367{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002368 expr_ty o = (expr_ty)_o;
2369 PyObject *result = NULL, *value = NULL;
2370 if (!o) {
2371 Py_INCREF(Py_None);
2372 return Py_None;
2373 }
2374
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375 switch (o->kind) {
2376 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002377 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2378 if (!result) goto failed;
2379 value = ast2obj_boolop(o->v.BoolOp.op);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "op", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "values", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002389 break;
2390 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002391 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2392 if (!result) goto failed;
2393 value = ast2obj_expr(o->v.BinOp.left);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "left", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
2398 value = ast2obj_operator(o->v.BinOp.op);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "op", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 value = ast2obj_expr(o->v.BinOp.right);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "right", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002408 break;
2409 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_unaryop(o->v.UnaryOp.op);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "op", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 value = ast2obj_expr(o->v.UnaryOp.operand);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "operand", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002422 break;
2423 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002424 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2425 if (!result) goto failed;
2426 value = ast2obj_arguments(o->v.Lambda.args);
2427 if (!value) goto failed;
2428 if (PyObject_SetAttrString(result, "args", value) == -1)
2429 goto failed;
2430 Py_DECREF(value);
2431 value = ast2obj_expr(o->v.Lambda.body);
2432 if (!value) goto failed;
2433 if (PyObject_SetAttrString(result, "body", value) == -1)
2434 goto failed;
2435 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002437 case IfExp_kind:
2438 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2439 if (!result) goto failed;
2440 value = ast2obj_expr(o->v.IfExp.test);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "test", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
2445 value = ast2obj_expr(o->v.IfExp.body);
2446 if (!value) goto failed;
2447 if (PyObject_SetAttrString(result, "body", value) == -1)
2448 goto failed;
2449 Py_DECREF(value);
2450 value = ast2obj_expr(o->v.IfExp.orelse);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
2455 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002456 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002457 result = PyType_GenericNew(Dict_type, NULL, NULL);
2458 if (!result) goto failed;
2459 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2460 if (!value) goto failed;
2461 if (PyObject_SetAttrString(result, "keys", value) == -1)
2462 goto failed;
2463 Py_DECREF(value);
2464 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2465 if (!value) goto failed;
2466 if (PyObject_SetAttrString(result, "values", value) == -1)
2467 goto failed;
2468 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002469 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002470 case Set_kind:
2471 result = PyType_GenericNew(Set_type, NULL, NULL);
2472 if (!result) goto failed;
2473 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2474 if (!value) goto failed;
2475 if (PyObject_SetAttrString(result, "elts", value) == -1)
2476 goto failed;
2477 Py_DECREF(value);
2478 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002480 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2481 if (!result) goto failed;
2482 value = ast2obj_expr(o->v.ListComp.elt);
2483 if (!value) goto failed;
2484 if (PyObject_SetAttrString(result, "elt", value) == -1)
2485 goto failed;
2486 Py_DECREF(value);
2487 value = ast2obj_list(o->v.ListComp.generators,
2488 ast2obj_comprehension);
2489 if (!value) goto failed;
2490 if (PyObject_SetAttrString(result, "generators", value) == -1)
2491 goto failed;
2492 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002493 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002494 case SetComp_kind:
2495 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2496 if (!result) goto failed;
2497 value = ast2obj_expr(o->v.SetComp.elt);
2498 if (!value) goto failed;
2499 if (PyObject_SetAttrString(result, "elt", value) == -1)
2500 goto failed;
2501 Py_DECREF(value);
2502 value = ast2obj_list(o->v.SetComp.generators,
2503 ast2obj_comprehension);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "generators", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
2508 break;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002509 case DictComp_kind:
2510 result = PyType_GenericNew(DictComp_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_expr(o->v.DictComp.key);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "key", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
2517 value = ast2obj_expr(o->v.DictComp.value);
2518 if (!value) goto failed;
2519 if (PyObject_SetAttrString(result, "value", value) == -1)
2520 goto failed;
2521 Py_DECREF(value);
2522 value = ast2obj_list(o->v.DictComp.generators,
2523 ast2obj_comprehension);
2524 if (!value) goto failed;
2525 if (PyObject_SetAttrString(result, "generators", value) == -1)
2526 goto failed;
2527 Py_DECREF(value);
2528 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002529 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002530 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2531 if (!result) goto failed;
2532 value = ast2obj_expr(o->v.GeneratorExp.elt);
2533 if (!value) goto failed;
2534 if (PyObject_SetAttrString(result, "elt", value) == -1)
2535 goto failed;
2536 Py_DECREF(value);
2537 value = ast2obj_list(o->v.GeneratorExp.generators,
2538 ast2obj_comprehension);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "generators", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002543 break;
2544 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002545 result = PyType_GenericNew(Yield_type, NULL, NULL);
2546 if (!result) goto failed;
2547 value = ast2obj_expr(o->v.Yield.value);
2548 if (!value) goto failed;
2549 if (PyObject_SetAttrString(result, "value", value) == -1)
2550 goto failed;
2551 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002552 break;
2553 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002554 result = PyType_GenericNew(Compare_type, NULL, NULL);
2555 if (!result) goto failed;
2556 value = ast2obj_expr(o->v.Compare.left);
2557 if (!value) goto failed;
2558 if (PyObject_SetAttrString(result, "left", value) == -1)
2559 goto failed;
2560 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002561 {
2562 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2563 value = PyList_New(n);
2564 if (!value) goto failed;
2565 for(i = 0; i < n; i++)
2566 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2567 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002568 if (!value) goto failed;
2569 if (PyObject_SetAttrString(result, "ops", value) == -1)
2570 goto failed;
2571 Py_DECREF(value);
2572 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2573 if (!value) goto failed;
2574 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2575 goto failed;
2576 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002577 break;
2578 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002579 result = PyType_GenericNew(Call_type, NULL, NULL);
2580 if (!result) goto failed;
2581 value = ast2obj_expr(o->v.Call.func);
2582 if (!value) goto failed;
2583 if (PyObject_SetAttrString(result, "func", value) == -1)
2584 goto failed;
2585 Py_DECREF(value);
2586 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2587 if (!value) goto failed;
2588 if (PyObject_SetAttrString(result, "args", value) == -1)
2589 goto failed;
2590 Py_DECREF(value);
2591 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2592 if (!value) goto failed;
2593 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2594 goto failed;
2595 Py_DECREF(value);
2596 value = ast2obj_expr(o->v.Call.starargs);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 value = ast2obj_expr(o->v.Call.kwargs);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002607 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002608 result = PyType_GenericNew(Num_type, NULL, NULL);
2609 if (!result) goto failed;
2610 value = ast2obj_object(o->v.Num.n);
2611 if (!value) goto failed;
2612 if (PyObject_SetAttrString(result, "n", value) == -1)
2613 goto failed;
2614 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002615 break;
2616 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002617 result = PyType_GenericNew(Str_type, NULL, NULL);
2618 if (!result) goto failed;
2619 value = ast2obj_string(o->v.Str.s);
2620 if (!value) goto failed;
2621 if (PyObject_SetAttrString(result, "s", value) == -1)
2622 goto failed;
2623 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002624 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002625 case Bytes_kind:
2626 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2627 if (!result) goto failed;
2628 value = ast2obj_string(o->v.Bytes.s);
2629 if (!value) goto failed;
2630 if (PyObject_SetAttrString(result, "s", value) == -1)
2631 goto failed;
2632 Py_DECREF(value);
2633 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002634 case Ellipsis_kind:
2635 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2636 if (!result) goto failed;
2637 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002638 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002639 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2640 if (!result) goto failed;
2641 value = ast2obj_expr(o->v.Attribute.value);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "value", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
2646 value = ast2obj_identifier(o->v.Attribute.attr);
2647 if (!value) goto failed;
2648 if (PyObject_SetAttrString(result, "attr", value) == -1)
2649 goto failed;
2650 Py_DECREF(value);
2651 value = ast2obj_expr_context(o->v.Attribute.ctx);
2652 if (!value) goto failed;
2653 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2654 goto failed;
2655 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656 break;
2657 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2659 if (!result) goto failed;
2660 value = ast2obj_expr(o->v.Subscript.value);
2661 if (!value) goto failed;
2662 if (PyObject_SetAttrString(result, "value", value) == -1)
2663 goto failed;
2664 Py_DECREF(value);
2665 value = ast2obj_slice(o->v.Subscript.slice);
2666 if (!value) goto failed;
2667 if (PyObject_SetAttrString(result, "slice", value) == -1)
2668 goto failed;
2669 Py_DECREF(value);
2670 value = ast2obj_expr_context(o->v.Subscript.ctx);
2671 if (!value) goto failed;
2672 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2673 goto failed;
2674 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002675 break;
Guido van Rossum0368b722007-05-11 16:50:42 +00002676 case Starred_kind:
2677 result = PyType_GenericNew(Starred_type, NULL, NULL);
2678 if (!result) goto failed;
2679 value = ast2obj_expr(o->v.Starred.value);
2680 if (!value) goto failed;
2681 if (PyObject_SetAttrString(result, "value", value) == -1)
2682 goto failed;
2683 Py_DECREF(value);
2684 value = ast2obj_expr_context(o->v.Starred.ctx);
2685 if (!value) goto failed;
2686 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2687 goto failed;
2688 Py_DECREF(value);
2689 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691 result = PyType_GenericNew(Name_type, NULL, NULL);
2692 if (!result) goto failed;
2693 value = ast2obj_identifier(o->v.Name.id);
2694 if (!value) goto failed;
2695 if (PyObject_SetAttrString(result, "id", value) == -1)
2696 goto failed;
2697 Py_DECREF(value);
2698 value = ast2obj_expr_context(o->v.Name.ctx);
2699 if (!value) goto failed;
2700 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2701 goto failed;
2702 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002703 break;
2704 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002705 result = PyType_GenericNew(List_type, NULL, NULL);
2706 if (!result) goto failed;
2707 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2708 if (!value) goto failed;
2709 if (PyObject_SetAttrString(result, "elts", value) == -1)
2710 goto failed;
2711 Py_DECREF(value);
2712 value = ast2obj_expr_context(o->v.List.ctx);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717 break;
2718 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002719 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2720 if (!result) goto failed;
2721 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2722 if (!value) goto failed;
2723 if (PyObject_SetAttrString(result, "elts", value) == -1)
2724 goto failed;
2725 Py_DECREF(value);
2726 value = ast2obj_expr_context(o->v.Tuple.ctx);
2727 if (!value) goto failed;
2728 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2729 goto failed;
2730 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002731 break;
2732 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002733 value = ast2obj_int(o->lineno);
2734 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002735 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2736 goto failed;
2737 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002738 value = ast2obj_int(o->col_offset);
2739 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002740 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2741 goto failed;
2742 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002743 return result;
2744failed:
2745 Py_XDECREF(value);
2746 Py_XDECREF(result);
2747 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002748}
2749
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002750PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002751{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002752 switch(o) {
2753 case Load:
2754 Py_INCREF(Load_singleton);
2755 return Load_singleton;
2756 case Store:
2757 Py_INCREF(Store_singleton);
2758 return Store_singleton;
2759 case Del:
2760 Py_INCREF(Del_singleton);
2761 return Del_singleton;
2762 case AugLoad:
2763 Py_INCREF(AugLoad_singleton);
2764 return AugLoad_singleton;
2765 case AugStore:
2766 Py_INCREF(AugStore_singleton);
2767 return AugStore_singleton;
2768 case Param:
2769 Py_INCREF(Param_singleton);
2770 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002771 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002772 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002773}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002774PyObject*
2775ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002776{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002777 slice_ty o = (slice_ty)_o;
2778 PyObject *result = NULL, *value = NULL;
2779 if (!o) {
2780 Py_INCREF(Py_None);
2781 return Py_None;
2782 }
2783
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002784 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002785 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002786 result = PyType_GenericNew(Slice_type, NULL, NULL);
2787 if (!result) goto failed;
2788 value = ast2obj_expr(o->v.Slice.lower);
2789 if (!value) goto failed;
2790 if (PyObject_SetAttrString(result, "lower", value) == -1)
2791 goto failed;
2792 Py_DECREF(value);
2793 value = ast2obj_expr(o->v.Slice.upper);
2794 if (!value) goto failed;
2795 if (PyObject_SetAttrString(result, "upper", value) == -1)
2796 goto failed;
2797 Py_DECREF(value);
2798 value = ast2obj_expr(o->v.Slice.step);
2799 if (!value) goto failed;
2800 if (PyObject_SetAttrString(result, "step", value) == -1)
2801 goto failed;
2802 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002803 break;
2804 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002805 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2806 if (!result) goto failed;
2807 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2808 if (!value) goto failed;
2809 if (PyObject_SetAttrString(result, "dims", value) == -1)
2810 goto failed;
2811 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002812 break;
2813 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002814 result = PyType_GenericNew(Index_type, NULL, NULL);
2815 if (!result) goto failed;
2816 value = ast2obj_expr(o->v.Index.value);
2817 if (!value) goto failed;
2818 if (PyObject_SetAttrString(result, "value", value) == -1)
2819 goto failed;
2820 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002821 break;
2822 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002823 return result;
2824failed:
2825 Py_XDECREF(value);
2826 Py_XDECREF(result);
2827 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002828}
2829
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002830PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002831{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002832 switch(o) {
2833 case And:
2834 Py_INCREF(And_singleton);
2835 return And_singleton;
2836 case Or:
2837 Py_INCREF(Or_singleton);
2838 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002839 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002840 return NULL; /* cannot happen */
2841}
2842PyObject* ast2obj_operator(operator_ty o)
2843{
2844 switch(o) {
2845 case Add:
2846 Py_INCREF(Add_singleton);
2847 return Add_singleton;
2848 case Sub:
2849 Py_INCREF(Sub_singleton);
2850 return Sub_singleton;
2851 case Mult:
2852 Py_INCREF(Mult_singleton);
2853 return Mult_singleton;
2854 case Div:
2855 Py_INCREF(Div_singleton);
2856 return Div_singleton;
2857 case Mod:
2858 Py_INCREF(Mod_singleton);
2859 return Mod_singleton;
2860 case Pow:
2861 Py_INCREF(Pow_singleton);
2862 return Pow_singleton;
2863 case LShift:
2864 Py_INCREF(LShift_singleton);
2865 return LShift_singleton;
2866 case RShift:
2867 Py_INCREF(RShift_singleton);
2868 return RShift_singleton;
2869 case BitOr:
2870 Py_INCREF(BitOr_singleton);
2871 return BitOr_singleton;
2872 case BitXor:
2873 Py_INCREF(BitXor_singleton);
2874 return BitXor_singleton;
2875 case BitAnd:
2876 Py_INCREF(BitAnd_singleton);
2877 return BitAnd_singleton;
2878 case FloorDiv:
2879 Py_INCREF(FloorDiv_singleton);
2880 return FloorDiv_singleton;
2881 }
2882 return NULL; /* cannot happen */
2883}
2884PyObject* ast2obj_unaryop(unaryop_ty o)
2885{
2886 switch(o) {
2887 case Invert:
2888 Py_INCREF(Invert_singleton);
2889 return Invert_singleton;
2890 case Not:
2891 Py_INCREF(Not_singleton);
2892 return Not_singleton;
2893 case UAdd:
2894 Py_INCREF(UAdd_singleton);
2895 return UAdd_singleton;
2896 case USub:
2897 Py_INCREF(USub_singleton);
2898 return USub_singleton;
2899 }
2900 return NULL; /* cannot happen */
2901}
2902PyObject* ast2obj_cmpop(cmpop_ty o)
2903{
2904 switch(o) {
2905 case Eq:
2906 Py_INCREF(Eq_singleton);
2907 return Eq_singleton;
2908 case NotEq:
2909 Py_INCREF(NotEq_singleton);
2910 return NotEq_singleton;
2911 case Lt:
2912 Py_INCREF(Lt_singleton);
2913 return Lt_singleton;
2914 case LtE:
2915 Py_INCREF(LtE_singleton);
2916 return LtE_singleton;
2917 case Gt:
2918 Py_INCREF(Gt_singleton);
2919 return Gt_singleton;
2920 case GtE:
2921 Py_INCREF(GtE_singleton);
2922 return GtE_singleton;
2923 case Is:
2924 Py_INCREF(Is_singleton);
2925 return Is_singleton;
2926 case IsNot:
2927 Py_INCREF(IsNot_singleton);
2928 return IsNot_singleton;
2929 case In:
2930 Py_INCREF(In_singleton);
2931 return In_singleton;
2932 case NotIn:
2933 Py_INCREF(NotIn_singleton);
2934 return NotIn_singleton;
2935 }
2936 return NULL; /* cannot happen */
2937}
2938PyObject*
2939ast2obj_comprehension(void* _o)
2940{
2941 comprehension_ty o = (comprehension_ty)_o;
2942 PyObject *result = NULL, *value = NULL;
2943 if (!o) {
2944 Py_INCREF(Py_None);
2945 return Py_None;
2946 }
2947
2948 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2949 if (!result) return NULL;
2950 value = ast2obj_expr(o->target);
2951 if (!value) goto failed;
2952 if (PyObject_SetAttrString(result, "target", value) == -1)
2953 goto failed;
2954 Py_DECREF(value);
2955 value = ast2obj_expr(o->iter);
2956 if (!value) goto failed;
2957 if (PyObject_SetAttrString(result, "iter", value) == -1)
2958 goto failed;
2959 Py_DECREF(value);
2960 value = ast2obj_list(o->ifs, ast2obj_expr);
2961 if (!value) goto failed;
2962 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2963 goto failed;
2964 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002965 return result;
2966failed:
2967 Py_XDECREF(value);
2968 Py_XDECREF(result);
2969 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002970}
2971
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002972PyObject*
2973ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002974{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002975 excepthandler_ty o = (excepthandler_ty)_o;
2976 PyObject *result = NULL, *value = NULL;
2977 if (!o) {
2978 Py_INCREF(Py_None);
2979 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002980 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002981
2982 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2983 if (!result) return NULL;
2984 value = ast2obj_expr(o->type);
2985 if (!value) goto failed;
2986 if (PyObject_SetAttrString(result, "type", value) == -1)
2987 goto failed;
2988 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002989 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002990 if (!value) goto failed;
2991 if (PyObject_SetAttrString(result, "name", value) == -1)
2992 goto failed;
2993 Py_DECREF(value);
2994 value = ast2obj_list(o->body, ast2obj_stmt);
2995 if (!value) goto failed;
2996 if (PyObject_SetAttrString(result, "body", value) == -1)
2997 goto failed;
2998 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002999 value = ast2obj_int(o->lineno);
3000 if (!value) goto failed;
3001 if (PyObject_SetAttrString(result, "lineno", value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
3004 value = ast2obj_int(o->col_offset);
3005 if (!value) goto failed;
3006 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
3007 goto failed;
3008 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003009 return result;
3010failed:
3011 Py_XDECREF(value);
3012 Py_XDECREF(result);
3013 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003014}
3015
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003016PyObject*
3017ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003018{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003019 arguments_ty o = (arguments_ty)_o;
3020 PyObject *result = NULL, *value = NULL;
3021 if (!o) {
3022 Py_INCREF(Py_None);
3023 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003024 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003025
3026 result = PyType_GenericNew(arguments_type, NULL, NULL);
3027 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00003028 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003029 if (!value) goto failed;
3030 if (PyObject_SetAttrString(result, "args", value) == -1)
3031 goto failed;
3032 Py_DECREF(value);
3033 value = ast2obj_identifier(o->vararg);
3034 if (!value) goto failed;
3035 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3036 goto failed;
3037 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003038 value = ast2obj_expr(o->varargannotation);
3039 if (!value) goto failed;
3040 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
3041 goto failed;
3042 Py_DECREF(value);
3043 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003044 if (!value) goto failed;
3045 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
3046 goto failed;
3047 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003048 value = ast2obj_identifier(o->kwarg);
3049 if (!value) goto failed;
3050 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3051 goto failed;
3052 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003053 value = ast2obj_expr(o->kwargannotation);
3054 if (!value) goto failed;
3055 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
3056 goto failed;
3057 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003058 value = ast2obj_list(o->defaults, ast2obj_expr);
3059 if (!value) goto failed;
3060 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3061 goto failed;
3062 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003063 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3064 if (!value) goto failed;
3065 if (PyObject_SetAttrString(result, "kw_defaults", 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*
Neal Norwitzc1505362006-12-28 06:47:50 +00003076ast2obj_arg(void* _o)
3077{
3078 arg_ty o = (arg_ty)_o;
3079 PyObject *result = NULL, *value = NULL;
3080 if (!o) {
3081 Py_INCREF(Py_None);
3082 return Py_None;
3083 }
3084
Guido van Rossum1bc535d2007-05-15 18:46:22 +00003085 result = PyType_GenericNew(arg_type, NULL, NULL);
3086 if (!result) return NULL;
3087 value = ast2obj_identifier(o->arg);
3088 if (!value) goto failed;
3089 if (PyObject_SetAttrString(result, "arg", value) == -1)
3090 goto failed;
3091 Py_DECREF(value);
3092 value = ast2obj_expr(o->annotation);
3093 if (!value) goto failed;
3094 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3095 goto failed;
3096 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003097 return result;
3098failed:
3099 Py_XDECREF(value);
3100 Py_XDECREF(result);
3101 return NULL;
3102}
3103
3104PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003105ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003106{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003107 keyword_ty o = (keyword_ty)_o;
3108 PyObject *result = NULL, *value = NULL;
3109 if (!o) {
3110 Py_INCREF(Py_None);
3111 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003112 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003113
3114 result = PyType_GenericNew(keyword_type, NULL, NULL);
3115 if (!result) return NULL;
3116 value = ast2obj_identifier(o->arg);
3117 if (!value) goto failed;
3118 if (PyObject_SetAttrString(result, "arg", value) == -1)
3119 goto failed;
3120 Py_DECREF(value);
3121 value = ast2obj_expr(o->value);
3122 if (!value) goto failed;
3123 if (PyObject_SetAttrString(result, "value", value) == -1)
3124 goto failed;
3125 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003126 return result;
3127failed:
3128 Py_XDECREF(value);
3129 Py_XDECREF(result);
3130 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003131}
3132
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003133PyObject*
3134ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003135{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003136 alias_ty o = (alias_ty)_o;
3137 PyObject *result = NULL, *value = NULL;
3138 if (!o) {
3139 Py_INCREF(Py_None);
3140 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003141 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003142
3143 result = PyType_GenericNew(alias_type, NULL, NULL);
3144 if (!result) return NULL;
3145 value = ast2obj_identifier(o->name);
3146 if (!value) goto failed;
3147 if (PyObject_SetAttrString(result, "name", value) == -1)
3148 goto failed;
3149 Py_DECREF(value);
3150 value = ast2obj_identifier(o->asname);
3151 if (!value) goto failed;
3152 if (PyObject_SetAttrString(result, "asname", value) == -1)
3153 goto failed;
3154 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003155 return result;
3156failed:
3157 Py_XDECREF(value);
3158 Py_XDECREF(result);
3159 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160}
3161
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003162
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003163PyMODINIT_FUNC
3164init_ast(void)
3165{
3166 PyObject *m, *d;
3167 if (!init_types()) return;
3168 m = Py_InitModule3("_ast", NULL, NULL);
3169 if (!m) return;
3170 d = PyModule_GetDict(m);
3171 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3172 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3173 return;
Guido van Rossum71d4a342007-08-31 04:03:25 +00003174 if (PyModule_AddStringConstant(m, "__version__", "57783") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003175 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003176 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3177 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3178 return;
3179 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3180 < 0) return;
3181 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3182 0) return;
3183 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3184 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3185 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3186 < 0) return;
3187 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3188 return;
3189 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3190 return;
3191 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3192 return;
3193 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3194 return;
3195 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3196 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003197 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3198 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3199 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3200 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3201 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3202 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3203 0) return;
3204 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3205 0) return;
3206 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3207 return;
3208 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3209 return;
3210 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3211 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003212 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3213 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003214 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3215 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003216 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3217 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3218 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3219 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3220 return;
3221 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3222 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3223 return;
3224 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3225 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3226 return;
3227 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3228 return;
3229 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3230 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003231 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003232 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3233 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003234 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3235 return;
Guido van Rossum992d4a32007-07-11 13:09:30 +00003236 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
3237 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003238 if (PyDict_SetItemString(d, "GeneratorExp",
3239 (PyObject*)GeneratorExp_type) < 0) return;
3240 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3241 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3242 return;
3243 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003244 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3245 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003246 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003247 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3248 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003249 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3250 0) return;
3251 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3252 0) return;
Guido van Rossum0368b722007-05-11 16:50:42 +00003253 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
3254 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003255 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3256 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3257 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3258 if (PyDict_SetItemString(d, "expr_context",
3259 (PyObject*)expr_context_type) < 0) return;
3260 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3261 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3262 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3263 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3264 return;
3265 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3266 return;
3267 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3268 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003269 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3270 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3271 return;
3272 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3273 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3274 return;
3275 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3276 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3277 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3278 return;
3279 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3280 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3281 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3282 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3283 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3284 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3285 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3286 return;
3287 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3288 return;
3289 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3290 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3291 return;
3292 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3293 return;
3294 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3295 return;
3296 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3297 return;
3298 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3299 return;
3300 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3301 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3302 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3303 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3304 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3305 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3306 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3307 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3308 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3309 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3310 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3311 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3312 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3313 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3314 if (PyDict_SetItemString(d, "comprehension",
3315 (PyObject*)comprehension_type) < 0) return;
3316 if (PyDict_SetItemString(d, "excepthandler",
3317 (PyObject*)excepthandler_type) < 0) return;
3318 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3319 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003320 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003321 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3322 return;
3323 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003324}
3325
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003326
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003327PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003328{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003329 init_types();
3330 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003331}
Martin v. Löwis5b222132007-06-10 09:51:05 +00003332
3333