blob: 605a152ca9702c4f09ff4c18bd32b171c05915bb [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossumc3e7ffc2007-07-11 20:56:15 +00005 __version__ 56266.
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[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000104 "type",
105 "inst",
106 "tback",
107};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000108static PyTypeObject *TryExcept_type;
109static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000110 "body",
111 "handlers",
112 "orelse",
113};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000114static PyTypeObject *TryFinally_type;
115static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000116 "body",
117 "finalbody",
118};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000119static PyTypeObject *Assert_type;
120static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000121 "test",
122 "msg",
123};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000124static PyTypeObject *Import_type;
125static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000126 "names",
127};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000128static PyTypeObject *ImportFrom_type;
129static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000130 "module",
131 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000132 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000133};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000134static PyTypeObject *Global_type;
135static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000136 "names",
137};
Jeremy Hylton81e95022007-02-27 06:50:52 +0000138static PyTypeObject *Nonlocal_type;
139static char *Nonlocal_fields[]={
140 "names",
141};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000142static PyTypeObject *Expr_type;
143static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000144 "value",
145};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000146static PyTypeObject *Pass_type;
147static PyTypeObject *Break_type;
148static PyTypeObject *Continue_type;
149static PyTypeObject *expr_type;
150static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000151 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000152 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000153};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000154static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000155static PyTypeObject *BoolOp_type;
156static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000157 "op",
158 "values",
159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *BinOp_type;
161static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000162 "left",
163 "op",
164 "right",
165};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000166static PyTypeObject *UnaryOp_type;
167static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000168 "op",
169 "operand",
170};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000171static PyTypeObject *Lambda_type;
172static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000173 "args",
174 "body",
175};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000176static PyTypeObject *IfExp_type;
177static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000178 "test",
179 "body",
180 "orelse",
181};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000182static PyTypeObject *Dict_type;
183static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000184 "keys",
185 "values",
186};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000187static PyTypeObject *Set_type;
188static char *Set_fields[]={
189 "elts",
190};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000191static PyTypeObject *ListComp_type;
192static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000193 "elt",
194 "generators",
195};
Nick Coghlan650f0d02007-04-15 12:05:43 +0000196static PyTypeObject *SetComp_type;
197static char *SetComp_fields[]={
198 "elt",
199 "generators",
200};
Guido van Rossum992d4a32007-07-11 13:09:30 +0000201static PyTypeObject *DictComp_type;
202static char *DictComp_fields[]={
203 "key",
204 "value",
205 "generators",
206};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000207static PyTypeObject *GeneratorExp_type;
208static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000209 "elt",
210 "generators",
211};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000212static PyTypeObject *Yield_type;
213static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000214 "value",
215};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000216static PyTypeObject *Compare_type;
217static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000218 "left",
219 "ops",
220 "comparators",
221};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000222static PyTypeObject *Call_type;
223static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000224 "func",
225 "args",
226 "keywords",
227 "starargs",
228 "kwargs",
229};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000230static PyTypeObject *Num_type;
231static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000232 "n",
233};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000234static PyTypeObject *Str_type;
235static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000236 "s",
237};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000238static PyTypeObject *Bytes_type;
239static char *Bytes_fields[]={
240 "s",
241};
Georg Brandl52318d62006-09-06 07:06:08 +0000242static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Attribute_type;
244static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "value",
246 "attr",
247 "ctx",
248};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000249static PyTypeObject *Subscript_type;
250static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000251 "value",
252 "slice",
253 "ctx",
254};
Guido van Rossum0368b722007-05-11 16:50:42 +0000255static PyTypeObject *Starred_type;
256static char *Starred_fields[]={
257 "value",
258 "ctx",
259};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000260static PyTypeObject *Name_type;
261static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000262 "id",
263 "ctx",
264};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000265static PyTypeObject *List_type;
266static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000267 "elts",
268 "ctx",
269};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000270static PyTypeObject *Tuple_type;
271static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000272 "elts",
273 "ctx",
274};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000276static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
277*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
278static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000279static PyTypeObject *Load_type;
280static PyTypeObject *Store_type;
281static PyTypeObject *Del_type;
282static PyTypeObject *AugLoad_type;
283static PyTypeObject *AugStore_type;
284static PyTypeObject *Param_type;
285static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000286static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000287static PyTypeObject *Slice_type;
288static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000289 "lower",
290 "upper",
291 "step",
292};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000293static PyTypeObject *ExtSlice_type;
294static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295 "dims",
296};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000297static PyTypeObject *Index_type;
298static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000299 "value",
300};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000301static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000302static PyObject *And_singleton, *Or_singleton;
303static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000304static PyTypeObject *And_type;
305static PyTypeObject *Or_type;
306static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000307static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
308*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
309*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
310*FloorDiv_singleton;
311static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000312static PyTypeObject *Add_type;
313static PyTypeObject *Sub_type;
314static PyTypeObject *Mult_type;
315static PyTypeObject *Div_type;
316static PyTypeObject *Mod_type;
317static PyTypeObject *Pow_type;
318static PyTypeObject *LShift_type;
319static PyTypeObject *RShift_type;
320static PyTypeObject *BitOr_type;
321static PyTypeObject *BitXor_type;
322static PyTypeObject *BitAnd_type;
323static PyTypeObject *FloorDiv_type;
324static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000325static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
326*USub_singleton;
327static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static PyTypeObject *Invert_type;
329static PyTypeObject *Not_type;
330static PyTypeObject *UAdd_type;
331static PyTypeObject *USub_type;
332static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
334*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
335*NotIn_singleton;
336static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static PyTypeObject *Eq_type;
338static PyTypeObject *NotEq_type;
339static PyTypeObject *Lt_type;
340static PyTypeObject *LtE_type;
341static PyTypeObject *Gt_type;
342static PyTypeObject *GtE_type;
343static PyTypeObject *Is_type;
344static PyTypeObject *IsNot_type;
345static PyTypeObject *In_type;
346static PyTypeObject *NotIn_type;
347static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350 "target",
351 "iter",
352 "ifs",
353};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000354static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000355static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000356static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000357 "type",
358 "name",
359 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000360 "lineno",
361 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000362};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000363static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000364static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000365static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000366 "args",
367 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000368 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000369 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000370 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000371 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000372 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000373 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000374};
Neal Norwitzc1505362006-12-28 06:47:50 +0000375static PyTypeObject *arg_type;
376static PyObject* ast2obj_arg(void*);
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000377static char *arg_fields[]={
Neal Norwitzc1505362006-12-28 06:47:50 +0000378 "arg",
379 "annotation",
380};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000381static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000382static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000383static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000384 "arg",
385 "value",
386};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000387static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000388static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000389static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000390 "name",
391 "asname",
392};
393
394
395static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
396{
397 PyObject *fnames, *result;
398 int i;
399 if (num_fields) {
400 fnames = PyTuple_New(num_fields);
401 if (!fnames) return NULL;
402 } else {
403 fnames = Py_None;
404 Py_INCREF(Py_None);
405 }
406 for(i=0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000407 PyObject *field = PyUnicode_FromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000408 if (!field) {
409 Py_DECREF(fnames);
410 return NULL;
411 }
412 PyTuple_SET_ITEM(fnames, i, field);
413 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000414 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000415 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000416 Py_DECREF(fnames);
417 return (PyTypeObject*)result;
418}
419
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000420static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
421{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000422 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000423 PyObject *s, *l = PyList_New(num_fields);
424 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000425 for(i = 0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000426 s = PyUnicode_FromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000427 if (!s) {
428 Py_DECREF(l);
429 return 0;
430 }
431 PyList_SET_ITEM(l, i, s);
432 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000433 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
434 Py_DECREF(l);
435 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000436}
437
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000438static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
439{
440 int i, n = asdl_seq_LEN(seq);
441 PyObject *result = PyList_New(n);
442 PyObject *value;
443 if (!result)
444 return NULL;
445 for (i = 0; i < n; i++) {
446 value = func(asdl_seq_GET(seq, i));
447 if (!value) {
448 Py_DECREF(result);
449 return NULL;
450 }
451 PyList_SET_ITEM(result, i, value);
452 }
453 return result;
454}
455
456static PyObject* ast2obj_object(void *o)
457{
458 if (!o)
459 o = Py_None;
460 Py_INCREF((PyObject*)o);
461 return (PyObject*)o;
462}
463#define ast2obj_identifier ast2obj_object
464#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000466static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000467{
468 return PyInt_FromLong(b);
469}
470
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471static int init_types(void)
472{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000473 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000474 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000475 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
476 mod_type = make_type("mod", AST_type, NULL, 0);
477 if (!mod_type) return 0;
478 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 Interactive_type = make_type("Interactive", mod_type,
482 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Expression_type = make_type("Expression", mod_type, Expression_fields,
485 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000487 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000488 if (!Suite_type) return 0;
489 stmt_type = make_type("stmt", AST_type, NULL, 0);
490 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000491 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000493 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!FunctionDef_type) return 0;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000495 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000510 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000511 With_type = make_type("With", stmt_type, With_fields, 3);
512 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000513 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000515 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000516 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000517 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
518 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000525 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000529 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
530 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000533 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000535 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000537 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Continue_type) return 0;
539 expr_type = make_type("expr", AST_type, NULL, 0);
540 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000541 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000550 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000554 Set_type = make_type("Set", expr_type, Set_fields, 1);
555 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000558 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
559 if (!SetComp_type) return 0;
Guido van Rossum992d4a32007-07-11 13:09:30 +0000560 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
561 if (!DictComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 GeneratorExp_type = make_type("GeneratorExp", expr_type,
563 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000564 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000565 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000567 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000569 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000571 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000573 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000575 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
576 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000577 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
578 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Subscript_type) return 0;
Guido van Rossum0368b722007-05-11 16:50:42 +0000583 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
584 if (!Starred_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000589 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!Tuple_type) return 0;
591 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
592 if (!expr_context_type) return 0;
593 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000594 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000598 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000600 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000602 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000604 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000606 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000607 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000608 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000609 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000610 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000611 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000612 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000614 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000616 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!Param_singleton) return 0;
618 slice_type = make_type("slice", AST_type, NULL, 0);
619 if (!slice_type) return 0;
620 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Index_type) return 0;
627 boolop_type = make_type("boolop", AST_type, NULL, 0);
628 if (!boolop_type) return 0;
629 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000630 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000632 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000634 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000636 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Or_singleton) return 0;
638 operator_type = make_type("operator", AST_type, NULL, 0);
639 if (!operator_type) return 0;
640 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000645 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000647 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000649 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000651 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000653 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000655 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000656 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000657 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000658 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000659 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000660 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000661 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000662 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000663 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000664 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000665 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000667 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!FloorDiv_singleton) return 0;
689 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
690 if (!unaryop_type) return 0;
691 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000692 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000694 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000696 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000698 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000700 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000704 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000706 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!USub_singleton) return 0;
708 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
709 if (!cmpop_type) return 0;
710 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000711 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000713 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000715 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000717 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000719 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000721 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000722 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000723 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000724 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000725 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000727 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000728 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000729 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000730 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000731 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000732 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000733 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000734 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000735 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000736 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000737 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000738 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000739 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000740 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000741 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000742 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000743 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000744 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000745 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000746 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000747 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000748 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000749 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000750 if (!NotIn_singleton) return 0;
751 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000752 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000753 if (!comprehension_type) return 0;
754 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000755 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000756 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000757 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000758 if (!arguments_type) return 0;
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000759 arg_type = make_type("arg", AST_type, arg_fields, 2);
Neal Norwitzc1505362006-12-28 06:47:50 +0000760 if (!arg_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000761 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
762 if (!keyword_type) return 0;
763 alias_type = make_type("alias", AST_type, alias_fields, 2);
764 if (!alias_type) return 0;
765 initialized = 1;
766 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000767}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000768
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000769mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000770Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771{
772 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000773 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000774 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000776 p->kind = Module_kind;
777 p->v.Module.body = body;
778 return p;
779}
780
781mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000782Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783{
784 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000785 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000786 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000788 p->kind = Interactive_kind;
789 p->v.Interactive.body = body;
790 return p;
791}
792
793mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000794Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000795{
796 mod_ty p;
797 if (!body) {
798 PyErr_SetString(PyExc_ValueError,
799 "field body is required for Expression");
800 return NULL;
801 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000802 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000803 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000805 p->kind = Expression_kind;
806 p->v.Expression.body = body;
807 return p;
808}
809
810mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000811Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000812{
813 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000814 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000815 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000816 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817 p->kind = Suite_kind;
818 p->v.Suite.body = body;
819 return p;
820}
821
822stmt_ty
823FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000824 decorator_list, expr_ty returns, int lineno, int col_offset,
825 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826{
827 stmt_ty p;
828 if (!name) {
829 PyErr_SetString(PyExc_ValueError,
830 "field name is required for FunctionDef");
831 return NULL;
832 }
833 if (!args) {
834 PyErr_SetString(PyExc_ValueError,
835 "field args is required for FunctionDef");
836 return NULL;
837 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000838 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000839 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 p->kind = FunctionDef_kind;
842 p->v.FunctionDef.name = name;
843 p->v.FunctionDef.args = args;
844 p->v.FunctionDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000845 p->v.FunctionDef.decorator_list = decorator_list;
Neal Norwitzc1505362006-12-28 06:47:50 +0000846 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000848 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 return p;
850}
851
852stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000853ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000854 starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list,
855 int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856{
857 stmt_ty p;
858 if (!name) {
859 PyErr_SetString(PyExc_ValueError,
860 "field name is required for ClassDef");
861 return NULL;
862 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000863 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000864 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 p->kind = ClassDef_kind;
867 p->v.ClassDef.name = name;
868 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000869 p->v.ClassDef.keywords = keywords;
870 p->v.ClassDef.starargs = starargs;
871 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000872 p->v.ClassDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000873 p->v.ClassDef.decorator_list = decorator_list;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000875 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 return p;
877}
878
879stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000880Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881{
882 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000883 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000884 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000886 p->kind = Return_kind;
887 p->v.Return.value = value;
888 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000889 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890 return p;
891}
892
893stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000894Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000895{
896 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000897 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000898 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000900 p->kind = Delete_kind;
901 p->v.Delete.targets = targets;
902 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000903 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000904 return p;
905}
906
907stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000908Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
909 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000910{
911 stmt_ty p;
912 if (!value) {
913 PyErr_SetString(PyExc_ValueError,
914 "field value is required for Assign");
915 return NULL;
916 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000917 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000918 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000919 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000920 p->kind = Assign_kind;
921 p->v.Assign.targets = targets;
922 p->v.Assign.value = value;
923 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000924 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000925 return p;
926}
927
928stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000929AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
930 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931{
932 stmt_ty p;
933 if (!target) {
934 PyErr_SetString(PyExc_ValueError,
935 "field target is required for AugAssign");
936 return NULL;
937 }
938 if (!op) {
939 PyErr_SetString(PyExc_ValueError,
940 "field op is required for AugAssign");
941 return NULL;
942 }
943 if (!value) {
944 PyErr_SetString(PyExc_ValueError,
945 "field value is required for AugAssign");
946 return NULL;
947 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000948 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000949 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000950 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951 p->kind = AugAssign_kind;
952 p->v.AugAssign.target = target;
953 p->v.AugAssign.op = op;
954 p->v.AugAssign.value = value;
955 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000956 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000957 return p;
958}
959
960stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000961For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000962 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000963{
964 stmt_ty p;
965 if (!target) {
966 PyErr_SetString(PyExc_ValueError,
967 "field target is required for For");
968 return NULL;
969 }
970 if (!iter) {
971 PyErr_SetString(PyExc_ValueError,
972 "field iter is required for For");
973 return NULL;
974 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000975 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000976 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000978 p->kind = For_kind;
979 p->v.For.target = target;
980 p->v.For.iter = iter;
981 p->v.For.body = body;
982 p->v.For.orelse = orelse;
983 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000984 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985 return p;
986}
987
988stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000989While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
990 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991{
992 stmt_ty p;
993 if (!test) {
994 PyErr_SetString(PyExc_ValueError,
995 "field test is required for While");
996 return NULL;
997 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000998 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000999 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001000 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 p->kind = While_kind;
1002 p->v.While.test = test;
1003 p->v.While.body = body;
1004 p->v.While.orelse = orelse;
1005 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001006 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001007 return p;
1008}
1009
1010stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001011If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1012 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013{
1014 stmt_ty p;
1015 if (!test) {
1016 PyErr_SetString(PyExc_ValueError,
1017 "field test is required for If");
1018 return NULL;
1019 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001020 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001021 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001022 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001023 p->kind = If_kind;
1024 p->v.If.test = test;
1025 p->v.If.body = body;
1026 p->v.If.orelse = orelse;
1027 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001028 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001029 return p;
1030}
1031
1032stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001033With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001034 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001035{
1036 stmt_ty p;
1037 if (!context_expr) {
1038 PyErr_SetString(PyExc_ValueError,
1039 "field context_expr is required for With");
1040 return NULL;
1041 }
1042 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001043 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001044 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001045 p->kind = With_kind;
1046 p->v.With.context_expr = context_expr;
1047 p->v.With.optional_vars = optional_vars;
1048 p->v.With.body = body;
1049 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001050 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001051 return p;
1052}
1053
1054stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001055Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1056 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001057{
1058 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001059 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001060 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001061 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 p->kind = Raise_kind;
1063 p->v.Raise.type = type;
1064 p->v.Raise.inst = inst;
1065 p->v.Raise.tback = tback;
1066 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001067 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068 return p;
1069}
1070
1071stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001072TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001073 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001074{
1075 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001076 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001077 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001078 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 p->kind = TryExcept_kind;
1080 p->v.TryExcept.body = body;
1081 p->v.TryExcept.handlers = handlers;
1082 p->v.TryExcept.orelse = orelse;
1083 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001084 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085 return p;
1086}
1087
1088stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001089TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1090 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001091{
1092 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001093 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001094 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096 p->kind = TryFinally_kind;
1097 p->v.TryFinally.body = body;
1098 p->v.TryFinally.finalbody = finalbody;
1099 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001100 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101 return p;
1102}
1103
1104stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001105Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106{
1107 stmt_ty p;
1108 if (!test) {
1109 PyErr_SetString(PyExc_ValueError,
1110 "field test is required for Assert");
1111 return NULL;
1112 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001113 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001114 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001115 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 p->kind = Assert_kind;
1117 p->v.Assert.test = test;
1118 p->v.Assert.msg = msg;
1119 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001120 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001121 return p;
1122}
1123
1124stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001125Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001126{
1127 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001128 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001129 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001130 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 p->kind = Import_kind;
1132 p->v.Import.names = names;
1133 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001134 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 return p;
1136}
1137
1138stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001139ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1140 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001141{
1142 stmt_ty p;
1143 if (!module) {
1144 PyErr_SetString(PyExc_ValueError,
1145 "field module is required for ImportFrom");
1146 return NULL;
1147 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001148 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001149 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001150 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151 p->kind = ImportFrom_kind;
1152 p->v.ImportFrom.module = module;
1153 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001154 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001155 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001156 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 return p;
1158}
1159
1160stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001161Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001162{
1163 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001164 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001165 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001166 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 p->kind = Global_kind;
1168 p->v.Global.names = names;
1169 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001170 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001171 return p;
1172}
1173
1174stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001175Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1176{
1177 stmt_ty p;
1178 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1179 if (!p)
1180 return NULL;
1181 p->kind = Nonlocal_kind;
1182 p->v.Nonlocal.names = names;
1183 p->lineno = lineno;
1184 p->col_offset = col_offset;
1185 return p;
1186}
1187
1188stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001189Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190{
1191 stmt_ty p;
1192 if (!value) {
1193 PyErr_SetString(PyExc_ValueError,
1194 "field value is required for Expr");
1195 return NULL;
1196 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001197 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001198 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 p->kind = Expr_kind;
1201 p->v.Expr.value = value;
1202 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001203 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204 return p;
1205}
1206
1207stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001208Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209{
1210 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001211 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001212 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001213 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214 p->kind = Pass_kind;
1215 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001216 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217 return p;
1218}
1219
1220stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001221Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222{
1223 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001224 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001225 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001226 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 p->kind = Break_kind;
1228 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001229 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230 return p;
1231}
1232
1233stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001234Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235{
1236 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001237 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001238 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001240 p->kind = Continue_kind;
1241 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001242 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001243 return p;
1244}
1245
1246expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001247BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1248 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249{
1250 expr_ty p;
1251 if (!op) {
1252 PyErr_SetString(PyExc_ValueError,
1253 "field op is required for BoolOp");
1254 return NULL;
1255 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001256 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001257 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001258 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259 p->kind = BoolOp_kind;
1260 p->v.BoolOp.op = op;
1261 p->v.BoolOp.values = values;
1262 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001263 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264 return p;
1265}
1266
1267expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001268BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1269 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001270{
1271 expr_ty p;
1272 if (!left) {
1273 PyErr_SetString(PyExc_ValueError,
1274 "field left is required for BinOp");
1275 return NULL;
1276 }
1277 if (!op) {
1278 PyErr_SetString(PyExc_ValueError,
1279 "field op is required for BinOp");
1280 return NULL;
1281 }
1282 if (!right) {
1283 PyErr_SetString(PyExc_ValueError,
1284 "field right is required for BinOp");
1285 return NULL;
1286 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001287 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001288 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001289 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290 p->kind = BinOp_kind;
1291 p->v.BinOp.left = left;
1292 p->v.BinOp.op = op;
1293 p->v.BinOp.right = right;
1294 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001295 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001296 return p;
1297}
1298
1299expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001300UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1301 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302{
1303 expr_ty p;
1304 if (!op) {
1305 PyErr_SetString(PyExc_ValueError,
1306 "field op is required for UnaryOp");
1307 return NULL;
1308 }
1309 if (!operand) {
1310 PyErr_SetString(PyExc_ValueError,
1311 "field operand is required for UnaryOp");
1312 return NULL;
1313 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001314 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001315 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001316 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001317 p->kind = UnaryOp_kind;
1318 p->v.UnaryOp.op = op;
1319 p->v.UnaryOp.operand = operand;
1320 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001321 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001322 return p;
1323}
1324
1325expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001326Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1327 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001328{
1329 expr_ty p;
1330 if (!args) {
1331 PyErr_SetString(PyExc_ValueError,
1332 "field args is required for Lambda");
1333 return NULL;
1334 }
1335 if (!body) {
1336 PyErr_SetString(PyExc_ValueError,
1337 "field body is required for Lambda");
1338 return NULL;
1339 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001340 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001341 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001342 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001343 p->kind = Lambda_kind;
1344 p->v.Lambda.args = args;
1345 p->v.Lambda.body = body;
1346 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001347 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001348 return p;
1349}
1350
1351expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001352IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1353 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001354{
1355 expr_ty p;
1356 if (!test) {
1357 PyErr_SetString(PyExc_ValueError,
1358 "field test is required for IfExp");
1359 return NULL;
1360 }
1361 if (!body) {
1362 PyErr_SetString(PyExc_ValueError,
1363 "field body is required for IfExp");
1364 return NULL;
1365 }
1366 if (!orelse) {
1367 PyErr_SetString(PyExc_ValueError,
1368 "field orelse is required for IfExp");
1369 return NULL;
1370 }
1371 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001372 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001373 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001374 p->kind = IfExp_kind;
1375 p->v.IfExp.test = test;
1376 p->v.IfExp.body = body;
1377 p->v.IfExp.orelse = orelse;
1378 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001379 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001380 return p;
1381}
1382
1383expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001384Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1385 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001386{
1387 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001388 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001389 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001390 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001391 p->kind = Dict_kind;
1392 p->v.Dict.keys = keys;
1393 p->v.Dict.values = values;
1394 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001395 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001396 return p;
1397}
1398
1399expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001400Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1401{
1402 expr_ty p;
1403 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001404 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001405 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001406 p->kind = Set_kind;
1407 p->v.Set.elts = elts;
1408 p->lineno = lineno;
1409 p->col_offset = col_offset;
1410 return p;
1411}
1412
1413expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001414ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1415 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001416{
1417 expr_ty p;
1418 if (!elt) {
1419 PyErr_SetString(PyExc_ValueError,
1420 "field elt is required for ListComp");
1421 return NULL;
1422 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001423 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001424 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001425 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426 p->kind = ListComp_kind;
1427 p->v.ListComp.elt = elt;
1428 p->v.ListComp.generators = generators;
1429 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001430 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001431 return p;
1432}
1433
1434expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001435SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1436 *arena)
1437{
1438 expr_ty p;
1439 if (!elt) {
1440 PyErr_SetString(PyExc_ValueError,
1441 "field elt is required for SetComp");
1442 return NULL;
1443 }
1444 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1445 if (!p)
1446 return NULL;
1447 p->kind = SetComp_kind;
1448 p->v.SetComp.elt = elt;
1449 p->v.SetComp.generators = generators;
1450 p->lineno = lineno;
1451 p->col_offset = col_offset;
1452 return p;
1453}
1454
1455expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00001456DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1457 col_offset, PyArena *arena)
1458{
1459 expr_ty p;
1460 if (!key) {
1461 PyErr_SetString(PyExc_ValueError,
1462 "field key is required for DictComp");
1463 return NULL;
1464 }
1465 if (!value) {
1466 PyErr_SetString(PyExc_ValueError,
1467 "field value is required for DictComp");
1468 return NULL;
1469 }
1470 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1471 if (!p)
1472 return NULL;
1473 p->kind = DictComp_kind;
1474 p->v.DictComp.key = key;
1475 p->v.DictComp.value = value;
1476 p->v.DictComp.generators = generators;
1477 p->lineno = lineno;
1478 p->col_offset = col_offset;
1479 return p;
1480}
1481
1482expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001483GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1484 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001485{
1486 expr_ty p;
1487 if (!elt) {
1488 PyErr_SetString(PyExc_ValueError,
1489 "field elt is required for GeneratorExp");
1490 return NULL;
1491 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001492 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001493 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001495 p->kind = GeneratorExp_kind;
1496 p->v.GeneratorExp.elt = elt;
1497 p->v.GeneratorExp.generators = generators;
1498 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001499 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500 return p;
1501}
1502
1503expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001504Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001505{
1506 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001507 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001508 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001509 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 p->kind = Yield_kind;
1511 p->v.Yield.value = value;
1512 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001513 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 return p;
1515}
1516
1517expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001518Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1519 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001520{
1521 expr_ty p;
1522 if (!left) {
1523 PyErr_SetString(PyExc_ValueError,
1524 "field left is required for Compare");
1525 return NULL;
1526 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001527 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001528 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001529 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530 p->kind = Compare_kind;
1531 p->v.Compare.left = left;
1532 p->v.Compare.ops = ops;
1533 p->v.Compare.comparators = comparators;
1534 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001535 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001536 return p;
1537}
1538
1539expr_ty
1540Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001541 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542{
1543 expr_ty p;
1544 if (!func) {
1545 PyErr_SetString(PyExc_ValueError,
1546 "field func is required for Call");
1547 return NULL;
1548 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001549 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001550 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001552 p->kind = Call_kind;
1553 p->v.Call.func = func;
1554 p->v.Call.args = args;
1555 p->v.Call.keywords = keywords;
1556 p->v.Call.starargs = starargs;
1557 p->v.Call.kwargs = kwargs;
1558 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001559 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001560 return p;
1561}
1562
1563expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001564Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565{
1566 expr_ty p;
1567 if (!n) {
1568 PyErr_SetString(PyExc_ValueError,
1569 "field n is required for Num");
1570 return NULL;
1571 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001572 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001573 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001574 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001575 p->kind = Num_kind;
1576 p->v.Num.n = n;
1577 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001578 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001579 return p;
1580}
1581
1582expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001583Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584{
1585 expr_ty p;
1586 if (!s) {
1587 PyErr_SetString(PyExc_ValueError,
1588 "field s is required for Str");
1589 return NULL;
1590 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001591 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001592 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001593 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594 p->kind = Str_kind;
1595 p->v.Str.s = s;
1596 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001597 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001598 return p;
1599}
1600
1601expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001602Bytes(string s, int lineno, int col_offset, PyArena *arena)
1603{
1604 expr_ty p;
1605 if (!s) {
1606 PyErr_SetString(PyExc_ValueError,
1607 "field s is required for Bytes");
1608 return NULL;
1609 }
1610 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001611 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001612 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001613 p->kind = Bytes_kind;
1614 p->v.Bytes.s = s;
1615 p->lineno = lineno;
1616 p->col_offset = col_offset;
1617 return p;
1618}
1619
1620expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001621Ellipsis(int lineno, int col_offset, PyArena *arena)
1622{
1623 expr_ty p;
1624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001625 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001626 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001627 p->kind = Ellipsis_kind;
1628 p->lineno = lineno;
1629 p->col_offset = col_offset;
1630 return p;
1631}
1632
1633expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001634Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1635 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001636{
1637 expr_ty p;
1638 if (!value) {
1639 PyErr_SetString(PyExc_ValueError,
1640 "field value is required for Attribute");
1641 return NULL;
1642 }
1643 if (!attr) {
1644 PyErr_SetString(PyExc_ValueError,
1645 "field attr is required for Attribute");
1646 return NULL;
1647 }
1648 if (!ctx) {
1649 PyErr_SetString(PyExc_ValueError,
1650 "field ctx is required for Attribute");
1651 return NULL;
1652 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001653 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001654 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001655 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001656 p->kind = Attribute_kind;
1657 p->v.Attribute.value = value;
1658 p->v.Attribute.attr = attr;
1659 p->v.Attribute.ctx = ctx;
1660 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001661 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001662 return p;
1663}
1664
1665expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001666Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1667 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668{
1669 expr_ty p;
1670 if (!value) {
1671 PyErr_SetString(PyExc_ValueError,
1672 "field value is required for Subscript");
1673 return NULL;
1674 }
1675 if (!slice) {
1676 PyErr_SetString(PyExc_ValueError,
1677 "field slice is required for Subscript");
1678 return NULL;
1679 }
1680 if (!ctx) {
1681 PyErr_SetString(PyExc_ValueError,
1682 "field ctx is required for Subscript");
1683 return NULL;
1684 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001685 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001686 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001687 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 p->kind = Subscript_kind;
1689 p->v.Subscript.value = value;
1690 p->v.Subscript.slice = slice;
1691 p->v.Subscript.ctx = ctx;
1692 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001693 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001694 return p;
1695}
1696
1697expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00001698Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
1699 *arena)
1700{
1701 expr_ty p;
1702 if (!value) {
1703 PyErr_SetString(PyExc_ValueError,
1704 "field value is required for Starred");
1705 return NULL;
1706 }
1707 if (!ctx) {
1708 PyErr_SetString(PyExc_ValueError,
1709 "field ctx is required for Starred");
1710 return NULL;
1711 }
1712 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1713 if (!p)
1714 return NULL;
1715 p->kind = Starred_kind;
1716 p->v.Starred.value = value;
1717 p->v.Starred.ctx = ctx;
1718 p->lineno = lineno;
1719 p->col_offset = col_offset;
1720 return p;
1721}
1722
1723expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001724Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1725 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726{
1727 expr_ty p;
1728 if (!id) {
1729 PyErr_SetString(PyExc_ValueError,
1730 "field id is required for Name");
1731 return NULL;
1732 }
1733 if (!ctx) {
1734 PyErr_SetString(PyExc_ValueError,
1735 "field ctx is required for Name");
1736 return NULL;
1737 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001738 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001739 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001741 p->kind = Name_kind;
1742 p->v.Name.id = id;
1743 p->v.Name.ctx = ctx;
1744 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001745 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001746 return p;
1747}
1748
1749expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001750List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1751 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001752{
1753 expr_ty p;
1754 if (!ctx) {
1755 PyErr_SetString(PyExc_ValueError,
1756 "field ctx is required for List");
1757 return NULL;
1758 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001759 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001760 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762 p->kind = List_kind;
1763 p->v.List.elts = elts;
1764 p->v.List.ctx = ctx;
1765 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001766 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767 return p;
1768}
1769
1770expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001771Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1772 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001773{
1774 expr_ty p;
1775 if (!ctx) {
1776 PyErr_SetString(PyExc_ValueError,
1777 "field ctx is required for Tuple");
1778 return NULL;
1779 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001780 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001781 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001782 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001783 p->kind = Tuple_kind;
1784 p->v.Tuple.elts = elts;
1785 p->v.Tuple.ctx = ctx;
1786 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001787 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001788 return p;
1789}
1790
1791slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001792Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001793{
1794 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001795 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001796 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001797 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001798 p->kind = Slice_kind;
1799 p->v.Slice.lower = lower;
1800 p->v.Slice.upper = upper;
1801 p->v.Slice.step = step;
1802 return p;
1803}
1804
1805slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001806ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001807{
1808 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001809 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001810 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001811 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001812 p->kind = ExtSlice_kind;
1813 p->v.ExtSlice.dims = dims;
1814 return p;
1815}
1816
1817slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001818Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001819{
1820 slice_ty p;
1821 if (!value) {
1822 PyErr_SetString(PyExc_ValueError,
1823 "field value is required for Index");
1824 return NULL;
1825 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001826 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001827 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001828 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 p->kind = Index_kind;
1830 p->v.Index.value = value;
1831 return p;
1832}
1833
1834comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001835comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001836{
1837 comprehension_ty p;
1838 if (!target) {
1839 PyErr_SetString(PyExc_ValueError,
1840 "field target is required for comprehension");
1841 return NULL;
1842 }
1843 if (!iter) {
1844 PyErr_SetString(PyExc_ValueError,
1845 "field iter is required for comprehension");
1846 return NULL;
1847 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001848 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001849 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001851 p->target = target;
1852 p->iter = iter;
1853 p->ifs = ifs;
1854 return p;
1855}
1856
1857excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001858excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001859 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001860{
1861 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001862 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001863 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001865 p->type = type;
1866 p->name = name;
1867 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001868 p->lineno = lineno;
1869 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870 return p;
1871}
1872
1873arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001874arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1875 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1876 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877{
1878 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001879 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001880 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882 p->args = args;
1883 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001884 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001885 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001887 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001888 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001889 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001890 return p;
1891}
1892
Neal Norwitzc1505362006-12-28 06:47:50 +00001893arg_ty
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001894arg(identifier arg, expr_ty annotation, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00001895{
1896 arg_ty p;
1897 if (!arg) {
1898 PyErr_SetString(PyExc_ValueError,
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001899 "field arg is required for arg");
Neal Norwitzc1505362006-12-28 06:47:50 +00001900 return NULL;
1901 }
1902 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001903 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001904 return NULL;
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001905 p->arg = arg;
1906 p->annotation = annotation;
Neal Norwitzc1505362006-12-28 06:47:50 +00001907 return p;
1908}
1909
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001910keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001911keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001912{
1913 keyword_ty p;
1914 if (!arg) {
1915 PyErr_SetString(PyExc_ValueError,
1916 "field arg is required for keyword");
1917 return NULL;
1918 }
1919 if (!value) {
1920 PyErr_SetString(PyExc_ValueError,
1921 "field value is required for keyword");
1922 return NULL;
1923 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001924 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001925 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001926 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001927 p->arg = arg;
1928 p->value = value;
1929 return p;
1930}
1931
1932alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001933alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001934{
1935 alias_ty p;
1936 if (!name) {
1937 PyErr_SetString(PyExc_ValueError,
1938 "field name is required for alias");
1939 return NULL;
1940 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001941 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001942 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001943 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001944 p->name = name;
1945 p->asname = asname;
1946 return p;
1947}
1948
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001949
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001950PyObject*
1951ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001952{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001953 mod_ty o = (mod_ty)_o;
1954 PyObject *result = NULL, *value = NULL;
1955 if (!o) {
1956 Py_INCREF(Py_None);
1957 return Py_None;
1958 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001959
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001960 switch (o->kind) {
1961 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001962 result = PyType_GenericNew(Module_type, NULL, NULL);
1963 if (!result) goto failed;
1964 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1965 if (!value) goto failed;
1966 if (PyObject_SetAttrString(result, "body", value) == -1)
1967 goto failed;
1968 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001969 break;
1970 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001971 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1972 if (!result) goto failed;
1973 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1974 if (!value) goto failed;
1975 if (PyObject_SetAttrString(result, "body", value) == -1)
1976 goto failed;
1977 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978 break;
1979 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001980 result = PyType_GenericNew(Expression_type, NULL, NULL);
1981 if (!result) goto failed;
1982 value = ast2obj_expr(o->v.Expression.body);
1983 if (!value) goto failed;
1984 if (PyObject_SetAttrString(result, "body", value) == -1)
1985 goto failed;
1986 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001987 break;
1988 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001989 result = PyType_GenericNew(Suite_type, NULL, NULL);
1990 if (!result) goto failed;
1991 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1992 if (!value) goto failed;
1993 if (PyObject_SetAttrString(result, "body", value) == -1)
1994 goto failed;
1995 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001996 break;
1997 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001998 return result;
1999failed:
2000 Py_XDECREF(value);
2001 Py_XDECREF(result);
2002 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002003}
2004
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002005PyObject*
2006ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002007{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002008 stmt_ty o = (stmt_ty)_o;
2009 PyObject *result = NULL, *value = NULL;
2010 if (!o) {
2011 Py_INCREF(Py_None);
2012 return Py_None;
2013 }
2014
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002015 switch (o->kind) {
2016 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002017 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2018 if (!result) goto failed;
2019 value = ast2obj_identifier(o->v.FunctionDef.name);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "name", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
2024 value = ast2obj_arguments(o->v.FunctionDef.args);
2025 if (!value) goto failed;
2026 if (PyObject_SetAttrString(result, "args", value) == -1)
2027 goto failed;
2028 Py_DECREF(value);
2029 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2030 if (!value) goto failed;
2031 if (PyObject_SetAttrString(result, "body", value) == -1)
2032 goto failed;
2033 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002034 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2035 ast2obj_expr);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002036 if (!value) goto failed;
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002037 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2038 -1)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002039 goto failed;
2040 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002041 value = ast2obj_expr(o->v.FunctionDef.returns);
2042 if (!value) goto failed;
2043 if (PyObject_SetAttrString(result, "returns", value) == -1)
2044 goto failed;
2045 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002046 break;
2047 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002048 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2049 if (!result) goto failed;
2050 value = ast2obj_identifier(o->v.ClassDef.name);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "name", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
2055 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "bases", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002060 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2061 if (!value) goto failed;
2062 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2063 goto failed;
2064 Py_DECREF(value);
2065 value = ast2obj_expr(o->v.ClassDef.starargs);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
2070 value = ast2obj_expr(o->v.ClassDef.kwargs);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002075 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2076 if (!value) goto failed;
2077 if (PyObject_SetAttrString(result, "body", value) == -1)
2078 goto failed;
2079 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002080 value = ast2obj_list(o->v.ClassDef.decorator_list,
2081 ast2obj_expr);
2082 if (!value) goto failed;
2083 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2084 -1)
2085 goto failed;
2086 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002087 break;
2088 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002089 result = PyType_GenericNew(Return_type, NULL, NULL);
2090 if (!result) goto failed;
2091 value = ast2obj_expr(o->v.Return.value);
2092 if (!value) goto failed;
2093 if (PyObject_SetAttrString(result, "value", value) == -1)
2094 goto failed;
2095 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096 break;
2097 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002098 result = PyType_GenericNew(Delete_type, NULL, NULL);
2099 if (!result) goto failed;
2100 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2101 if (!value) goto failed;
2102 if (PyObject_SetAttrString(result, "targets", value) == -1)
2103 goto failed;
2104 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002105 break;
2106 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002107 result = PyType_GenericNew(Assign_type, NULL, NULL);
2108 if (!result) goto failed;
2109 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2110 if (!value) goto failed;
2111 if (PyObject_SetAttrString(result, "targets", value) == -1)
2112 goto failed;
2113 Py_DECREF(value);
2114 value = ast2obj_expr(o->v.Assign.value);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "value", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002119 break;
2120 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002121 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2122 if (!result) goto failed;
2123 value = ast2obj_expr(o->v.AugAssign.target);
2124 if (!value) goto failed;
2125 if (PyObject_SetAttrString(result, "target", value) == -1)
2126 goto failed;
2127 Py_DECREF(value);
2128 value = ast2obj_operator(o->v.AugAssign.op);
2129 if (!value) goto failed;
2130 if (PyObject_SetAttrString(result, "op", value) == -1)
2131 goto failed;
2132 Py_DECREF(value);
2133 value = ast2obj_expr(o->v.AugAssign.value);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "value", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002138 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002139 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002140 result = PyType_GenericNew(For_type, NULL, NULL);
2141 if (!result) goto failed;
2142 value = ast2obj_expr(o->v.For.target);
2143 if (!value) goto failed;
2144 if (PyObject_SetAttrString(result, "target", value) == -1)
2145 goto failed;
2146 Py_DECREF(value);
2147 value = ast2obj_expr(o->v.For.iter);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "iter", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
2152 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2153 if (!value) goto failed;
2154 if (PyObject_SetAttrString(result, "body", value) == -1)
2155 goto failed;
2156 Py_DECREF(value);
2157 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2158 if (!value) goto failed;
2159 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2160 goto failed;
2161 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002162 break;
2163 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002164 result = PyType_GenericNew(While_type, NULL, NULL);
2165 if (!result) goto failed;
2166 value = ast2obj_expr(o->v.While.test);
2167 if (!value) goto failed;
2168 if (PyObject_SetAttrString(result, "test", value) == -1)
2169 goto failed;
2170 Py_DECREF(value);
2171 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2172 if (!value) goto failed;
2173 if (PyObject_SetAttrString(result, "body", value) == -1)
2174 goto failed;
2175 Py_DECREF(value);
2176 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2177 if (!value) goto failed;
2178 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2179 goto failed;
2180 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002181 break;
2182 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002183 result = PyType_GenericNew(If_type, NULL, NULL);
2184 if (!result) goto failed;
2185 value = ast2obj_expr(o->v.If.test);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "test", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
2190 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "body", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002200 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002201 case With_kind:
2202 result = PyType_GenericNew(With_type, NULL, NULL);
2203 if (!result) goto failed;
2204 value = ast2obj_expr(o->v.With.context_expr);
2205 if (!value) goto failed;
2206 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2207 goto failed;
2208 Py_DECREF(value);
2209 value = ast2obj_expr(o->v.With.optional_vars);
2210 if (!value) goto failed;
2211 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2212 -1)
2213 goto failed;
2214 Py_DECREF(value);
2215 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "body", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
2220 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002221 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002222 result = PyType_GenericNew(Raise_type, NULL, NULL);
2223 if (!result) goto failed;
2224 value = ast2obj_expr(o->v.Raise.type);
2225 if (!value) goto failed;
2226 if (PyObject_SetAttrString(result, "type", value) == -1)
2227 goto failed;
2228 Py_DECREF(value);
2229 value = ast2obj_expr(o->v.Raise.inst);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "inst", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
2234 value = ast2obj_expr(o->v.Raise.tback);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "tback", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002239 break;
2240 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002241 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2242 if (!result) goto failed;
2243 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "body", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
2248 value = ast2obj_list(o->v.TryExcept.handlers,
2249 ast2obj_excepthandler);
2250 if (!value) goto failed;
2251 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2252 goto failed;
2253 Py_DECREF(value);
2254 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259 break;
2260 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002261 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2262 if (!result) goto failed;
2263 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2264 if (!value) goto failed;
2265 if (PyObject_SetAttrString(result, "body", value) == -1)
2266 goto failed;
2267 Py_DECREF(value);
2268 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2269 if (!value) goto failed;
2270 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2271 goto failed;
2272 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002273 break;
2274 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002275 result = PyType_GenericNew(Assert_type, NULL, NULL);
2276 if (!result) goto failed;
2277 value = ast2obj_expr(o->v.Assert.test);
2278 if (!value) goto failed;
2279 if (PyObject_SetAttrString(result, "test", value) == -1)
2280 goto failed;
2281 Py_DECREF(value);
2282 value = ast2obj_expr(o->v.Assert.msg);
2283 if (!value) goto failed;
2284 if (PyObject_SetAttrString(result, "msg", value) == -1)
2285 goto failed;
2286 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002287 break;
2288 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002289 result = PyType_GenericNew(Import_type, NULL, NULL);
2290 if (!result) goto failed;
2291 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2292 if (!value) goto failed;
2293 if (PyObject_SetAttrString(result, "names", value) == -1)
2294 goto failed;
2295 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002296 break;
2297 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002298 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2299 if (!result) goto failed;
2300 value = ast2obj_identifier(o->v.ImportFrom.module);
2301 if (!value) goto failed;
2302 if (PyObject_SetAttrString(result, "module", value) == -1)
2303 goto failed;
2304 Py_DECREF(value);
2305 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2306 if (!value) goto failed;
2307 if (PyObject_SetAttrString(result, "names", value) == -1)
2308 goto failed;
2309 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002310 value = ast2obj_int(o->v.ImportFrom.level);
2311 if (!value) goto failed;
2312 if (PyObject_SetAttrString(result, "level", value) == -1)
2313 goto failed;
2314 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002315 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002316 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002317 result = PyType_GenericNew(Global_type, NULL, NULL);
2318 if (!result) goto failed;
2319 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2320 if (!value) goto failed;
2321 if (PyObject_SetAttrString(result, "names", value) == -1)
2322 goto failed;
2323 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002325 case Nonlocal_kind:
2326 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2327 if (!result) goto failed;
2328 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "names", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
2333 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002334 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002335 result = PyType_GenericNew(Expr_type, NULL, NULL);
2336 if (!result) goto failed;
2337 value = ast2obj_expr(o->v.Expr.value);
2338 if (!value) goto failed;
2339 if (PyObject_SetAttrString(result, "value", value) == -1)
2340 goto failed;
2341 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342 break;
2343 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 result = PyType_GenericNew(Pass_type, NULL, NULL);
2345 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346 break;
2347 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002348 result = PyType_GenericNew(Break_type, NULL, NULL);
2349 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002350 break;
2351 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002352 result = PyType_GenericNew(Continue_type, NULL, NULL);
2353 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002354 break;
2355 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002356 value = ast2obj_int(o->lineno);
2357 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002358 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2359 goto failed;
2360 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002361 value = ast2obj_int(o->col_offset);
2362 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002363 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2364 goto failed;
2365 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002366 return result;
2367failed:
2368 Py_XDECREF(value);
2369 Py_XDECREF(result);
2370 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002371}
2372
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002373PyObject*
2374ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002376 expr_ty o = (expr_ty)_o;
2377 PyObject *result = NULL, *value = NULL;
2378 if (!o) {
2379 Py_INCREF(Py_None);
2380 return Py_None;
2381 }
2382
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002383 switch (o->kind) {
2384 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002385 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2386 if (!result) goto failed;
2387 value = ast2obj_boolop(o->v.BoolOp.op);
2388 if (!value) goto failed;
2389 if (PyObject_SetAttrString(result, "op", value) == -1)
2390 goto failed;
2391 Py_DECREF(value);
2392 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2393 if (!value) goto failed;
2394 if (PyObject_SetAttrString(result, "values", value) == -1)
2395 goto failed;
2396 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002397 break;
2398 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002399 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2400 if (!result) goto failed;
2401 value = ast2obj_expr(o->v.BinOp.left);
2402 if (!value) goto failed;
2403 if (PyObject_SetAttrString(result, "left", value) == -1)
2404 goto failed;
2405 Py_DECREF(value);
2406 value = ast2obj_operator(o->v.BinOp.op);
2407 if (!value) goto failed;
2408 if (PyObject_SetAttrString(result, "op", value) == -1)
2409 goto failed;
2410 Py_DECREF(value);
2411 value = ast2obj_expr(o->v.BinOp.right);
2412 if (!value) goto failed;
2413 if (PyObject_SetAttrString(result, "right", value) == -1)
2414 goto failed;
2415 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002416 break;
2417 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002418 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2419 if (!result) goto failed;
2420 value = ast2obj_unaryop(o->v.UnaryOp.op);
2421 if (!value) goto failed;
2422 if (PyObject_SetAttrString(result, "op", value) == -1)
2423 goto failed;
2424 Py_DECREF(value);
2425 value = ast2obj_expr(o->v.UnaryOp.operand);
2426 if (!value) goto failed;
2427 if (PyObject_SetAttrString(result, "operand", value) == -1)
2428 goto failed;
2429 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002430 break;
2431 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002432 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2433 if (!result) goto failed;
2434 value = ast2obj_arguments(o->v.Lambda.args);
2435 if (!value) goto failed;
2436 if (PyObject_SetAttrString(result, "args", value) == -1)
2437 goto failed;
2438 Py_DECREF(value);
2439 value = ast2obj_expr(o->v.Lambda.body);
2440 if (!value) goto failed;
2441 if (PyObject_SetAttrString(result, "body", value) == -1)
2442 goto failed;
2443 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002444 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002445 case IfExp_kind:
2446 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2447 if (!result) goto failed;
2448 value = ast2obj_expr(o->v.IfExp.test);
2449 if (!value) goto failed;
2450 if (PyObject_SetAttrString(result, "test", value) == -1)
2451 goto failed;
2452 Py_DECREF(value);
2453 value = ast2obj_expr(o->v.IfExp.body);
2454 if (!value) goto failed;
2455 if (PyObject_SetAttrString(result, "body", value) == -1)
2456 goto failed;
2457 Py_DECREF(value);
2458 value = ast2obj_expr(o->v.IfExp.orelse);
2459 if (!value) goto failed;
2460 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2461 goto failed;
2462 Py_DECREF(value);
2463 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002464 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002465 result = PyType_GenericNew(Dict_type, NULL, NULL);
2466 if (!result) goto failed;
2467 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "keys", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
2472 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2473 if (!value) goto failed;
2474 if (PyObject_SetAttrString(result, "values", value) == -1)
2475 goto failed;
2476 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002478 case Set_kind:
2479 result = PyType_GenericNew(Set_type, NULL, NULL);
2480 if (!result) goto failed;
2481 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "elts", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002488 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2489 if (!result) goto failed;
2490 value = ast2obj_expr(o->v.ListComp.elt);
2491 if (!value) goto failed;
2492 if (PyObject_SetAttrString(result, "elt", value) == -1)
2493 goto failed;
2494 Py_DECREF(value);
2495 value = ast2obj_list(o->v.ListComp.generators,
2496 ast2obj_comprehension);
2497 if (!value) goto failed;
2498 if (PyObject_SetAttrString(result, "generators", value) == -1)
2499 goto failed;
2500 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002501 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002502 case SetComp_kind:
2503 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2504 if (!result) goto failed;
2505 value = ast2obj_expr(o->v.SetComp.elt);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "elt", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
2510 value = ast2obj_list(o->v.SetComp.generators,
2511 ast2obj_comprehension);
2512 if (!value) goto failed;
2513 if (PyObject_SetAttrString(result, "generators", value) == -1)
2514 goto failed;
2515 Py_DECREF(value);
2516 break;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002517 case DictComp_kind:
2518 result = PyType_GenericNew(DictComp_type, NULL, NULL);
2519 if (!result) goto failed;
2520 value = ast2obj_expr(o->v.DictComp.key);
2521 if (!value) goto failed;
2522 if (PyObject_SetAttrString(result, "key", value) == -1)
2523 goto failed;
2524 Py_DECREF(value);
2525 value = ast2obj_expr(o->v.DictComp.value);
2526 if (!value) goto failed;
2527 if (PyObject_SetAttrString(result, "value", value) == -1)
2528 goto failed;
2529 Py_DECREF(value);
2530 value = ast2obj_list(o->v.DictComp.generators,
2531 ast2obj_comprehension);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "generators", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002537 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002538 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2539 if (!result) goto failed;
2540 value = ast2obj_expr(o->v.GeneratorExp.elt);
2541 if (!value) goto failed;
2542 if (PyObject_SetAttrString(result, "elt", value) == -1)
2543 goto failed;
2544 Py_DECREF(value);
2545 value = ast2obj_list(o->v.GeneratorExp.generators,
2546 ast2obj_comprehension);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "generators", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002551 break;
2552 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002553 result = PyType_GenericNew(Yield_type, NULL, NULL);
2554 if (!result) goto failed;
2555 value = ast2obj_expr(o->v.Yield.value);
2556 if (!value) goto failed;
2557 if (PyObject_SetAttrString(result, "value", value) == -1)
2558 goto failed;
2559 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002560 break;
2561 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002562 result = PyType_GenericNew(Compare_type, NULL, NULL);
2563 if (!result) goto failed;
2564 value = ast2obj_expr(o->v.Compare.left);
2565 if (!value) goto failed;
2566 if (PyObject_SetAttrString(result, "left", value) == -1)
2567 goto failed;
2568 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002569 {
2570 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2571 value = PyList_New(n);
2572 if (!value) goto failed;
2573 for(i = 0; i < n; i++)
2574 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2575 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "ops", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002585 break;
2586 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002587 result = PyType_GenericNew(Call_type, NULL, NULL);
2588 if (!result) goto failed;
2589 value = ast2obj_expr(o->v.Call.func);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "func", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
2594 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "args", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2600 if (!value) goto failed;
2601 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2602 goto failed;
2603 Py_DECREF(value);
2604 value = ast2obj_expr(o->v.Call.starargs);
2605 if (!value) goto failed;
2606 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2607 goto failed;
2608 Py_DECREF(value);
2609 value = ast2obj_expr(o->v.Call.kwargs);
2610 if (!value) goto failed;
2611 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2612 goto failed;
2613 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002614 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002615 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002616 result = PyType_GenericNew(Num_type, NULL, NULL);
2617 if (!result) goto failed;
2618 value = ast2obj_object(o->v.Num.n);
2619 if (!value) goto failed;
2620 if (PyObject_SetAttrString(result, "n", value) == -1)
2621 goto failed;
2622 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002623 break;
2624 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002625 result = PyType_GenericNew(Str_type, NULL, NULL);
2626 if (!result) goto failed;
2627 value = ast2obj_string(o->v.Str.s);
2628 if (!value) goto failed;
2629 if (PyObject_SetAttrString(result, "s", value) == -1)
2630 goto failed;
2631 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002633 case Bytes_kind:
2634 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2635 if (!result) goto failed;
2636 value = ast2obj_string(o->v.Bytes.s);
2637 if (!value) goto failed;
2638 if (PyObject_SetAttrString(result, "s", value) == -1)
2639 goto failed;
2640 Py_DECREF(value);
2641 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002642 case Ellipsis_kind:
2643 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2644 if (!result) goto failed;
2645 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002646 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002647 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2648 if (!result) goto failed;
2649 value = ast2obj_expr(o->v.Attribute.value);
2650 if (!value) goto failed;
2651 if (PyObject_SetAttrString(result, "value", value) == -1)
2652 goto failed;
2653 Py_DECREF(value);
2654 value = ast2obj_identifier(o->v.Attribute.attr);
2655 if (!value) goto failed;
2656 if (PyObject_SetAttrString(result, "attr", value) == -1)
2657 goto failed;
2658 Py_DECREF(value);
2659 value = ast2obj_expr_context(o->v.Attribute.ctx);
2660 if (!value) goto failed;
2661 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2662 goto failed;
2663 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002664 break;
2665 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002666 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2667 if (!result) goto failed;
2668 value = ast2obj_expr(o->v.Subscript.value);
2669 if (!value) goto failed;
2670 if (PyObject_SetAttrString(result, "value", value) == -1)
2671 goto failed;
2672 Py_DECREF(value);
2673 value = ast2obj_slice(o->v.Subscript.slice);
2674 if (!value) goto failed;
2675 if (PyObject_SetAttrString(result, "slice", value) == -1)
2676 goto failed;
2677 Py_DECREF(value);
2678 value = ast2obj_expr_context(o->v.Subscript.ctx);
2679 if (!value) goto failed;
2680 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2681 goto failed;
2682 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002683 break;
Guido van Rossum0368b722007-05-11 16:50:42 +00002684 case Starred_kind:
2685 result = PyType_GenericNew(Starred_type, NULL, NULL);
2686 if (!result) goto failed;
2687 value = ast2obj_expr(o->v.Starred.value);
2688 if (!value) goto failed;
2689 if (PyObject_SetAttrString(result, "value", value) == -1)
2690 goto failed;
2691 Py_DECREF(value);
2692 value = ast2obj_expr_context(o->v.Starred.ctx);
2693 if (!value) goto failed;
2694 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2695 goto failed;
2696 Py_DECREF(value);
2697 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002698 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002699 result = PyType_GenericNew(Name_type, NULL, NULL);
2700 if (!result) goto failed;
2701 value = ast2obj_identifier(o->v.Name.id);
2702 if (!value) goto failed;
2703 if (PyObject_SetAttrString(result, "id", value) == -1)
2704 goto failed;
2705 Py_DECREF(value);
2706 value = ast2obj_expr_context(o->v.Name.ctx);
2707 if (!value) goto failed;
2708 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2709 goto failed;
2710 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002711 break;
2712 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002713 result = PyType_GenericNew(List_type, NULL, NULL);
2714 if (!result) goto failed;
2715 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2716 if (!value) goto failed;
2717 if (PyObject_SetAttrString(result, "elts", value) == -1)
2718 goto failed;
2719 Py_DECREF(value);
2720 value = ast2obj_expr_context(o->v.List.ctx);
2721 if (!value) goto failed;
2722 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2723 goto failed;
2724 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002725 break;
2726 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002727 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2728 if (!result) goto failed;
2729 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2730 if (!value) goto failed;
2731 if (PyObject_SetAttrString(result, "elts", value) == -1)
2732 goto failed;
2733 Py_DECREF(value);
2734 value = ast2obj_expr_context(o->v.Tuple.ctx);
2735 if (!value) goto failed;
2736 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2737 goto failed;
2738 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002739 break;
2740 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002741 value = ast2obj_int(o->lineno);
2742 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002743 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2744 goto failed;
2745 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002746 value = ast2obj_int(o->col_offset);
2747 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002748 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2749 goto failed;
2750 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002751 return result;
2752failed:
2753 Py_XDECREF(value);
2754 Py_XDECREF(result);
2755 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002756}
2757
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002758PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002759{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002760 switch(o) {
2761 case Load:
2762 Py_INCREF(Load_singleton);
2763 return Load_singleton;
2764 case Store:
2765 Py_INCREF(Store_singleton);
2766 return Store_singleton;
2767 case Del:
2768 Py_INCREF(Del_singleton);
2769 return Del_singleton;
2770 case AugLoad:
2771 Py_INCREF(AugLoad_singleton);
2772 return AugLoad_singleton;
2773 case AugStore:
2774 Py_INCREF(AugStore_singleton);
2775 return AugStore_singleton;
2776 case Param:
2777 Py_INCREF(Param_singleton);
2778 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002779 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002780 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002781}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002782PyObject*
2783ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002784{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002785 slice_ty o = (slice_ty)_o;
2786 PyObject *result = NULL, *value = NULL;
2787 if (!o) {
2788 Py_INCREF(Py_None);
2789 return Py_None;
2790 }
2791
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002792 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002793 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002794 result = PyType_GenericNew(Slice_type, NULL, NULL);
2795 if (!result) goto failed;
2796 value = ast2obj_expr(o->v.Slice.lower);
2797 if (!value) goto failed;
2798 if (PyObject_SetAttrString(result, "lower", value) == -1)
2799 goto failed;
2800 Py_DECREF(value);
2801 value = ast2obj_expr(o->v.Slice.upper);
2802 if (!value) goto failed;
2803 if (PyObject_SetAttrString(result, "upper", value) == -1)
2804 goto failed;
2805 Py_DECREF(value);
2806 value = ast2obj_expr(o->v.Slice.step);
2807 if (!value) goto failed;
2808 if (PyObject_SetAttrString(result, "step", value) == -1)
2809 goto failed;
2810 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002811 break;
2812 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002813 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2814 if (!result) goto failed;
2815 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2816 if (!value) goto failed;
2817 if (PyObject_SetAttrString(result, "dims", value) == -1)
2818 goto failed;
2819 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002820 break;
2821 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002822 result = PyType_GenericNew(Index_type, NULL, NULL);
2823 if (!result) goto failed;
2824 value = ast2obj_expr(o->v.Index.value);
2825 if (!value) goto failed;
2826 if (PyObject_SetAttrString(result, "value", value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002829 break;
2830 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002831 return result;
2832failed:
2833 Py_XDECREF(value);
2834 Py_XDECREF(result);
2835 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002836}
2837
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002838PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002839{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002840 switch(o) {
2841 case And:
2842 Py_INCREF(And_singleton);
2843 return And_singleton;
2844 case Or:
2845 Py_INCREF(Or_singleton);
2846 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002847 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002848 return NULL; /* cannot happen */
2849}
2850PyObject* ast2obj_operator(operator_ty o)
2851{
2852 switch(o) {
2853 case Add:
2854 Py_INCREF(Add_singleton);
2855 return Add_singleton;
2856 case Sub:
2857 Py_INCREF(Sub_singleton);
2858 return Sub_singleton;
2859 case Mult:
2860 Py_INCREF(Mult_singleton);
2861 return Mult_singleton;
2862 case Div:
2863 Py_INCREF(Div_singleton);
2864 return Div_singleton;
2865 case Mod:
2866 Py_INCREF(Mod_singleton);
2867 return Mod_singleton;
2868 case Pow:
2869 Py_INCREF(Pow_singleton);
2870 return Pow_singleton;
2871 case LShift:
2872 Py_INCREF(LShift_singleton);
2873 return LShift_singleton;
2874 case RShift:
2875 Py_INCREF(RShift_singleton);
2876 return RShift_singleton;
2877 case BitOr:
2878 Py_INCREF(BitOr_singleton);
2879 return BitOr_singleton;
2880 case BitXor:
2881 Py_INCREF(BitXor_singleton);
2882 return BitXor_singleton;
2883 case BitAnd:
2884 Py_INCREF(BitAnd_singleton);
2885 return BitAnd_singleton;
2886 case FloorDiv:
2887 Py_INCREF(FloorDiv_singleton);
2888 return FloorDiv_singleton;
2889 }
2890 return NULL; /* cannot happen */
2891}
2892PyObject* ast2obj_unaryop(unaryop_ty o)
2893{
2894 switch(o) {
2895 case Invert:
2896 Py_INCREF(Invert_singleton);
2897 return Invert_singleton;
2898 case Not:
2899 Py_INCREF(Not_singleton);
2900 return Not_singleton;
2901 case UAdd:
2902 Py_INCREF(UAdd_singleton);
2903 return UAdd_singleton;
2904 case USub:
2905 Py_INCREF(USub_singleton);
2906 return USub_singleton;
2907 }
2908 return NULL; /* cannot happen */
2909}
2910PyObject* ast2obj_cmpop(cmpop_ty o)
2911{
2912 switch(o) {
2913 case Eq:
2914 Py_INCREF(Eq_singleton);
2915 return Eq_singleton;
2916 case NotEq:
2917 Py_INCREF(NotEq_singleton);
2918 return NotEq_singleton;
2919 case Lt:
2920 Py_INCREF(Lt_singleton);
2921 return Lt_singleton;
2922 case LtE:
2923 Py_INCREF(LtE_singleton);
2924 return LtE_singleton;
2925 case Gt:
2926 Py_INCREF(Gt_singleton);
2927 return Gt_singleton;
2928 case GtE:
2929 Py_INCREF(GtE_singleton);
2930 return GtE_singleton;
2931 case Is:
2932 Py_INCREF(Is_singleton);
2933 return Is_singleton;
2934 case IsNot:
2935 Py_INCREF(IsNot_singleton);
2936 return IsNot_singleton;
2937 case In:
2938 Py_INCREF(In_singleton);
2939 return In_singleton;
2940 case NotIn:
2941 Py_INCREF(NotIn_singleton);
2942 return NotIn_singleton;
2943 }
2944 return NULL; /* cannot happen */
2945}
2946PyObject*
2947ast2obj_comprehension(void* _o)
2948{
2949 comprehension_ty o = (comprehension_ty)_o;
2950 PyObject *result = NULL, *value = NULL;
2951 if (!o) {
2952 Py_INCREF(Py_None);
2953 return Py_None;
2954 }
2955
2956 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2957 if (!result) return NULL;
2958 value = ast2obj_expr(o->target);
2959 if (!value) goto failed;
2960 if (PyObject_SetAttrString(result, "target", value) == -1)
2961 goto failed;
2962 Py_DECREF(value);
2963 value = ast2obj_expr(o->iter);
2964 if (!value) goto failed;
2965 if (PyObject_SetAttrString(result, "iter", value) == -1)
2966 goto failed;
2967 Py_DECREF(value);
2968 value = ast2obj_list(o->ifs, ast2obj_expr);
2969 if (!value) goto failed;
2970 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2971 goto failed;
2972 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002973 return result;
2974failed:
2975 Py_XDECREF(value);
2976 Py_XDECREF(result);
2977 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002978}
2979
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002980PyObject*
2981ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002982{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002983 excepthandler_ty o = (excepthandler_ty)_o;
2984 PyObject *result = NULL, *value = NULL;
2985 if (!o) {
2986 Py_INCREF(Py_None);
2987 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002988 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002989
2990 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2991 if (!result) return NULL;
2992 value = ast2obj_expr(o->type);
2993 if (!value) goto failed;
2994 if (PyObject_SetAttrString(result, "type", value) == -1)
2995 goto failed;
2996 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002997 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002998 if (!value) goto failed;
2999 if (PyObject_SetAttrString(result, "name", value) == -1)
3000 goto failed;
3001 Py_DECREF(value);
3002 value = ast2obj_list(o->body, ast2obj_stmt);
3003 if (!value) goto failed;
3004 if (PyObject_SetAttrString(result, "body", value) == -1)
3005 goto failed;
3006 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003007 value = ast2obj_int(o->lineno);
3008 if (!value) goto failed;
3009 if (PyObject_SetAttrString(result, "lineno", value) == -1)
3010 goto failed;
3011 Py_DECREF(value);
3012 value = ast2obj_int(o->col_offset);
3013 if (!value) goto failed;
3014 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
3015 goto failed;
3016 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003017 return result;
3018failed:
3019 Py_XDECREF(value);
3020 Py_XDECREF(result);
3021 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003022}
3023
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003024PyObject*
3025ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003026{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003027 arguments_ty o = (arguments_ty)_o;
3028 PyObject *result = NULL, *value = NULL;
3029 if (!o) {
3030 Py_INCREF(Py_None);
3031 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003032 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003033
3034 result = PyType_GenericNew(arguments_type, NULL, NULL);
3035 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00003036 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003037 if (!value) goto failed;
3038 if (PyObject_SetAttrString(result, "args", value) == -1)
3039 goto failed;
3040 Py_DECREF(value);
3041 value = ast2obj_identifier(o->vararg);
3042 if (!value) goto failed;
3043 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3044 goto failed;
3045 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003046 value = ast2obj_expr(o->varargannotation);
3047 if (!value) goto failed;
3048 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
3049 goto failed;
3050 Py_DECREF(value);
3051 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003052 if (!value) goto failed;
3053 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
3054 goto failed;
3055 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003056 value = ast2obj_identifier(o->kwarg);
3057 if (!value) goto failed;
3058 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3059 goto failed;
3060 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003061 value = ast2obj_expr(o->kwargannotation);
3062 if (!value) goto failed;
3063 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
3064 goto failed;
3065 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003066 value = ast2obj_list(o->defaults, ast2obj_expr);
3067 if (!value) goto failed;
3068 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3069 goto failed;
3070 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003071 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3072 if (!value) goto failed;
3073 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3074 goto failed;
3075 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003076 return result;
3077failed:
3078 Py_XDECREF(value);
3079 Py_XDECREF(result);
3080 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003081}
3082
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003083PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003084ast2obj_arg(void* _o)
3085{
3086 arg_ty o = (arg_ty)_o;
3087 PyObject *result = NULL, *value = NULL;
3088 if (!o) {
3089 Py_INCREF(Py_None);
3090 return Py_None;
3091 }
3092
Guido van Rossum1bc535d2007-05-15 18:46:22 +00003093 result = PyType_GenericNew(arg_type, NULL, NULL);
3094 if (!result) return NULL;
3095 value = ast2obj_identifier(o->arg);
3096 if (!value) goto failed;
3097 if (PyObject_SetAttrString(result, "arg", value) == -1)
3098 goto failed;
3099 Py_DECREF(value);
3100 value = ast2obj_expr(o->annotation);
3101 if (!value) goto failed;
3102 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3103 goto failed;
3104 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003105 return result;
3106failed:
3107 Py_XDECREF(value);
3108 Py_XDECREF(result);
3109 return NULL;
3110}
3111
3112PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003113ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003114{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003115 keyword_ty o = (keyword_ty)_o;
3116 PyObject *result = NULL, *value = NULL;
3117 if (!o) {
3118 Py_INCREF(Py_None);
3119 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003120 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003121
3122 result = PyType_GenericNew(keyword_type, NULL, NULL);
3123 if (!result) return NULL;
3124 value = ast2obj_identifier(o->arg);
3125 if (!value) goto failed;
3126 if (PyObject_SetAttrString(result, "arg", value) == -1)
3127 goto failed;
3128 Py_DECREF(value);
3129 value = ast2obj_expr(o->value);
3130 if (!value) goto failed;
3131 if (PyObject_SetAttrString(result, "value", value) == -1)
3132 goto failed;
3133 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003134 return result;
3135failed:
3136 Py_XDECREF(value);
3137 Py_XDECREF(result);
3138 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003139}
3140
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003141PyObject*
3142ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003143{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003144 alias_ty o = (alias_ty)_o;
3145 PyObject *result = NULL, *value = NULL;
3146 if (!o) {
3147 Py_INCREF(Py_None);
3148 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003149 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003150
3151 result = PyType_GenericNew(alias_type, NULL, NULL);
3152 if (!result) return NULL;
3153 value = ast2obj_identifier(o->name);
3154 if (!value) goto failed;
3155 if (PyObject_SetAttrString(result, "name", value) == -1)
3156 goto failed;
3157 Py_DECREF(value);
3158 value = ast2obj_identifier(o->asname);
3159 if (!value) goto failed;
3160 if (PyObject_SetAttrString(result, "asname", value) == -1)
3161 goto failed;
3162 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003163 return result;
3164failed:
3165 Py_XDECREF(value);
3166 Py_XDECREF(result);
3167 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003168}
3169
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003170
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003171PyMODINIT_FUNC
3172init_ast(void)
3173{
3174 PyObject *m, *d;
3175 if (!init_types()) return;
3176 m = Py_InitModule3("_ast", NULL, NULL);
3177 if (!m) return;
3178 d = PyModule_GetDict(m);
3179 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3180 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3181 return;
Guido van Rossumc3e7ffc2007-07-11 20:56:15 +00003182 if (PyModule_AddStringConstant(m, "__version__", "56266") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003183 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003184 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3185 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3186 return;
3187 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3188 < 0) return;
3189 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3190 0) return;
3191 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3192 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3193 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3194 < 0) return;
3195 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3196 return;
3197 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3198 return;
3199 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3200 return;
3201 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3202 return;
3203 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3204 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003205 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3206 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3207 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3208 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3209 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3210 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3211 0) return;
3212 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3213 0) return;
3214 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3215 return;
3216 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3217 return;
3218 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3219 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003220 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3221 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003222 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3223 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003224 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3225 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3226 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3227 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3228 return;
3229 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3230 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3231 return;
3232 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3233 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3234 return;
3235 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3236 return;
3237 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3238 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003239 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003240 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3241 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003242 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3243 return;
Guido van Rossum992d4a32007-07-11 13:09:30 +00003244 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
3245 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003246 if (PyDict_SetItemString(d, "GeneratorExp",
3247 (PyObject*)GeneratorExp_type) < 0) return;
3248 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3249 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3250 return;
3251 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003252 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3253 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003254 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003255 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3256 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003257 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3258 0) return;
3259 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3260 0) return;
Guido van Rossum0368b722007-05-11 16:50:42 +00003261 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
3262 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003263 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3264 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3265 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3266 if (PyDict_SetItemString(d, "expr_context",
3267 (PyObject*)expr_context_type) < 0) return;
3268 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3269 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3270 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3271 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3272 return;
3273 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3274 return;
3275 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3276 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003277 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3278 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3279 return;
3280 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3281 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3282 return;
3283 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3284 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3285 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3286 return;
3287 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3288 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3289 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3290 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3291 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3292 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3293 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3294 return;
3295 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3296 return;
3297 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3298 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3299 return;
3300 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3301 return;
3302 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3303 return;
3304 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3305 return;
3306 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3307 return;
3308 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3309 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3310 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3311 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3312 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3313 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3314 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3315 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3316 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3317 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3318 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3319 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3320 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3321 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3322 if (PyDict_SetItemString(d, "comprehension",
3323 (PyObject*)comprehension_type) < 0) return;
3324 if (PyDict_SetItemString(d, "excepthandler",
3325 (PyObject*)excepthandler_type) < 0) return;
3326 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3327 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003328 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003329 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3330 return;
3331 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003332}
3333
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003334
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003335PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003336{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003337 init_types();
3338 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003339}
Martin v. Löwis5b222132007-06-10 09:51:05 +00003340
3341