blob: 18c2eb5d315322079ccae791e1e112bb1ba7c05a [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum6dd15d32007-05-22 18:28:08 +00005 __version__ 55514.
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};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000201static PyTypeObject *GeneratorExp_type;
202static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000203 "elt",
204 "generators",
205};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000206static PyTypeObject *Yield_type;
207static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000208 "value",
209};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000210static PyTypeObject *Compare_type;
211static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000212 "left",
213 "ops",
214 "comparators",
215};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000216static PyTypeObject *Call_type;
217static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000218 "func",
219 "args",
220 "keywords",
221 "starargs",
222 "kwargs",
223};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000224static PyTypeObject *Num_type;
225static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000226 "n",
227};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000228static PyTypeObject *Str_type;
229static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000230 "s",
231};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000232static PyTypeObject *Bytes_type;
233static char *Bytes_fields[]={
234 "s",
235};
Georg Brandl52318d62006-09-06 07:06:08 +0000236static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000237static PyTypeObject *Attribute_type;
238static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000239 "value",
240 "attr",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Subscript_type;
244static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "value",
246 "slice",
247 "ctx",
248};
Guido van Rossum0368b722007-05-11 16:50:42 +0000249static PyTypeObject *Starred_type;
250static char *Starred_fields[]={
251 "value",
252 "ctx",
253};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000254static PyTypeObject *Name_type;
255static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000256 "id",
257 "ctx",
258};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000259static PyTypeObject *List_type;
260static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000261 "elts",
262 "ctx",
263};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000264static PyTypeObject *Tuple_type;
265static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000266 "elts",
267 "ctx",
268};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000270static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
271*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
272static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000273static PyTypeObject *Load_type;
274static PyTypeObject *Store_type;
275static PyTypeObject *Del_type;
276static PyTypeObject *AugLoad_type;
277static PyTypeObject *AugStore_type;
278static PyTypeObject *Param_type;
279static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000280static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000281static PyTypeObject *Slice_type;
282static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000283 "lower",
284 "upper",
285 "step",
286};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000287static PyTypeObject *ExtSlice_type;
288static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000289 "dims",
290};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000291static PyTypeObject *Index_type;
292static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000293 "value",
294};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000295static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000296static PyObject *And_singleton, *Or_singleton;
297static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000298static PyTypeObject *And_type;
299static PyTypeObject *Or_type;
300static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000301static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
302*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
303*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
304*FloorDiv_singleton;
305static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000306static PyTypeObject *Add_type;
307static PyTypeObject *Sub_type;
308static PyTypeObject *Mult_type;
309static PyTypeObject *Div_type;
310static PyTypeObject *Mod_type;
311static PyTypeObject *Pow_type;
312static PyTypeObject *LShift_type;
313static PyTypeObject *RShift_type;
314static PyTypeObject *BitOr_type;
315static PyTypeObject *BitXor_type;
316static PyTypeObject *BitAnd_type;
317static PyTypeObject *FloorDiv_type;
318static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000319static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
320*USub_singleton;
321static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000322static PyTypeObject *Invert_type;
323static PyTypeObject *Not_type;
324static PyTypeObject *UAdd_type;
325static PyTypeObject *USub_type;
326static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000327static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
328*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
329*NotIn_singleton;
330static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000331static PyTypeObject *Eq_type;
332static PyTypeObject *NotEq_type;
333static PyTypeObject *Lt_type;
334static PyTypeObject *LtE_type;
335static PyTypeObject *Gt_type;
336static PyTypeObject *GtE_type;
337static PyTypeObject *Is_type;
338static PyTypeObject *IsNot_type;
339static PyTypeObject *In_type;
340static PyTypeObject *NotIn_type;
341static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000343static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344 "target",
345 "iter",
346 "ifs",
347};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000348static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000349static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000350static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000351 "type",
352 "name",
353 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000354 "lineno",
355 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000356};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000357static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000358static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000359static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000360 "args",
361 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000362 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000363 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000364 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000365 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000366 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000367 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000368};
Neal Norwitzc1505362006-12-28 06:47:50 +0000369static PyTypeObject *arg_type;
370static PyObject* ast2obj_arg(void*);
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000371static char *arg_fields[]={
Neal Norwitzc1505362006-12-28 06:47:50 +0000372 "arg",
373 "annotation",
374};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000375static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000376static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000377static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000378 "arg",
379 "value",
380};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000381static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000382static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000383static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000384 "name",
385 "asname",
386};
387
388
389static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
390{
391 PyObject *fnames, *result;
392 int i;
393 if (num_fields) {
394 fnames = PyTuple_New(num_fields);
395 if (!fnames) return NULL;
396 } else {
397 fnames = Py_None;
398 Py_INCREF(Py_None);
399 }
400 for(i=0; i < num_fields; i++) {
401 PyObject *field = PyString_FromString(fields[i]);
402 if (!field) {
403 Py_DECREF(fnames);
404 return NULL;
405 }
406 PyTuple_SET_ITEM(fnames, i, field);
407 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000408 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000409 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000410 Py_DECREF(fnames);
411 return (PyTypeObject*)result;
412}
413
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000414static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
415{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000416 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000417 PyObject *s, *l = PyList_New(num_fields);
418 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000419 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000420 s = PyString_FromString(attrs[i]);
421 if (!s) {
422 Py_DECREF(l);
423 return 0;
424 }
425 PyList_SET_ITEM(l, i, s);
426 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000427 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
428 Py_DECREF(l);
429 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000430}
431
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000432static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
433{
434 int i, n = asdl_seq_LEN(seq);
435 PyObject *result = PyList_New(n);
436 PyObject *value;
437 if (!result)
438 return NULL;
439 for (i = 0; i < n; i++) {
440 value = func(asdl_seq_GET(seq, i));
441 if (!value) {
442 Py_DECREF(result);
443 return NULL;
444 }
445 PyList_SET_ITEM(result, i, value);
446 }
447 return result;
448}
449
450static PyObject* ast2obj_object(void *o)
451{
452 if (!o)
453 o = Py_None;
454 Py_INCREF((PyObject*)o);
455 return (PyObject*)o;
456}
457#define ast2obj_identifier ast2obj_object
458#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000460static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000461{
462 return PyInt_FromLong(b);
463}
464
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465static int init_types(void)
466{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000467 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000468 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000469 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
470 mod_type = make_type("mod", AST_type, NULL, 0);
471 if (!mod_type) return 0;
472 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 Interactive_type = make_type("Interactive", mod_type,
476 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000477 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000478 Expression_type = make_type("Expression", mod_type, Expression_fields,
479 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!Suite_type) return 0;
483 stmt_type = make_type("stmt", AST_type, NULL, 0);
484 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000485 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000487 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000488 if (!FunctionDef_type) return 0;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000489 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000490 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000505 With_type = make_type("With", stmt_type, With_fields, 3);
506 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000510 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000511 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
512 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000519 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000520 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000521 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000523 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
524 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000527 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000529 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000531 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Continue_type) return 0;
533 expr_type = make_type("expr", AST_type, NULL, 0);
534 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000535 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000536 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000537 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000538 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000539 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000544 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000548 Set_type = make_type("Set", expr_type, Set_fields, 1);
549 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000552 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
553 if (!SetComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 GeneratorExp_type = make_type("GeneratorExp", expr_type,
555 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000556 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000557 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000558 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000559 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000560 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000561 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000562 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000563 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000564 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000565 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000567 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
568 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000569 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
570 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000571 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000573 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Subscript_type) return 0;
Guido van Rossum0368b722007-05-11 16:50:42 +0000575 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
576 if (!Starred_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Tuple_type) return 0;
583 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
584 if (!expr_context_type) return 0;
585 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000586 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000588 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000594 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000598 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000600 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000602 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000604 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000606 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000607 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000608 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000609 if (!Param_singleton) return 0;
610 slice_type = make_type("slice", AST_type, NULL, 0);
611 if (!slice_type) return 0;
612 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Index_type) return 0;
619 boolop_type = make_type("boolop", AST_type, NULL, 0);
620 if (!boolop_type) return 0;
621 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000622 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000624 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000626 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000628 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!Or_singleton) return 0;
630 operator_type = make_type("operator", AST_type, NULL, 0);
631 if (!operator_type) return 0;
632 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000633 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000635 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000637 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000639 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000645 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000647 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000649 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000651 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000653 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000655 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000656 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000657 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000658 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000659 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000660 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000661 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000662 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000663 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000664 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000665 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000667 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!FloorDiv_singleton) return 0;
681 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
682 if (!unaryop_type) return 0;
683 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000684 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000686 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000688 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000690 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000692 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000694 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000696 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000698 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!USub_singleton) return 0;
700 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
701 if (!cmpop_type) return 0;
702 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000703 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000707 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000709 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000711 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000713 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000715 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000717 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000719 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000721 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000722 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000723 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000724 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000725 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000727 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000728 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000729 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000730 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000731 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000732 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000733 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000734 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000735 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000736 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000737 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000738 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000739 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000740 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000741 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000742 if (!NotIn_singleton) return 0;
743 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000744 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000745 if (!comprehension_type) return 0;
746 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000747 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000748 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000749 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000750 if (!arguments_type) return 0;
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000751 arg_type = make_type("arg", AST_type, arg_fields, 2);
Neal Norwitzc1505362006-12-28 06:47:50 +0000752 if (!arg_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000753 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
754 if (!keyword_type) return 0;
755 alias_type = make_type("alias", AST_type, alias_fields, 2);
756 if (!alias_type) return 0;
757 initialized = 1;
758 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000759}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000760
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000762Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763{
764 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000765 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000766 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000768 p->kind = Module_kind;
769 p->v.Module.body = body;
770 return p;
771}
772
773mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000774Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775{
776 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000777 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000778 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000779 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000780 p->kind = Interactive_kind;
781 p->v.Interactive.body = body;
782 return p;
783}
784
785mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000786Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787{
788 mod_ty p;
789 if (!body) {
790 PyErr_SetString(PyExc_ValueError,
791 "field body is required for Expression");
792 return NULL;
793 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000794 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000795 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000796 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000797 p->kind = Expression_kind;
798 p->v.Expression.body = body;
799 return p;
800}
801
802mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000803Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804{
805 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000806 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000807 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000808 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000809 p->kind = Suite_kind;
810 p->v.Suite.body = body;
811 return p;
812}
813
814stmt_ty
815FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000816 decorator_list, expr_ty returns, int lineno, int col_offset,
817 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000818{
819 stmt_ty p;
820 if (!name) {
821 PyErr_SetString(PyExc_ValueError,
822 "field name is required for FunctionDef");
823 return NULL;
824 }
825 if (!args) {
826 PyErr_SetString(PyExc_ValueError,
827 "field args is required for FunctionDef");
828 return NULL;
829 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000830 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000831 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000833 p->kind = FunctionDef_kind;
834 p->v.FunctionDef.name = name;
835 p->v.FunctionDef.args = args;
836 p->v.FunctionDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000837 p->v.FunctionDef.decorator_list = decorator_list;
Neal Norwitzc1505362006-12-28 06:47:50 +0000838 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000839 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000840 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 return p;
842}
843
844stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000845ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000846 starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list,
847 int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000848{
849 stmt_ty p;
850 if (!name) {
851 PyErr_SetString(PyExc_ValueError,
852 "field name is required for ClassDef");
853 return NULL;
854 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000855 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000856 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000857 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858 p->kind = ClassDef_kind;
859 p->v.ClassDef.name = name;
860 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000861 p->v.ClassDef.keywords = keywords;
862 p->v.ClassDef.starargs = starargs;
863 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864 p->v.ClassDef.body = body;
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000865 p->v.ClassDef.decorator_list = decorator_list;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000867 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868 return p;
869}
870
871stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000872Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873{
874 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000875 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000876 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000878 p->kind = Return_kind;
879 p->v.Return.value = value;
880 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882 return p;
883}
884
885stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000886Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887{
888 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000889 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000890 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000891 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000892 p->kind = Delete_kind;
893 p->v.Delete.targets = targets;
894 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000895 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896 return p;
897}
898
899stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000900Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
901 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000902{
903 stmt_ty p;
904 if (!value) {
905 PyErr_SetString(PyExc_ValueError,
906 "field value is required for Assign");
907 return NULL;
908 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000909 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000910 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000911 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000912 p->kind = Assign_kind;
913 p->v.Assign.targets = targets;
914 p->v.Assign.value = value;
915 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000916 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000917 return p;
918}
919
920stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000921AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
922 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000923{
924 stmt_ty p;
925 if (!target) {
926 PyErr_SetString(PyExc_ValueError,
927 "field target is required for AugAssign");
928 return NULL;
929 }
930 if (!op) {
931 PyErr_SetString(PyExc_ValueError,
932 "field op is required for AugAssign");
933 return NULL;
934 }
935 if (!value) {
936 PyErr_SetString(PyExc_ValueError,
937 "field value is required for AugAssign");
938 return NULL;
939 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000940 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000941 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000942 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000943 p->kind = AugAssign_kind;
944 p->v.AugAssign.target = target;
945 p->v.AugAssign.op = op;
946 p->v.AugAssign.value = value;
947 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000948 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949 return p;
950}
951
952stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000953For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000954 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955{
956 stmt_ty p;
957 if (!target) {
958 PyErr_SetString(PyExc_ValueError,
959 "field target is required for For");
960 return NULL;
961 }
962 if (!iter) {
963 PyErr_SetString(PyExc_ValueError,
964 "field iter is required for For");
965 return NULL;
966 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000967 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000968 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000969 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000970 p->kind = For_kind;
971 p->v.For.target = target;
972 p->v.For.iter = iter;
973 p->v.For.body = body;
974 p->v.For.orelse = orelse;
975 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000976 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 return p;
978}
979
980stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000981While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
982 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000983{
984 stmt_ty p;
985 if (!test) {
986 PyErr_SetString(PyExc_ValueError,
987 "field test is required for While");
988 return NULL;
989 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000990 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000991 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000992 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000993 p->kind = While_kind;
994 p->v.While.test = test;
995 p->v.While.body = body;
996 p->v.While.orelse = orelse;
997 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000998 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000999 return p;
1000}
1001
1002stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001003If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1004 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001005{
1006 stmt_ty p;
1007 if (!test) {
1008 PyErr_SetString(PyExc_ValueError,
1009 "field test is required for If");
1010 return NULL;
1011 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001012 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001013 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001014 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001015 p->kind = If_kind;
1016 p->v.If.test = test;
1017 p->v.If.body = body;
1018 p->v.If.orelse = orelse;
1019 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001020 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001021 return p;
1022}
1023
1024stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001026 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001027{
1028 stmt_ty p;
1029 if (!context_expr) {
1030 PyErr_SetString(PyExc_ValueError,
1031 "field context_expr is required for With");
1032 return NULL;
1033 }
1034 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001035 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001036 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001037 p->kind = With_kind;
1038 p->v.With.context_expr = context_expr;
1039 p->v.With.optional_vars = optional_vars;
1040 p->v.With.body = body;
1041 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001042 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001043 return p;
1044}
1045
1046stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001047Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1048 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001049{
1050 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001051 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001052 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001053 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054 p->kind = Raise_kind;
1055 p->v.Raise.type = type;
1056 p->v.Raise.inst = inst;
1057 p->v.Raise.tback = tback;
1058 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001059 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001060 return p;
1061}
1062
1063stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001064TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001065 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001066{
1067 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001068 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001069 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071 p->kind = TryExcept_kind;
1072 p->v.TryExcept.body = body;
1073 p->v.TryExcept.handlers = handlers;
1074 p->v.TryExcept.orelse = orelse;
1075 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001076 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001077 return p;
1078}
1079
1080stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001081TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1082 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001083{
1084 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001085 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001086 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001088 p->kind = TryFinally_kind;
1089 p->v.TryFinally.body = body;
1090 p->v.TryFinally.finalbody = finalbody;
1091 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001092 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001093 return p;
1094}
1095
1096stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001097Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098{
1099 stmt_ty p;
1100 if (!test) {
1101 PyErr_SetString(PyExc_ValueError,
1102 "field test is required for Assert");
1103 return NULL;
1104 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001105 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001106 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001108 p->kind = Assert_kind;
1109 p->v.Assert.test = test;
1110 p->v.Assert.msg = msg;
1111 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001112 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113 return p;
1114}
1115
1116stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001117Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118{
1119 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001120 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001121 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001123 p->kind = Import_kind;
1124 p->v.Import.names = names;
1125 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001126 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001127 return p;
1128}
1129
1130stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001131ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1132 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001133{
1134 stmt_ty p;
1135 if (!module) {
1136 PyErr_SetString(PyExc_ValueError,
1137 "field module is required for ImportFrom");
1138 return NULL;
1139 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001140 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001141 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001142 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001143 p->kind = ImportFrom_kind;
1144 p->v.ImportFrom.module = module;
1145 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001146 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001148 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149 return p;
1150}
1151
1152stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001153Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154{
1155 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001156 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001157 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001158 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 p->kind = Global_kind;
1160 p->v.Global.names = names;
1161 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001162 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 return p;
1164}
1165
1166stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001167Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1168{
1169 stmt_ty p;
1170 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1171 if (!p)
1172 return NULL;
1173 p->kind = Nonlocal_kind;
1174 p->v.Nonlocal.names = names;
1175 p->lineno = lineno;
1176 p->col_offset = col_offset;
1177 return p;
1178}
1179
1180stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001181Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001182{
1183 stmt_ty p;
1184 if (!value) {
1185 PyErr_SetString(PyExc_ValueError,
1186 "field value is required for Expr");
1187 return NULL;
1188 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001189 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001190 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192 p->kind = Expr_kind;
1193 p->v.Expr.value = value;
1194 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001195 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001196 return p;
1197}
1198
1199stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001200Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201{
1202 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001203 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001204 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001205 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 p->kind = Pass_kind;
1207 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001208 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209 return p;
1210}
1211
1212stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001213Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214{
1215 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001216 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001217 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001219 p->kind = Break_kind;
1220 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001221 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return p;
1223}
1224
1225stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001226Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227{
1228 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001229 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001230 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232 p->kind = Continue_kind;
1233 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001234 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235 return p;
1236}
1237
1238expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001239BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1240 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001241{
1242 expr_ty p;
1243 if (!op) {
1244 PyErr_SetString(PyExc_ValueError,
1245 "field op is required for BoolOp");
1246 return NULL;
1247 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001248 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001249 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001251 p->kind = BoolOp_kind;
1252 p->v.BoolOp.op = op;
1253 p->v.BoolOp.values = values;
1254 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001255 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001256 return p;
1257}
1258
1259expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001260BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1261 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001262{
1263 expr_ty p;
1264 if (!left) {
1265 PyErr_SetString(PyExc_ValueError,
1266 "field left is required for BinOp");
1267 return NULL;
1268 }
1269 if (!op) {
1270 PyErr_SetString(PyExc_ValueError,
1271 "field op is required for BinOp");
1272 return NULL;
1273 }
1274 if (!right) {
1275 PyErr_SetString(PyExc_ValueError,
1276 "field right is required for BinOp");
1277 return NULL;
1278 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001279 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001280 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001281 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001282 p->kind = BinOp_kind;
1283 p->v.BinOp.left = left;
1284 p->v.BinOp.op = op;
1285 p->v.BinOp.right = right;
1286 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001287 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001288 return p;
1289}
1290
1291expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001292UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1293 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001294{
1295 expr_ty p;
1296 if (!op) {
1297 PyErr_SetString(PyExc_ValueError,
1298 "field op is required for UnaryOp");
1299 return NULL;
1300 }
1301 if (!operand) {
1302 PyErr_SetString(PyExc_ValueError,
1303 "field operand is required for UnaryOp");
1304 return NULL;
1305 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001306 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001307 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001308 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001309 p->kind = UnaryOp_kind;
1310 p->v.UnaryOp.op = op;
1311 p->v.UnaryOp.operand = operand;
1312 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001313 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001314 return p;
1315}
1316
1317expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001318Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1319 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001320{
1321 expr_ty p;
1322 if (!args) {
1323 PyErr_SetString(PyExc_ValueError,
1324 "field args is required for Lambda");
1325 return NULL;
1326 }
1327 if (!body) {
1328 PyErr_SetString(PyExc_ValueError,
1329 "field body is required for Lambda");
1330 return NULL;
1331 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001332 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001333 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001334 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001335 p->kind = Lambda_kind;
1336 p->v.Lambda.args = args;
1337 p->v.Lambda.body = body;
1338 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001339 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001340 return p;
1341}
1342
1343expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001344IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1345 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001346{
1347 expr_ty p;
1348 if (!test) {
1349 PyErr_SetString(PyExc_ValueError,
1350 "field test is required for IfExp");
1351 return NULL;
1352 }
1353 if (!body) {
1354 PyErr_SetString(PyExc_ValueError,
1355 "field body is required for IfExp");
1356 return NULL;
1357 }
1358 if (!orelse) {
1359 PyErr_SetString(PyExc_ValueError,
1360 "field orelse is required for IfExp");
1361 return NULL;
1362 }
1363 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001364 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001365 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001366 p->kind = IfExp_kind;
1367 p->v.IfExp.test = test;
1368 p->v.IfExp.body = body;
1369 p->v.IfExp.orelse = orelse;
1370 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001371 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001372 return p;
1373}
1374
1375expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001376Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1377 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001378{
1379 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001380 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001381 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001382 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001383 p->kind = Dict_kind;
1384 p->v.Dict.keys = keys;
1385 p->v.Dict.values = values;
1386 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001387 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001388 return p;
1389}
1390
1391expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001392Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1393{
1394 expr_ty p;
1395 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001396 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001397 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001398 p->kind = Set_kind;
1399 p->v.Set.elts = elts;
1400 p->lineno = lineno;
1401 p->col_offset = col_offset;
1402 return p;
1403}
1404
1405expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001406ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1407 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001408{
1409 expr_ty p;
1410 if (!elt) {
1411 PyErr_SetString(PyExc_ValueError,
1412 "field elt is required for ListComp");
1413 return NULL;
1414 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001415 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001416 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001417 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001418 p->kind = ListComp_kind;
1419 p->v.ListComp.elt = elt;
1420 p->v.ListComp.generators = generators;
1421 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001422 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001423 return p;
1424}
1425
1426expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001427SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1428 *arena)
1429{
1430 expr_ty p;
1431 if (!elt) {
1432 PyErr_SetString(PyExc_ValueError,
1433 "field elt is required for SetComp");
1434 return NULL;
1435 }
1436 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1437 if (!p)
1438 return NULL;
1439 p->kind = SetComp_kind;
1440 p->v.SetComp.elt = elt;
1441 p->v.SetComp.generators = generators;
1442 p->lineno = lineno;
1443 p->col_offset = col_offset;
1444 return p;
1445}
1446
1447expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001448GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1449 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001450{
1451 expr_ty p;
1452 if (!elt) {
1453 PyErr_SetString(PyExc_ValueError,
1454 "field elt is required for GeneratorExp");
1455 return NULL;
1456 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001457 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001458 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001459 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001460 p->kind = GeneratorExp_kind;
1461 p->v.GeneratorExp.elt = elt;
1462 p->v.GeneratorExp.generators = generators;
1463 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001464 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001465 return p;
1466}
1467
1468expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001469Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001470{
1471 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001472 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001473 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001474 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475 p->kind = Yield_kind;
1476 p->v.Yield.value = value;
1477 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001478 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479 return p;
1480}
1481
1482expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001483Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1484 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001485{
1486 expr_ty p;
1487 if (!left) {
1488 PyErr_SetString(PyExc_ValueError,
1489 "field left is required for Compare");
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 = Compare_kind;
1496 p->v.Compare.left = left;
1497 p->v.Compare.ops = ops;
1498 p->v.Compare.comparators = comparators;
1499 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001500 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001501 return p;
1502}
1503
1504expr_ty
1505Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001506 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001507{
1508 expr_ty p;
1509 if (!func) {
1510 PyErr_SetString(PyExc_ValueError,
1511 "field func is required for Call");
1512 return NULL;
1513 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001514 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001515 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001517 p->kind = Call_kind;
1518 p->v.Call.func = func;
1519 p->v.Call.args = args;
1520 p->v.Call.keywords = keywords;
1521 p->v.Call.starargs = starargs;
1522 p->v.Call.kwargs = kwargs;
1523 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001524 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001525 return p;
1526}
1527
1528expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001529Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530{
1531 expr_ty p;
1532 if (!n) {
1533 PyErr_SetString(PyExc_ValueError,
1534 "field n is required for Num");
1535 return NULL;
1536 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001537 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001538 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001539 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540 p->kind = Num_kind;
1541 p->v.Num.n = n;
1542 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001543 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001544 return p;
1545}
1546
1547expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001548Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549{
1550 expr_ty p;
1551 if (!s) {
1552 PyErr_SetString(PyExc_ValueError,
1553 "field s is required for Str");
1554 return NULL;
1555 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001556 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001557 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001558 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001559 p->kind = Str_kind;
1560 p->v.Str.s = s;
1561 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001562 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001563 return p;
1564}
1565
1566expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001567Bytes(string s, int lineno, int col_offset, PyArena *arena)
1568{
1569 expr_ty p;
1570 if (!s) {
1571 PyErr_SetString(PyExc_ValueError,
1572 "field s is required for Bytes");
1573 return NULL;
1574 }
1575 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001576 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001577 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001578 p->kind = Bytes_kind;
1579 p->v.Bytes.s = s;
1580 p->lineno = lineno;
1581 p->col_offset = col_offset;
1582 return p;
1583}
1584
1585expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001586Ellipsis(int lineno, int col_offset, PyArena *arena)
1587{
1588 expr_ty p;
1589 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001590 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001591 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001592 p->kind = Ellipsis_kind;
1593 p->lineno = lineno;
1594 p->col_offset = col_offset;
1595 return p;
1596}
1597
1598expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001599Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1600 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001601{
1602 expr_ty p;
1603 if (!value) {
1604 PyErr_SetString(PyExc_ValueError,
1605 "field value is required for Attribute");
1606 return NULL;
1607 }
1608 if (!attr) {
1609 PyErr_SetString(PyExc_ValueError,
1610 "field attr is required for Attribute");
1611 return NULL;
1612 }
1613 if (!ctx) {
1614 PyErr_SetString(PyExc_ValueError,
1615 "field ctx is required for Attribute");
1616 return NULL;
1617 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001618 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001619 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001620 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001621 p->kind = Attribute_kind;
1622 p->v.Attribute.value = value;
1623 p->v.Attribute.attr = attr;
1624 p->v.Attribute.ctx = ctx;
1625 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001626 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 return p;
1628}
1629
1630expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001631Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1632 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001633{
1634 expr_ty p;
1635 if (!value) {
1636 PyErr_SetString(PyExc_ValueError,
1637 "field value is required for Subscript");
1638 return NULL;
1639 }
1640 if (!slice) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field slice is required for Subscript");
1643 return NULL;
1644 }
1645 if (!ctx) {
1646 PyErr_SetString(PyExc_ValueError,
1647 "field ctx is required for Subscript");
1648 return NULL;
1649 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001650 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001651 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 p->kind = Subscript_kind;
1654 p->v.Subscript.value = value;
1655 p->v.Subscript.slice = slice;
1656 p->v.Subscript.ctx = ctx;
1657 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001658 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659 return p;
1660}
1661
1662expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00001663Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
1664 *arena)
1665{
1666 expr_ty p;
1667 if (!value) {
1668 PyErr_SetString(PyExc_ValueError,
1669 "field value is required for Starred");
1670 return NULL;
1671 }
1672 if (!ctx) {
1673 PyErr_SetString(PyExc_ValueError,
1674 "field ctx is required for Starred");
1675 return NULL;
1676 }
1677 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1678 if (!p)
1679 return NULL;
1680 p->kind = Starred_kind;
1681 p->v.Starred.value = value;
1682 p->v.Starred.ctx = ctx;
1683 p->lineno = lineno;
1684 p->col_offset = col_offset;
1685 return p;
1686}
1687
1688expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001689Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1690 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001691{
1692 expr_ty p;
1693 if (!id) {
1694 PyErr_SetString(PyExc_ValueError,
1695 "field id is required for Name");
1696 return NULL;
1697 }
1698 if (!ctx) {
1699 PyErr_SetString(PyExc_ValueError,
1700 "field ctx is required for Name");
1701 return NULL;
1702 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001703 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001704 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001705 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706 p->kind = Name_kind;
1707 p->v.Name.id = id;
1708 p->v.Name.ctx = ctx;
1709 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001710 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001711 return p;
1712}
1713
1714expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001715List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1716 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001717{
1718 expr_ty p;
1719 if (!ctx) {
1720 PyErr_SetString(PyExc_ValueError,
1721 "field ctx is required for List");
1722 return NULL;
1723 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001724 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001725 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001727 p->kind = List_kind;
1728 p->v.List.elts = elts;
1729 p->v.List.ctx = ctx;
1730 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001731 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001732 return p;
1733}
1734
1735expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001736Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1737 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738{
1739 expr_ty p;
1740 if (!ctx) {
1741 PyErr_SetString(PyExc_ValueError,
1742 "field ctx is required for Tuple");
1743 return NULL;
1744 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001745 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001746 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001747 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748 p->kind = Tuple_kind;
1749 p->v.Tuple.elts = elts;
1750 p->v.Tuple.ctx = ctx;
1751 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001752 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 return p;
1754}
1755
1756slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001757Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001758{
1759 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001760 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001761 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763 p->kind = Slice_kind;
1764 p->v.Slice.lower = lower;
1765 p->v.Slice.upper = upper;
1766 p->v.Slice.step = step;
1767 return p;
1768}
1769
1770slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001771ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772{
1773 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001774 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001775 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001777 p->kind = ExtSlice_kind;
1778 p->v.ExtSlice.dims = dims;
1779 return p;
1780}
1781
1782slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001783Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001784{
1785 slice_ty p;
1786 if (!value) {
1787 PyErr_SetString(PyExc_ValueError,
1788 "field value is required for Index");
1789 return NULL;
1790 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001791 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001792 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001793 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 p->kind = Index_kind;
1795 p->v.Index.value = value;
1796 return p;
1797}
1798
1799comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001800comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001801{
1802 comprehension_ty p;
1803 if (!target) {
1804 PyErr_SetString(PyExc_ValueError,
1805 "field target is required for comprehension");
1806 return NULL;
1807 }
1808 if (!iter) {
1809 PyErr_SetString(PyExc_ValueError,
1810 "field iter is required for comprehension");
1811 return NULL;
1812 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001813 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001814 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001816 p->target = target;
1817 p->iter = iter;
1818 p->ifs = ifs;
1819 return p;
1820}
1821
1822excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001823excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001824 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001825{
1826 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001827 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001828 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001830 p->type = type;
1831 p->name = name;
1832 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001833 p->lineno = lineno;
1834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835 return p;
1836}
1837
1838arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001839arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1840 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1841 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001842{
1843 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001844 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001845 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847 p->args = args;
1848 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001849 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001850 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001851 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001852 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001854 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855 return p;
1856}
1857
Neal Norwitzc1505362006-12-28 06:47:50 +00001858arg_ty
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001859arg(identifier arg, expr_ty annotation, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00001860{
1861 arg_ty p;
1862 if (!arg) {
1863 PyErr_SetString(PyExc_ValueError,
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001864 "field arg is required for arg");
Neal Norwitzc1505362006-12-28 06:47:50 +00001865 return NULL;
1866 }
1867 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001868 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001869 return NULL;
Guido van Rossum1bc535d2007-05-15 18:46:22 +00001870 p->arg = arg;
1871 p->annotation = annotation;
Neal Norwitzc1505362006-12-28 06:47:50 +00001872 return p;
1873}
1874
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001875keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001876keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877{
1878 keyword_ty p;
1879 if (!arg) {
1880 PyErr_SetString(PyExc_ValueError,
1881 "field arg is required for keyword");
1882 return NULL;
1883 }
1884 if (!value) {
1885 PyErr_SetString(PyExc_ValueError,
1886 "field value is required for keyword");
1887 return NULL;
1888 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001889 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001890 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001891 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001892 p->arg = arg;
1893 p->value = value;
1894 return p;
1895}
1896
1897alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001898alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899{
1900 alias_ty p;
1901 if (!name) {
1902 PyErr_SetString(PyExc_ValueError,
1903 "field name is required for alias");
1904 return NULL;
1905 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001906 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001907 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001908 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909 p->name = name;
1910 p->asname = asname;
1911 return p;
1912}
1913
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001914
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001915PyObject*
1916ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001917{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001918 mod_ty o = (mod_ty)_o;
1919 PyObject *result = NULL, *value = NULL;
1920 if (!o) {
1921 Py_INCREF(Py_None);
1922 return Py_None;
1923 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001924
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001925 switch (o->kind) {
1926 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001927 result = PyType_GenericNew(Module_type, NULL, NULL);
1928 if (!result) goto failed;
1929 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1930 if (!value) goto failed;
1931 if (PyObject_SetAttrString(result, "body", value) == -1)
1932 goto failed;
1933 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001934 break;
1935 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001936 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1937 if (!result) goto failed;
1938 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1939 if (!value) goto failed;
1940 if (PyObject_SetAttrString(result, "body", value) == -1)
1941 goto failed;
1942 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001943 break;
1944 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001945 result = PyType_GenericNew(Expression_type, NULL, NULL);
1946 if (!result) goto failed;
1947 value = ast2obj_expr(o->v.Expression.body);
1948 if (!value) goto failed;
1949 if (PyObject_SetAttrString(result, "body", value) == -1)
1950 goto failed;
1951 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001952 break;
1953 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001954 result = PyType_GenericNew(Suite_type, NULL, NULL);
1955 if (!result) goto failed;
1956 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1957 if (!value) goto failed;
1958 if (PyObject_SetAttrString(result, "body", value) == -1)
1959 goto failed;
1960 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001961 break;
1962 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001963 return result;
1964failed:
1965 Py_XDECREF(value);
1966 Py_XDECREF(result);
1967 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001968}
1969
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001970PyObject*
1971ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001972{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001973 stmt_ty o = (stmt_ty)_o;
1974 PyObject *result = NULL, *value = NULL;
1975 if (!o) {
1976 Py_INCREF(Py_None);
1977 return Py_None;
1978 }
1979
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001980 switch (o->kind) {
1981 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001982 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1983 if (!result) goto failed;
1984 value = ast2obj_identifier(o->v.FunctionDef.name);
1985 if (!value) goto failed;
1986 if (PyObject_SetAttrString(result, "name", value) == -1)
1987 goto failed;
1988 Py_DECREF(value);
1989 value = ast2obj_arguments(o->v.FunctionDef.args);
1990 if (!value) goto failed;
1991 if (PyObject_SetAttrString(result, "args", value) == -1)
1992 goto failed;
1993 Py_DECREF(value);
1994 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1995 if (!value) goto failed;
1996 if (PyObject_SetAttrString(result, "body", value) == -1)
1997 goto failed;
1998 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00001999 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2000 ast2obj_expr);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002001 if (!value) goto failed;
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002002 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2003 -1)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002004 goto failed;
2005 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002006 value = ast2obj_expr(o->v.FunctionDef.returns);
2007 if (!value) goto failed;
2008 if (PyObject_SetAttrString(result, "returns", value) == -1)
2009 goto failed;
2010 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002011 break;
2012 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002013 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2014 if (!result) goto failed;
2015 value = ast2obj_identifier(o->v.ClassDef.name);
2016 if (!value) goto failed;
2017 if (PyObject_SetAttrString(result, "name", value) == -1)
2018 goto failed;
2019 Py_DECREF(value);
2020 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2021 if (!value) goto failed;
2022 if (PyObject_SetAttrString(result, "bases", value) == -1)
2023 goto failed;
2024 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002025 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2026 if (!value) goto failed;
2027 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2028 goto failed;
2029 Py_DECREF(value);
2030 value = ast2obj_expr(o->v.ClassDef.starargs);
2031 if (!value) goto failed;
2032 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2033 goto failed;
2034 Py_DECREF(value);
2035 value = ast2obj_expr(o->v.ClassDef.kwargs);
2036 if (!value) goto failed;
2037 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2038 goto failed;
2039 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002040 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "body", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
Guido van Rossumd59da4b2007-05-22 18:11:13 +00002045 value = ast2obj_list(o->v.ClassDef.decorator_list,
2046 ast2obj_expr);
2047 if (!value) goto failed;
2048 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2049 -1)
2050 goto failed;
2051 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002052 break;
2053 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002054 result = PyType_GenericNew(Return_type, NULL, NULL);
2055 if (!result) goto failed;
2056 value = ast2obj_expr(o->v.Return.value);
2057 if (!value) goto failed;
2058 if (PyObject_SetAttrString(result, "value", value) == -1)
2059 goto failed;
2060 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061 break;
2062 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002063 result = PyType_GenericNew(Delete_type, NULL, NULL);
2064 if (!result) goto failed;
2065 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "targets", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002070 break;
2071 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002072 result = PyType_GenericNew(Assign_type, NULL, NULL);
2073 if (!result) goto failed;
2074 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2075 if (!value) goto failed;
2076 if (PyObject_SetAttrString(result, "targets", value) == -1)
2077 goto failed;
2078 Py_DECREF(value);
2079 value = ast2obj_expr(o->v.Assign.value);
2080 if (!value) goto failed;
2081 if (PyObject_SetAttrString(result, "value", value) == -1)
2082 goto failed;
2083 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002084 break;
2085 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002086 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2087 if (!result) goto failed;
2088 value = ast2obj_expr(o->v.AugAssign.target);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "target", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
2093 value = ast2obj_operator(o->v.AugAssign.op);
2094 if (!value) goto failed;
2095 if (PyObject_SetAttrString(result, "op", value) == -1)
2096 goto failed;
2097 Py_DECREF(value);
2098 value = ast2obj_expr(o->v.AugAssign.value);
2099 if (!value) goto failed;
2100 if (PyObject_SetAttrString(result, "value", value) == -1)
2101 goto failed;
2102 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002103 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002104 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002105 result = PyType_GenericNew(For_type, NULL, NULL);
2106 if (!result) goto failed;
2107 value = ast2obj_expr(o->v.For.target);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "target", value) == -1)
2110 goto failed;
2111 Py_DECREF(value);
2112 value = ast2obj_expr(o->v.For.iter);
2113 if (!value) goto failed;
2114 if (PyObject_SetAttrString(result, "iter", value) == -1)
2115 goto failed;
2116 Py_DECREF(value);
2117 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2118 if (!value) goto failed;
2119 if (PyObject_SetAttrString(result, "body", value) == -1)
2120 goto failed;
2121 Py_DECREF(value);
2122 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2123 if (!value) goto failed;
2124 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2125 goto failed;
2126 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002127 break;
2128 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002129 result = PyType_GenericNew(While_type, NULL, NULL);
2130 if (!result) goto failed;
2131 value = ast2obj_expr(o->v.While.test);
2132 if (!value) goto failed;
2133 if (PyObject_SetAttrString(result, "test", value) == -1)
2134 goto failed;
2135 Py_DECREF(value);
2136 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2137 if (!value) goto failed;
2138 if (PyObject_SetAttrString(result, "body", value) == -1)
2139 goto failed;
2140 Py_DECREF(value);
2141 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2142 if (!value) goto failed;
2143 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2144 goto failed;
2145 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002146 break;
2147 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002148 result = PyType_GenericNew(If_type, NULL, NULL);
2149 if (!result) goto failed;
2150 value = ast2obj_expr(o->v.If.test);
2151 if (!value) goto failed;
2152 if (PyObject_SetAttrString(result, "test", value) == -1)
2153 goto failed;
2154 Py_DECREF(value);
2155 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2156 if (!value) goto failed;
2157 if (PyObject_SetAttrString(result, "body", value) == -1)
2158 goto failed;
2159 Py_DECREF(value);
2160 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2161 if (!value) goto failed;
2162 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2163 goto failed;
2164 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002165 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002166 case With_kind:
2167 result = PyType_GenericNew(With_type, NULL, NULL);
2168 if (!result) goto failed;
2169 value = ast2obj_expr(o->v.With.context_expr);
2170 if (!value) goto failed;
2171 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2172 goto failed;
2173 Py_DECREF(value);
2174 value = ast2obj_expr(o->v.With.optional_vars);
2175 if (!value) goto failed;
2176 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2177 -1)
2178 goto failed;
2179 Py_DECREF(value);
2180 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2181 if (!value) goto failed;
2182 if (PyObject_SetAttrString(result, "body", value) == -1)
2183 goto failed;
2184 Py_DECREF(value);
2185 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002186 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002187 result = PyType_GenericNew(Raise_type, NULL, NULL);
2188 if (!result) goto failed;
2189 value = ast2obj_expr(o->v.Raise.type);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "type", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
2194 value = ast2obj_expr(o->v.Raise.inst);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "inst", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 value = ast2obj_expr(o->v.Raise.tback);
2200 if (!value) goto failed;
2201 if (PyObject_SetAttrString(result, "tback", value) == -1)
2202 goto failed;
2203 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002204 break;
2205 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002206 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2207 if (!result) goto failed;
2208 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "body", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
2213 value = ast2obj_list(o->v.TryExcept.handlers,
2214 ast2obj_excepthandler);
2215 if (!value) goto failed;
2216 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2217 goto failed;
2218 Py_DECREF(value);
2219 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2220 if (!value) goto failed;
2221 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2222 goto failed;
2223 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002224 break;
2225 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002226 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2227 if (!result) goto failed;
2228 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2229 if (!value) goto failed;
2230 if (PyObject_SetAttrString(result, "body", value) == -1)
2231 goto failed;
2232 Py_DECREF(value);
2233 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2234 if (!value) goto failed;
2235 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2236 goto failed;
2237 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002238 break;
2239 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002240 result = PyType_GenericNew(Assert_type, NULL, NULL);
2241 if (!result) goto failed;
2242 value = ast2obj_expr(o->v.Assert.test);
2243 if (!value) goto failed;
2244 if (PyObject_SetAttrString(result, "test", value) == -1)
2245 goto failed;
2246 Py_DECREF(value);
2247 value = ast2obj_expr(o->v.Assert.msg);
2248 if (!value) goto failed;
2249 if (PyObject_SetAttrString(result, "msg", value) == -1)
2250 goto failed;
2251 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002252 break;
2253 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002254 result = PyType_GenericNew(Import_type, NULL, NULL);
2255 if (!result) goto failed;
2256 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2257 if (!value) goto failed;
2258 if (PyObject_SetAttrString(result, "names", value) == -1)
2259 goto failed;
2260 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002261 break;
2262 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002263 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2264 if (!result) goto failed;
2265 value = ast2obj_identifier(o->v.ImportFrom.module);
2266 if (!value) goto failed;
2267 if (PyObject_SetAttrString(result, "module", value) == -1)
2268 goto failed;
2269 Py_DECREF(value);
2270 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2271 if (!value) goto failed;
2272 if (PyObject_SetAttrString(result, "names", value) == -1)
2273 goto failed;
2274 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002275 value = ast2obj_int(o->v.ImportFrom.level);
2276 if (!value) goto failed;
2277 if (PyObject_SetAttrString(result, "level", value) == -1)
2278 goto failed;
2279 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002280 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002281 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002282 result = PyType_GenericNew(Global_type, NULL, NULL);
2283 if (!result) goto failed;
2284 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2285 if (!value) goto failed;
2286 if (PyObject_SetAttrString(result, "names", value) == -1)
2287 goto failed;
2288 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002289 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002290 case Nonlocal_kind:
2291 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2292 if (!result) goto failed;
2293 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2294 if (!value) goto failed;
2295 if (PyObject_SetAttrString(result, "names", value) == -1)
2296 goto failed;
2297 Py_DECREF(value);
2298 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002299 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002300 result = PyType_GenericNew(Expr_type, NULL, NULL);
2301 if (!result) goto failed;
2302 value = ast2obj_expr(o->v.Expr.value);
2303 if (!value) goto failed;
2304 if (PyObject_SetAttrString(result, "value", value) == -1)
2305 goto failed;
2306 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002307 break;
2308 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002309 result = PyType_GenericNew(Pass_type, NULL, NULL);
2310 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002311 break;
2312 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002313 result = PyType_GenericNew(Break_type, NULL, NULL);
2314 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002315 break;
2316 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002317 result = PyType_GenericNew(Continue_type, NULL, NULL);
2318 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319 break;
2320 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002321 value = ast2obj_int(o->lineno);
2322 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002323 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2324 goto failed;
2325 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002326 value = ast2obj_int(o->col_offset);
2327 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002328 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2329 goto failed;
2330 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002331 return result;
2332failed:
2333 Py_XDECREF(value);
2334 Py_XDECREF(result);
2335 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002336}
2337
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002338PyObject*
2339ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002340{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002341 expr_ty o = (expr_ty)_o;
2342 PyObject *result = NULL, *value = NULL;
2343 if (!o) {
2344 Py_INCREF(Py_None);
2345 return Py_None;
2346 }
2347
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002348 switch (o->kind) {
2349 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002350 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2351 if (!result) goto failed;
2352 value = ast2obj_boolop(o->v.BoolOp.op);
2353 if (!value) goto failed;
2354 if (PyObject_SetAttrString(result, "op", value) == -1)
2355 goto failed;
2356 Py_DECREF(value);
2357 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2358 if (!value) goto failed;
2359 if (PyObject_SetAttrString(result, "values", value) == -1)
2360 goto failed;
2361 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002362 break;
2363 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002364 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2365 if (!result) goto failed;
2366 value = ast2obj_expr(o->v.BinOp.left);
2367 if (!value) goto failed;
2368 if (PyObject_SetAttrString(result, "left", value) == -1)
2369 goto failed;
2370 Py_DECREF(value);
2371 value = ast2obj_operator(o->v.BinOp.op);
2372 if (!value) goto failed;
2373 if (PyObject_SetAttrString(result, "op", value) == -1)
2374 goto failed;
2375 Py_DECREF(value);
2376 value = ast2obj_expr(o->v.BinOp.right);
2377 if (!value) goto failed;
2378 if (PyObject_SetAttrString(result, "right", value) == -1)
2379 goto failed;
2380 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002381 break;
2382 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002383 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2384 if (!result) goto failed;
2385 value = ast2obj_unaryop(o->v.UnaryOp.op);
2386 if (!value) goto failed;
2387 if (PyObject_SetAttrString(result, "op", value) == -1)
2388 goto failed;
2389 Py_DECREF(value);
2390 value = ast2obj_expr(o->v.UnaryOp.operand);
2391 if (!value) goto failed;
2392 if (PyObject_SetAttrString(result, "operand", value) == -1)
2393 goto failed;
2394 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002395 break;
2396 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002397 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2398 if (!result) goto failed;
2399 value = ast2obj_arguments(o->v.Lambda.args);
2400 if (!value) goto failed;
2401 if (PyObject_SetAttrString(result, "args", value) == -1)
2402 goto failed;
2403 Py_DECREF(value);
2404 value = ast2obj_expr(o->v.Lambda.body);
2405 if (!value) goto failed;
2406 if (PyObject_SetAttrString(result, "body", value) == -1)
2407 goto failed;
2408 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002409 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002410 case IfExp_kind:
2411 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2412 if (!result) goto failed;
2413 value = ast2obj_expr(o->v.IfExp.test);
2414 if (!value) goto failed;
2415 if (PyObject_SetAttrString(result, "test", value) == -1)
2416 goto failed;
2417 Py_DECREF(value);
2418 value = ast2obj_expr(o->v.IfExp.body);
2419 if (!value) goto failed;
2420 if (PyObject_SetAttrString(result, "body", value) == -1)
2421 goto failed;
2422 Py_DECREF(value);
2423 value = ast2obj_expr(o->v.IfExp.orelse);
2424 if (!value) goto failed;
2425 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2426 goto failed;
2427 Py_DECREF(value);
2428 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002429 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002430 result = PyType_GenericNew(Dict_type, NULL, NULL);
2431 if (!result) goto failed;
2432 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2433 if (!value) goto failed;
2434 if (PyObject_SetAttrString(result, "keys", value) == -1)
2435 goto failed;
2436 Py_DECREF(value);
2437 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2438 if (!value) goto failed;
2439 if (PyObject_SetAttrString(result, "values", value) == -1)
2440 goto failed;
2441 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002443 case Set_kind:
2444 result = PyType_GenericNew(Set_type, NULL, NULL);
2445 if (!result) goto failed;
2446 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "elts", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
2451 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002452 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002453 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2454 if (!result) goto failed;
2455 value = ast2obj_expr(o->v.ListComp.elt);
2456 if (!value) goto failed;
2457 if (PyObject_SetAttrString(result, "elt", value) == -1)
2458 goto failed;
2459 Py_DECREF(value);
2460 value = ast2obj_list(o->v.ListComp.generators,
2461 ast2obj_comprehension);
2462 if (!value) goto failed;
2463 if (PyObject_SetAttrString(result, "generators", value) == -1)
2464 goto failed;
2465 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002466 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002467 case SetComp_kind:
2468 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2469 if (!result) goto failed;
2470 value = ast2obj_expr(o->v.SetComp.elt);
2471 if (!value) goto failed;
2472 if (PyObject_SetAttrString(result, "elt", value) == -1)
2473 goto failed;
2474 Py_DECREF(value);
2475 value = ast2obj_list(o->v.SetComp.generators,
2476 ast2obj_comprehension);
2477 if (!value) goto failed;
2478 if (PyObject_SetAttrString(result, "generators", value) == -1)
2479 goto failed;
2480 Py_DECREF(value);
2481 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002482 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002483 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2484 if (!result) goto failed;
2485 value = ast2obj_expr(o->v.GeneratorExp.elt);
2486 if (!value) goto failed;
2487 if (PyObject_SetAttrString(result, "elt", value) == -1)
2488 goto failed;
2489 Py_DECREF(value);
2490 value = ast2obj_list(o->v.GeneratorExp.generators,
2491 ast2obj_comprehension);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "generators", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496 break;
2497 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002498 result = PyType_GenericNew(Yield_type, NULL, NULL);
2499 if (!result) goto failed;
2500 value = ast2obj_expr(o->v.Yield.value);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "value", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505 break;
2506 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Compare_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_expr(o->v.Compare.left);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "left", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002514 {
2515 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2516 value = PyList_New(n);
2517 if (!value) goto failed;
2518 for(i = 0; i < n; i++)
2519 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2520 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002521 if (!value) goto failed;
2522 if (PyObject_SetAttrString(result, "ops", value) == -1)
2523 goto failed;
2524 Py_DECREF(value);
2525 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2526 if (!value) goto failed;
2527 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2528 goto failed;
2529 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002530 break;
2531 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002532 result = PyType_GenericNew(Call_type, NULL, NULL);
2533 if (!result) goto failed;
2534 value = ast2obj_expr(o->v.Call.func);
2535 if (!value) goto failed;
2536 if (PyObject_SetAttrString(result, "func", value) == -1)
2537 goto failed;
2538 Py_DECREF(value);
2539 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2540 if (!value) goto failed;
2541 if (PyObject_SetAttrString(result, "args", value) == -1)
2542 goto failed;
2543 Py_DECREF(value);
2544 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2545 if (!value) goto failed;
2546 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2547 goto failed;
2548 Py_DECREF(value);
2549 value = ast2obj_expr(o->v.Call.starargs);
2550 if (!value) goto failed;
2551 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2552 goto failed;
2553 Py_DECREF(value);
2554 value = ast2obj_expr(o->v.Call.kwargs);
2555 if (!value) goto failed;
2556 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2557 goto failed;
2558 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002559 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002560 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002561 result = PyType_GenericNew(Num_type, NULL, NULL);
2562 if (!result) goto failed;
2563 value = ast2obj_object(o->v.Num.n);
2564 if (!value) goto failed;
2565 if (PyObject_SetAttrString(result, "n", value) == -1)
2566 goto failed;
2567 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002568 break;
2569 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002570 result = PyType_GenericNew(Str_type, NULL, NULL);
2571 if (!result) goto failed;
2572 value = ast2obj_string(o->v.Str.s);
2573 if (!value) goto failed;
2574 if (PyObject_SetAttrString(result, "s", value) == -1)
2575 goto failed;
2576 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002577 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002578 case Bytes_kind:
2579 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2580 if (!result) goto failed;
2581 value = ast2obj_string(o->v.Bytes.s);
2582 if (!value) goto failed;
2583 if (PyObject_SetAttrString(result, "s", value) == -1)
2584 goto failed;
2585 Py_DECREF(value);
2586 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002587 case Ellipsis_kind:
2588 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2589 if (!result) goto failed;
2590 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002591 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002592 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2593 if (!result) goto failed;
2594 value = ast2obj_expr(o->v.Attribute.value);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "value", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 value = ast2obj_identifier(o->v.Attribute.attr);
2600 if (!value) goto failed;
2601 if (PyObject_SetAttrString(result, "attr", value) == -1)
2602 goto failed;
2603 Py_DECREF(value);
2604 value = ast2obj_expr_context(o->v.Attribute.ctx);
2605 if (!value) goto failed;
2606 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2607 goto failed;
2608 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002609 break;
2610 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002611 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2612 if (!result) goto failed;
2613 value = ast2obj_expr(o->v.Subscript.value);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "value", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
2618 value = ast2obj_slice(o->v.Subscript.slice);
2619 if (!value) goto failed;
2620 if (PyObject_SetAttrString(result, "slice", value) == -1)
2621 goto failed;
2622 Py_DECREF(value);
2623 value = ast2obj_expr_context(o->v.Subscript.ctx);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002628 break;
Guido van Rossum0368b722007-05-11 16:50:42 +00002629 case Starred_kind:
2630 result = PyType_GenericNew(Starred_type, NULL, NULL);
2631 if (!result) goto failed;
2632 value = ast2obj_expr(o->v.Starred.value);
2633 if (!value) goto failed;
2634 if (PyObject_SetAttrString(result, "value", value) == -1)
2635 goto failed;
2636 Py_DECREF(value);
2637 value = ast2obj_expr_context(o->v.Starred.ctx);
2638 if (!value) goto failed;
2639 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2640 goto failed;
2641 Py_DECREF(value);
2642 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002643 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002644 result = PyType_GenericNew(Name_type, NULL, NULL);
2645 if (!result) goto failed;
2646 value = ast2obj_identifier(o->v.Name.id);
2647 if (!value) goto failed;
2648 if (PyObject_SetAttrString(result, "id", value) == -1)
2649 goto failed;
2650 Py_DECREF(value);
2651 value = ast2obj_expr_context(o->v.Name.ctx);
2652 if (!value) goto failed;
2653 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2654 goto failed;
2655 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656 break;
2657 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 result = PyType_GenericNew(List_type, NULL, NULL);
2659 if (!result) goto failed;
2660 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2661 if (!value) goto failed;
2662 if (PyObject_SetAttrString(result, "elts", value) == -1)
2663 goto failed;
2664 Py_DECREF(value);
2665 value = ast2obj_expr_context(o->v.List.ctx);
2666 if (!value) goto failed;
2667 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2668 goto failed;
2669 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002670 break;
2671 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002672 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2673 if (!result) goto failed;
2674 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2675 if (!value) goto failed;
2676 if (PyObject_SetAttrString(result, "elts", value) == -1)
2677 goto failed;
2678 Py_DECREF(value);
2679 value = ast2obj_expr_context(o->v.Tuple.ctx);
2680 if (!value) goto failed;
2681 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2682 goto failed;
2683 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002684 break;
2685 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002686 value = ast2obj_int(o->lineno);
2687 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002688 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2689 goto failed;
2690 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002691 value = ast2obj_int(o->col_offset);
2692 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002693 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2694 goto failed;
2695 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002696 return result;
2697failed:
2698 Py_XDECREF(value);
2699 Py_XDECREF(result);
2700 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002701}
2702
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002703PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002704{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002705 switch(o) {
2706 case Load:
2707 Py_INCREF(Load_singleton);
2708 return Load_singleton;
2709 case Store:
2710 Py_INCREF(Store_singleton);
2711 return Store_singleton;
2712 case Del:
2713 Py_INCREF(Del_singleton);
2714 return Del_singleton;
2715 case AugLoad:
2716 Py_INCREF(AugLoad_singleton);
2717 return AugLoad_singleton;
2718 case AugStore:
2719 Py_INCREF(AugStore_singleton);
2720 return AugStore_singleton;
2721 case Param:
2722 Py_INCREF(Param_singleton);
2723 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002724 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002725 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002726}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002727PyObject*
2728ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002729{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002730 slice_ty o = (slice_ty)_o;
2731 PyObject *result = NULL, *value = NULL;
2732 if (!o) {
2733 Py_INCREF(Py_None);
2734 return Py_None;
2735 }
2736
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002737 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002738 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002739 result = PyType_GenericNew(Slice_type, NULL, NULL);
2740 if (!result) goto failed;
2741 value = ast2obj_expr(o->v.Slice.lower);
2742 if (!value) goto failed;
2743 if (PyObject_SetAttrString(result, "lower", value) == -1)
2744 goto failed;
2745 Py_DECREF(value);
2746 value = ast2obj_expr(o->v.Slice.upper);
2747 if (!value) goto failed;
2748 if (PyObject_SetAttrString(result, "upper", value) == -1)
2749 goto failed;
2750 Py_DECREF(value);
2751 value = ast2obj_expr(o->v.Slice.step);
2752 if (!value) goto failed;
2753 if (PyObject_SetAttrString(result, "step", value) == -1)
2754 goto failed;
2755 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002756 break;
2757 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002758 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2759 if (!result) goto failed;
2760 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2761 if (!value) goto failed;
2762 if (PyObject_SetAttrString(result, "dims", value) == -1)
2763 goto failed;
2764 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002765 break;
2766 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002767 result = PyType_GenericNew(Index_type, NULL, NULL);
2768 if (!result) goto failed;
2769 value = ast2obj_expr(o->v.Index.value);
2770 if (!value) goto failed;
2771 if (PyObject_SetAttrString(result, "value", value) == -1)
2772 goto failed;
2773 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002774 break;
2775 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002776 return result;
2777failed:
2778 Py_XDECREF(value);
2779 Py_XDECREF(result);
2780 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002781}
2782
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002783PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002784{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002785 switch(o) {
2786 case And:
2787 Py_INCREF(And_singleton);
2788 return And_singleton;
2789 case Or:
2790 Py_INCREF(Or_singleton);
2791 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002792 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002793 return NULL; /* cannot happen */
2794}
2795PyObject* ast2obj_operator(operator_ty o)
2796{
2797 switch(o) {
2798 case Add:
2799 Py_INCREF(Add_singleton);
2800 return Add_singleton;
2801 case Sub:
2802 Py_INCREF(Sub_singleton);
2803 return Sub_singleton;
2804 case Mult:
2805 Py_INCREF(Mult_singleton);
2806 return Mult_singleton;
2807 case Div:
2808 Py_INCREF(Div_singleton);
2809 return Div_singleton;
2810 case Mod:
2811 Py_INCREF(Mod_singleton);
2812 return Mod_singleton;
2813 case Pow:
2814 Py_INCREF(Pow_singleton);
2815 return Pow_singleton;
2816 case LShift:
2817 Py_INCREF(LShift_singleton);
2818 return LShift_singleton;
2819 case RShift:
2820 Py_INCREF(RShift_singleton);
2821 return RShift_singleton;
2822 case BitOr:
2823 Py_INCREF(BitOr_singleton);
2824 return BitOr_singleton;
2825 case BitXor:
2826 Py_INCREF(BitXor_singleton);
2827 return BitXor_singleton;
2828 case BitAnd:
2829 Py_INCREF(BitAnd_singleton);
2830 return BitAnd_singleton;
2831 case FloorDiv:
2832 Py_INCREF(FloorDiv_singleton);
2833 return FloorDiv_singleton;
2834 }
2835 return NULL; /* cannot happen */
2836}
2837PyObject* ast2obj_unaryop(unaryop_ty o)
2838{
2839 switch(o) {
2840 case Invert:
2841 Py_INCREF(Invert_singleton);
2842 return Invert_singleton;
2843 case Not:
2844 Py_INCREF(Not_singleton);
2845 return Not_singleton;
2846 case UAdd:
2847 Py_INCREF(UAdd_singleton);
2848 return UAdd_singleton;
2849 case USub:
2850 Py_INCREF(USub_singleton);
2851 return USub_singleton;
2852 }
2853 return NULL; /* cannot happen */
2854}
2855PyObject* ast2obj_cmpop(cmpop_ty o)
2856{
2857 switch(o) {
2858 case Eq:
2859 Py_INCREF(Eq_singleton);
2860 return Eq_singleton;
2861 case NotEq:
2862 Py_INCREF(NotEq_singleton);
2863 return NotEq_singleton;
2864 case Lt:
2865 Py_INCREF(Lt_singleton);
2866 return Lt_singleton;
2867 case LtE:
2868 Py_INCREF(LtE_singleton);
2869 return LtE_singleton;
2870 case Gt:
2871 Py_INCREF(Gt_singleton);
2872 return Gt_singleton;
2873 case GtE:
2874 Py_INCREF(GtE_singleton);
2875 return GtE_singleton;
2876 case Is:
2877 Py_INCREF(Is_singleton);
2878 return Is_singleton;
2879 case IsNot:
2880 Py_INCREF(IsNot_singleton);
2881 return IsNot_singleton;
2882 case In:
2883 Py_INCREF(In_singleton);
2884 return In_singleton;
2885 case NotIn:
2886 Py_INCREF(NotIn_singleton);
2887 return NotIn_singleton;
2888 }
2889 return NULL; /* cannot happen */
2890}
2891PyObject*
2892ast2obj_comprehension(void* _o)
2893{
2894 comprehension_ty o = (comprehension_ty)_o;
2895 PyObject *result = NULL, *value = NULL;
2896 if (!o) {
2897 Py_INCREF(Py_None);
2898 return Py_None;
2899 }
2900
2901 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2902 if (!result) return NULL;
2903 value = ast2obj_expr(o->target);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "target", value) == -1)
2906 goto failed;
2907 Py_DECREF(value);
2908 value = ast2obj_expr(o->iter);
2909 if (!value) goto failed;
2910 if (PyObject_SetAttrString(result, "iter", value) == -1)
2911 goto failed;
2912 Py_DECREF(value);
2913 value = ast2obj_list(o->ifs, ast2obj_expr);
2914 if (!value) goto failed;
2915 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2916 goto failed;
2917 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002918 return result;
2919failed:
2920 Py_XDECREF(value);
2921 Py_XDECREF(result);
2922 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923}
2924
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002925PyObject*
2926ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002927{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002928 excepthandler_ty o = (excepthandler_ty)_o;
2929 PyObject *result = NULL, *value = NULL;
2930 if (!o) {
2931 Py_INCREF(Py_None);
2932 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002933 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934
2935 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2936 if (!result) return NULL;
2937 value = ast2obj_expr(o->type);
2938 if (!value) goto failed;
2939 if (PyObject_SetAttrString(result, "type", value) == -1)
2940 goto failed;
2941 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002942 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002943 if (!value) goto failed;
2944 if (PyObject_SetAttrString(result, "name", value) == -1)
2945 goto failed;
2946 Py_DECREF(value);
2947 value = ast2obj_list(o->body, ast2obj_stmt);
2948 if (!value) goto failed;
2949 if (PyObject_SetAttrString(result, "body", value) == -1)
2950 goto failed;
2951 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002952 value = ast2obj_int(o->lineno);
2953 if (!value) goto failed;
2954 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2955 goto failed;
2956 Py_DECREF(value);
2957 value = ast2obj_int(o->col_offset);
2958 if (!value) goto failed;
2959 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2960 goto failed;
2961 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002962 return result;
2963failed:
2964 Py_XDECREF(value);
2965 Py_XDECREF(result);
2966 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002967}
2968
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002969PyObject*
2970ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002971{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002972 arguments_ty o = (arguments_ty)_o;
2973 PyObject *result = NULL, *value = NULL;
2974 if (!o) {
2975 Py_INCREF(Py_None);
2976 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002977 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002978
2979 result = PyType_GenericNew(arguments_type, NULL, NULL);
2980 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002981 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002982 if (!value) goto failed;
2983 if (PyObject_SetAttrString(result, "args", value) == -1)
2984 goto failed;
2985 Py_DECREF(value);
2986 value = ast2obj_identifier(o->vararg);
2987 if (!value) goto failed;
2988 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2989 goto failed;
2990 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002991 value = ast2obj_expr(o->varargannotation);
2992 if (!value) goto failed;
2993 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2994 goto failed;
2995 Py_DECREF(value);
2996 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002997 if (!value) goto failed;
2998 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2999 goto failed;
3000 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003001 value = ast2obj_identifier(o->kwarg);
3002 if (!value) goto failed;
3003 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3004 goto failed;
3005 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003006 value = ast2obj_expr(o->kwargannotation);
3007 if (!value) goto failed;
3008 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
3009 goto failed;
3010 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003011 value = ast2obj_list(o->defaults, ast2obj_expr);
3012 if (!value) goto failed;
3013 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3014 goto failed;
3015 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003016 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3017 if (!value) goto failed;
3018 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3019 goto failed;
3020 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003021 return result;
3022failed:
3023 Py_XDECREF(value);
3024 Py_XDECREF(result);
3025 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003026}
3027
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003028PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003029ast2obj_arg(void* _o)
3030{
3031 arg_ty o = (arg_ty)_o;
3032 PyObject *result = NULL, *value = NULL;
3033 if (!o) {
3034 Py_INCREF(Py_None);
3035 return Py_None;
3036 }
3037
Guido van Rossum1bc535d2007-05-15 18:46:22 +00003038 result = PyType_GenericNew(arg_type, NULL, NULL);
3039 if (!result) return NULL;
3040 value = ast2obj_identifier(o->arg);
3041 if (!value) goto failed;
3042 if (PyObject_SetAttrString(result, "arg", value) == -1)
3043 goto failed;
3044 Py_DECREF(value);
3045 value = ast2obj_expr(o->annotation);
3046 if (!value) goto failed;
3047 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3048 goto failed;
3049 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00003050 return result;
3051failed:
3052 Py_XDECREF(value);
3053 Py_XDECREF(result);
3054 return NULL;
3055}
3056
3057PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003058ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003059{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003060 keyword_ty o = (keyword_ty)_o;
3061 PyObject *result = NULL, *value = NULL;
3062 if (!o) {
3063 Py_INCREF(Py_None);
3064 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003065 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003066
3067 result = PyType_GenericNew(keyword_type, NULL, NULL);
3068 if (!result) return NULL;
3069 value = ast2obj_identifier(o->arg);
3070 if (!value) goto failed;
3071 if (PyObject_SetAttrString(result, "arg", value) == -1)
3072 goto failed;
3073 Py_DECREF(value);
3074 value = ast2obj_expr(o->value);
3075 if (!value) goto failed;
3076 if (PyObject_SetAttrString(result, "value", value) == -1)
3077 goto failed;
3078 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003079 return result;
3080failed:
3081 Py_XDECREF(value);
3082 Py_XDECREF(result);
3083 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003084}
3085
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003086PyObject*
3087ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003088{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003089 alias_ty o = (alias_ty)_o;
3090 PyObject *result = NULL, *value = NULL;
3091 if (!o) {
3092 Py_INCREF(Py_None);
3093 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003094 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003095
3096 result = PyType_GenericNew(alias_type, NULL, NULL);
3097 if (!result) return NULL;
3098 value = ast2obj_identifier(o->name);
3099 if (!value) goto failed;
3100 if (PyObject_SetAttrString(result, "name", value) == -1)
3101 goto failed;
3102 Py_DECREF(value);
3103 value = ast2obj_identifier(o->asname);
3104 if (!value) goto failed;
3105 if (PyObject_SetAttrString(result, "asname", value) == -1)
3106 goto failed;
3107 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003108 return result;
3109failed:
3110 Py_XDECREF(value);
3111 Py_XDECREF(result);
3112 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003113}
3114
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003115
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003116PyMODINIT_FUNC
3117init_ast(void)
3118{
3119 PyObject *m, *d;
3120 if (!init_types()) return;
3121 m = Py_InitModule3("_ast", NULL, NULL);
3122 if (!m) return;
3123 d = PyModule_GetDict(m);
3124 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3125 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3126 return;
Guido van Rossum6dd15d32007-05-22 18:28:08 +00003127 if (PyModule_AddStringConstant(m, "__version__", "55514") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003128 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003129 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3130 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3131 return;
3132 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3133 < 0) return;
3134 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3135 0) return;
3136 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3137 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3138 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3139 < 0) return;
3140 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3141 return;
3142 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3143 return;
3144 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3145 return;
3146 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3147 return;
3148 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3149 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003150 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3151 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3152 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3153 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3154 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3155 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3156 0) return;
3157 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3158 0) return;
3159 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3160 return;
3161 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3162 return;
3163 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3164 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003165 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3166 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003167 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3168 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003169 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3170 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3172 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3173 return;
3174 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3175 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3176 return;
3177 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3178 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3179 return;
3180 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3181 return;
3182 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3183 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003184 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003185 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3186 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003187 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3188 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003189 if (PyDict_SetItemString(d, "GeneratorExp",
3190 (PyObject*)GeneratorExp_type) < 0) return;
3191 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3192 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3193 return;
3194 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003195 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3196 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003197 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003198 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3199 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003200 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3201 0) return;
3202 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3203 0) return;
Guido van Rossum0368b722007-05-11 16:50:42 +00003204 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
3205 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003206 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3207 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3208 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3209 if (PyDict_SetItemString(d, "expr_context",
3210 (PyObject*)expr_context_type) < 0) return;
3211 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3212 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3213 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3214 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3215 return;
3216 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3217 return;
3218 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3219 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003220 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3221 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3222 return;
3223 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3224 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3225 return;
3226 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3227 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3228 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3229 return;
3230 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3231 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3232 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3233 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3234 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3235 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3236 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3237 return;
3238 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3239 return;
3240 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3241 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3242 return;
3243 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3244 return;
3245 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3246 return;
3247 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3248 return;
3249 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3250 return;
3251 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3252 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3253 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3254 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3255 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3256 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3257 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3258 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3259 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3260 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3261 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3262 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3263 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3264 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3265 if (PyDict_SetItemString(d, "comprehension",
3266 (PyObject*)comprehension_type) < 0) return;
3267 if (PyDict_SetItemString(d, "excepthandler",
3268 (PyObject*)excepthandler_type) < 0) return;
3269 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3270 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003271 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003272 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3273 return;
3274 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003275}
3276
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003277
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003278PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003279{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003280 init_types();
3281 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003282}
Martin v. Löwis5b222132007-06-10 09:51:05 +00003283
3284