blob: 4cf686f51cf059547700b77ef45f3bfaaf93010c [file] [log] [blame]
Neal Norwitz897ff812005-12-11 21:18:22 +00001/* File automatically generated by Parser/asdl_c.py */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
3#include "Python.h"
4#include "Python-ast.h"
5
Neal Norwitz53d960c2006-02-28 22:47:29 +00006static PyTypeObject* AST_type;
7static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +00009static PyTypeObject *Module_type;
10static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000011 "body",
12};
Neal Norwitz53d960c2006-02-28 22:47:29 +000013static PyTypeObject *Interactive_type;
14static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000015 "body",
16};
Neal Norwitz53d960c2006-02-28 22:47:29 +000017static PyTypeObject *Expression_type;
18static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000019 "body",
20};
Neal Norwitz53d960c2006-02-28 22:47:29 +000021static PyTypeObject *Suite_type;
22static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000023 "body",
24};
Neal Norwitz53d960c2006-02-28 22:47:29 +000025static PyTypeObject *stmt_type;
26static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000027 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000028 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000029};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000030static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000031static PyTypeObject *FunctionDef_type;
32static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000033 "name",
34 "args",
35 "body",
36 "decorators",
Neal Norwitzc1505362006-12-28 06:47:50 +000037 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000038};
Neal Norwitz53d960c2006-02-28 22:47:29 +000039static PyTypeObject *ClassDef_type;
40static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000041 "name",
42 "bases",
43 "body",
44};
Neal Norwitz53d960c2006-02-28 22:47:29 +000045static PyTypeObject *Return_type;
46static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047 "value",
48};
Neal Norwitz53d960c2006-02-28 22:47:29 +000049static PyTypeObject *Delete_type;
50static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000051 "targets",
52};
Neal Norwitz53d960c2006-02-28 22:47:29 +000053static PyTypeObject *Assign_type;
54static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000055 "targets",
56 "value",
57};
Neal Norwitz53d960c2006-02-28 22:47:29 +000058static PyTypeObject *AugAssign_type;
59static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000060 "target",
61 "op",
62 "value",
63};
Neal Norwitz53d960c2006-02-28 22:47:29 +000064static PyTypeObject *Print_type;
65static char *Print_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000066 "dest",
67 "values",
68 "nl",
69};
Neal Norwitz53d960c2006-02-28 22:47:29 +000070static PyTypeObject *For_type;
71static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000072 "target",
73 "iter",
74 "body",
75 "orelse",
76};
Neal Norwitz53d960c2006-02-28 22:47:29 +000077static PyTypeObject *While_type;
78static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000079 "test",
80 "body",
81 "orelse",
82};
Neal Norwitz53d960c2006-02-28 22:47:29 +000083static PyTypeObject *If_type;
84static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000085 "test",
86 "body",
87 "orelse",
88};
Neal Norwitz53d960c2006-02-28 22:47:29 +000089static PyTypeObject *With_type;
90static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000091 "context_expr",
92 "optional_vars",
93 "body",
94};
Neal Norwitz53d960c2006-02-28 22:47:29 +000095static PyTypeObject *Raise_type;
96static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000097 "type",
98 "inst",
99 "tback",
100};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000101static PyTypeObject *TryExcept_type;
102static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000103 "body",
104 "handlers",
105 "orelse",
106};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000107static PyTypeObject *TryFinally_type;
108static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000109 "body",
110 "finalbody",
111};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000112static PyTypeObject *Assert_type;
113static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000114 "test",
115 "msg",
116};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000117static PyTypeObject *Import_type;
118static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000119 "names",
120};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000121static PyTypeObject *ImportFrom_type;
122static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000123 "module",
124 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000125 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000126};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000127static PyTypeObject *Global_type;
128static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000129 "names",
130};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000131static PyTypeObject *Expr_type;
132static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000133 "value",
134};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000135static PyTypeObject *Pass_type;
136static PyTypeObject *Break_type;
137static PyTypeObject *Continue_type;
138static PyTypeObject *expr_type;
139static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000140 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000141 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000142};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000143static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000144static PyTypeObject *BoolOp_type;
145static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000146 "op",
147 "values",
148};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *BinOp_type;
150static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000151 "left",
152 "op",
153 "right",
154};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000155static PyTypeObject *UnaryOp_type;
156static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000157 "op",
158 "operand",
159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *Lambda_type;
161static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000162 "args",
163 "body",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *IfExp_type;
166static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000167 "test",
168 "body",
169 "orelse",
170};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000171static PyTypeObject *Dict_type;
172static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000173 "keys",
174 "values",
175};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000176static PyTypeObject *Set_type;
177static char *Set_fields[]={
178 "elts",
179};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000180static PyTypeObject *ListComp_type;
181static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000182 "elt",
183 "generators",
184};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000185static PyTypeObject *GeneratorExp_type;
186static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000187 "elt",
188 "generators",
189};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000190static PyTypeObject *Yield_type;
191static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000192 "value",
193};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000194static PyTypeObject *Compare_type;
195static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000196 "left",
197 "ops",
198 "comparators",
199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *Call_type;
201static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000202 "func",
203 "args",
204 "keywords",
205 "starargs",
206 "kwargs",
207};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000208static PyTypeObject *Num_type;
209static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000210 "n",
211};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000212static PyTypeObject *Str_type;
213static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000214 "s",
215};
Georg Brandl52318d62006-09-06 07:06:08 +0000216static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Attribute_type;
218static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "value",
220 "attr",
221 "ctx",
222};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000223static PyTypeObject *Subscript_type;
224static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000225 "value",
226 "slice",
227 "ctx",
228};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000229static PyTypeObject *Name_type;
230static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000231 "id",
232 "ctx",
233};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000234static PyTypeObject *List_type;
235static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000236 "elts",
237 "ctx",
238};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000239static PyTypeObject *Tuple_type;
240static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000241 "elts",
242 "ctx",
243};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000244static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
246*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
247static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *Load_type;
249static PyTypeObject *Store_type;
250static PyTypeObject *Del_type;
251static PyTypeObject *AugLoad_type;
252static PyTypeObject *AugStore_type;
253static PyTypeObject *Param_type;
254static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000256static PyTypeObject *Slice_type;
257static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000258 "lower",
259 "upper",
260 "step",
261};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000262static PyTypeObject *ExtSlice_type;
263static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000264 "dims",
265};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000266static PyTypeObject *Index_type;
267static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000268 "value",
269};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000270static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271static PyObject *And_singleton, *Or_singleton;
272static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000273static PyTypeObject *And_type;
274static PyTypeObject *Or_type;
275static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000276static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
277*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
278*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
279*FloorDiv_singleton;
280static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000281static PyTypeObject *Add_type;
282static PyTypeObject *Sub_type;
283static PyTypeObject *Mult_type;
284static PyTypeObject *Div_type;
285static PyTypeObject *Mod_type;
286static PyTypeObject *Pow_type;
287static PyTypeObject *LShift_type;
288static PyTypeObject *RShift_type;
289static PyTypeObject *BitOr_type;
290static PyTypeObject *BitXor_type;
291static PyTypeObject *BitAnd_type;
292static PyTypeObject *FloorDiv_type;
293static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000294static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
295*USub_singleton;
296static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000297static PyTypeObject *Invert_type;
298static PyTypeObject *Not_type;
299static PyTypeObject *UAdd_type;
300static PyTypeObject *USub_type;
301static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000302static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
303*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
304*NotIn_singleton;
305static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000306static PyTypeObject *Eq_type;
307static PyTypeObject *NotEq_type;
308static PyTypeObject *Lt_type;
309static PyTypeObject *LtE_type;
310static PyTypeObject *Gt_type;
311static PyTypeObject *GtE_type;
312static PyTypeObject *Is_type;
313static PyTypeObject *IsNot_type;
314static PyTypeObject *In_type;
315static PyTypeObject *NotIn_type;
316static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000317static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000318static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000319 "target",
320 "iter",
321 "ifs",
322};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000323static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000325static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000326 "type",
327 "name",
328 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000329 "lineno",
330 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000332static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000334static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000335 "args",
336 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000337 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000338 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000339 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000340 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000341 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000342 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000343};
Neal Norwitzc1505362006-12-28 06:47:50 +0000344static PyTypeObject *arg_type;
345static PyObject* ast2obj_arg(void*);
346static PyTypeObject *SimpleArg_type;
347static char *SimpleArg_fields[]={
348 "arg",
349 "annotation",
350};
351static PyTypeObject *NestedArgs_type;
352static char *NestedArgs_fields[]={
353 "args",
354};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000355static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000356static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000357static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000358 "arg",
359 "value",
360};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000361static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000362static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000363static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000364 "name",
365 "asname",
366};
367
368
369static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
370{
371 PyObject *fnames, *result;
372 int i;
373 if (num_fields) {
374 fnames = PyTuple_New(num_fields);
375 if (!fnames) return NULL;
376 } else {
377 fnames = Py_None;
378 Py_INCREF(Py_None);
379 }
380 for(i=0; i < num_fields; i++) {
381 PyObject *field = PyString_FromString(fields[i]);
382 if (!field) {
383 Py_DECREF(fnames);
384 return NULL;
385 }
386 PyTuple_SET_ITEM(fnames, i, field);
387 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000388 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000389 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000390 Py_DECREF(fnames);
391 return (PyTypeObject*)result;
392}
393
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000394static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
395{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000396 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000397 PyObject *s, *l = PyList_New(num_fields);
398 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000399 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000400 s = PyString_FromString(attrs[i]);
401 if (!s) {
402 Py_DECREF(l);
403 return 0;
404 }
405 PyList_SET_ITEM(l, i, s);
406 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000407 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
408 Py_DECREF(l);
409 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000410}
411
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000412static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
413{
414 int i, n = asdl_seq_LEN(seq);
415 PyObject *result = PyList_New(n);
416 PyObject *value;
417 if (!result)
418 return NULL;
419 for (i = 0; i < n; i++) {
420 value = func(asdl_seq_GET(seq, i));
421 if (!value) {
422 Py_DECREF(result);
423 return NULL;
424 }
425 PyList_SET_ITEM(result, i, value);
426 }
427 return result;
428}
429
430static PyObject* ast2obj_object(void *o)
431{
432 if (!o)
433 o = Py_None;
434 Py_INCREF((PyObject*)o);
435 return (PyObject*)o;
436}
437#define ast2obj_identifier ast2obj_object
438#define ast2obj_string ast2obj_object
439static PyObject* ast2obj_bool(bool b)
440{
441 return PyBool_FromLong(b);
442}
443
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000444static PyObject* ast2obj_int(bool b)
445{
446 return PyInt_FromLong(b);
447}
448
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000449static int init_types(void)
450{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000451 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000452 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000453 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
454 mod_type = make_type("mod", AST_type, NULL, 0);
455 if (!mod_type) return 0;
456 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000457 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 Interactive_type = make_type("Interactive", mod_type,
460 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000461 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000462 Expression_type = make_type("Expression", mod_type, Expression_fields,
463 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Suite_type) return 0;
467 stmt_type = make_type("stmt", AST_type, NULL, 0);
468 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000469 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000470 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000471 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000484 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000487 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000488 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000489 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000490 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000491 With_type = make_type("With", stmt_type, With_fields, 3);
492 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
498 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000503 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000504 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000505 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000510 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000511 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000512 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000513 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000515 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000516 if (!Continue_type) return 0;
517 expr_type = make_type("expr", AST_type, NULL, 0);
518 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000519 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000528 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000529 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000530 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000532 Set_type = make_type("Set", expr_type, Set_fields, 1);
533 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000534 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000535 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000536 GeneratorExp_type = make_type("GeneratorExp", expr_type,
537 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000547 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!Str_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000549 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
550 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000551 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000552 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000554 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000555 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000556 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000557 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000558 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000559 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000560 if (!Tuple_type) return 0;
561 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
562 if (!expr_context_type) return 0;
563 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000564 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000568 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000572 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000574 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000575 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000576 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000580 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000581 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000582 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000583 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000584 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000585 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000586 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!Param_singleton) return 0;
588 slice_type = make_type("slice", AST_type, NULL, 0);
589 if (!slice_type) return 0;
590 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000591 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000592 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000593 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000595 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!Index_type) return 0;
597 boolop_type = make_type("boolop", AST_type, NULL, 0);
598 if (!boolop_type) return 0;
599 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000600 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000602 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000604 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000606 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000607 if (!Or_singleton) return 0;
608 operator_type = make_type("operator", AST_type, NULL, 0);
609 if (!operator_type) return 0;
610 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000615 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000647 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000649 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000651 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000653 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000655 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000656 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000657 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000658 if (!FloorDiv_singleton) return 0;
659 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
660 if (!unaryop_type) return 0;
661 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000666 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000670 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000671 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000672 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000673 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000674 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000676 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!USub_singleton) return 0;
678 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
679 if (!cmpop_type) return 0;
680 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000705 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000707 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000709 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000711 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000713 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000715 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000717 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000719 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!NotIn_singleton) return 0;
721 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000722 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!comprehension_type) return 0;
724 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000725 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000727 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000728 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000729 arg_type = make_type("arg", AST_type, NULL, 0);
730 if (!arg_type) return 0;
731 if (!add_attributes(arg_type, NULL, 0)) return 0;
732 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
733 if (!SimpleArg_type) return 0;
734 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
735 1);
736 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000737 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
738 if (!keyword_type) return 0;
739 alias_type = make_type("alias", AST_type, alias_fields, 2);
740 if (!alias_type) return 0;
741 initialized = 1;
742 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000743}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000744
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000745mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000746Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000747{
748 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000749 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000750 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000751 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000752 return NULL;
753 }
754 p->kind = Module_kind;
755 p->v.Module.body = body;
756 return p;
757}
758
759mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000760Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761{
762 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000763 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000764 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000765 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766 return NULL;
767 }
768 p->kind = Interactive_kind;
769 p->v.Interactive.body = body;
770 return p;
771}
772
773mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000774Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775{
776 mod_ty p;
777 if (!body) {
778 PyErr_SetString(PyExc_ValueError,
779 "field body is required for Expression");
780 return NULL;
781 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000782 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000784 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000785 return NULL;
786 }
787 p->kind = Expression_kind;
788 p->v.Expression.body = body;
789 return p;
790}
791
792mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000793Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000794{
795 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000796 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000797 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000798 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000799 return NULL;
800 }
801 p->kind = Suite_kind;
802 p->v.Suite.body = body;
803 return p;
804}
805
806stmt_ty
807FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000808 decorators, expr_ty returns, int lineno, int col_offset, PyArena
809 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000810{
811 stmt_ty p;
812 if (!name) {
813 PyErr_SetString(PyExc_ValueError,
814 "field name is required for FunctionDef");
815 return NULL;
816 }
817 if (!args) {
818 PyErr_SetString(PyExc_ValueError,
819 "field args is required for FunctionDef");
820 return NULL;
821 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000822 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000823 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000824 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 return NULL;
826 }
827 p->kind = FunctionDef_kind;
828 p->v.FunctionDef.name = name;
829 p->v.FunctionDef.args = args;
830 p->v.FunctionDef.body = body;
831 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000832 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000833 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835 return p;
836}
837
838stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000839ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
840 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841{
842 stmt_ty p;
843 if (!name) {
844 PyErr_SetString(PyExc_ValueError,
845 "field name is required for ClassDef");
846 return NULL;
847 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000848 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000850 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851 return NULL;
852 }
853 p->kind = ClassDef_kind;
854 p->v.ClassDef.name = name;
855 p->v.ClassDef.bases = bases;
856 p->v.ClassDef.body = body;
857 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000858 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 return p;
860}
861
862stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000863Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864{
865 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000866 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000868 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000869 return NULL;
870 }
871 p->kind = Return_kind;
872 p->v.Return.value = value;
873 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000874 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875 return p;
876}
877
878stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000879Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000880{
881 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000882 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000883 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000884 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885 return NULL;
886 }
887 p->kind = Delete_kind;
888 p->v.Delete.targets = targets;
889 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000890 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000891 return p;
892}
893
894stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000895Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
896 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000897{
898 stmt_ty p;
899 if (!value) {
900 PyErr_SetString(PyExc_ValueError,
901 "field value is required for Assign");
902 return NULL;
903 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000904 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000905 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000906 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000907 return NULL;
908 }
909 p->kind = Assign_kind;
910 p->v.Assign.targets = targets;
911 p->v.Assign.value = value;
912 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000913 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 return p;
915}
916
917stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000918AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
919 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000920{
921 stmt_ty p;
922 if (!target) {
923 PyErr_SetString(PyExc_ValueError,
924 "field target is required for AugAssign");
925 return NULL;
926 }
927 if (!op) {
928 PyErr_SetString(PyExc_ValueError,
929 "field op is required for AugAssign");
930 return NULL;
931 }
932 if (!value) {
933 PyErr_SetString(PyExc_ValueError,
934 "field value is required for AugAssign");
935 return NULL;
936 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000937 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000938 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000939 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000940 return NULL;
941 }
942 p->kind = AugAssign_kind;
943 p->v.AugAssign.target = target;
944 p->v.AugAssign.op = op;
945 p->v.AugAssign.value = value;
946 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000947 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000948 return p;
949}
950
951stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000952Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
953 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000954{
955 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000956 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000957 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000958 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000959 return NULL;
960 }
961 p->kind = Print_kind;
962 p->v.Print.dest = dest;
963 p->v.Print.values = values;
964 p->v.Print.nl = nl;
965 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000966 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000967 return p;
968}
969
970stmt_ty
971For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000972 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000973{
974 stmt_ty p;
975 if (!target) {
976 PyErr_SetString(PyExc_ValueError,
977 "field target is required for For");
978 return NULL;
979 }
980 if (!iter) {
981 PyErr_SetString(PyExc_ValueError,
982 "field iter is required for For");
983 return NULL;
984 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000985 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000986 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000987 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000988 return NULL;
989 }
990 p->kind = For_kind;
991 p->v.For.target = target;
992 p->v.For.iter = iter;
993 p->v.For.body = body;
994 p->v.For.orelse = orelse;
995 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000996 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000997 return p;
998}
999
1000stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001001While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1002 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003{
1004 stmt_ty p;
1005 if (!test) {
1006 PyErr_SetString(PyExc_ValueError,
1007 "field test is required for While");
1008 return NULL;
1009 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001010 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001011 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001012 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013 return NULL;
1014 }
1015 p->kind = While_kind;
1016 p->v.While.test = test;
1017 p->v.While.body = body;
1018 p->v.While.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
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001025If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1026 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001027{
1028 stmt_ty p;
1029 if (!test) {
1030 PyErr_SetString(PyExc_ValueError,
1031 "field test is required for If");
1032 return NULL;
1033 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001034 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001035 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001036 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001037 return NULL;
1038 }
1039 p->kind = If_kind;
1040 p->v.If.test = test;
1041 p->v.If.body = body;
1042 p->v.If.orelse = orelse;
1043 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001044 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001045 return p;
1046}
1047
1048stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001049With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001050 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001051{
1052 stmt_ty p;
1053 if (!context_expr) {
1054 PyErr_SetString(PyExc_ValueError,
1055 "field context_expr is required for With");
1056 return NULL;
1057 }
1058 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1059 if (!p) {
1060 PyErr_NoMemory();
1061 return NULL;
1062 }
1063 p->kind = With_kind;
1064 p->v.With.context_expr = context_expr;
1065 p->v.With.optional_vars = optional_vars;
1066 p->v.With.body = body;
1067 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001068 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001069 return p;
1070}
1071
1072stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001073Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1074 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075{
1076 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001077 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001078 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001079 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001080 return NULL;
1081 }
1082 p->kind = Raise_kind;
1083 p->v.Raise.type = type;
1084 p->v.Raise.inst = inst;
1085 p->v.Raise.tback = tback;
1086 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001087 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001088 return p;
1089}
1090
1091stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001092TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001093 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001094{
1095 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001096 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001097 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001098 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001099 return NULL;
1100 }
1101 p->kind = TryExcept_kind;
1102 p->v.TryExcept.body = body;
1103 p->v.TryExcept.handlers = handlers;
1104 p->v.TryExcept.orelse = orelse;
1105 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001106 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107 return p;
1108}
1109
1110stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001111TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1112 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113{
1114 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001115 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001117 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118 return NULL;
1119 }
1120 p->kind = TryFinally_kind;
1121 p->v.TryFinally.body = body;
1122 p->v.TryFinally.finalbody = finalbody;
1123 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001124 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 return p;
1126}
1127
1128stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001129Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001130{
1131 stmt_ty p;
1132 if (!test) {
1133 PyErr_SetString(PyExc_ValueError,
1134 "field test is required for Assert");
1135 return NULL;
1136 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001137 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001138 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001139 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001140 return NULL;
1141 }
1142 p->kind = Assert_kind;
1143 p->v.Assert.test = test;
1144 p->v.Assert.msg = msg;
1145 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001146 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147 return p;
1148}
1149
1150stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001151Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001152{
1153 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001154 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001155 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001156 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 return NULL;
1158 }
1159 p->kind = Import_kind;
1160 p->v.Import.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
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001167ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1168 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169{
1170 stmt_ty p;
1171 if (!module) {
1172 PyErr_SetString(PyExc_ValueError,
1173 "field module is required for ImportFrom");
1174 return NULL;
1175 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001176 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001178 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 return NULL;
1180 }
1181 p->kind = ImportFrom_kind;
1182 p->v.ImportFrom.module = module;
1183 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001184 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001185 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001186 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001187 return p;
1188}
1189
1190stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001191Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192{
1193 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001194 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001195 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001196 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 return NULL;
1198 }
1199 p->kind = Global_kind;
1200 p->v.Global.names = names;
1201 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001202 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203 return p;
1204}
1205
1206stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001207Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208{
1209 stmt_ty p;
1210 if (!value) {
1211 PyErr_SetString(PyExc_ValueError,
1212 "field value is required for Expr");
1213 return NULL;
1214 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001215 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001216 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001217 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return NULL;
1219 }
1220 p->kind = Expr_kind;
1221 p->v.Expr.value = value;
1222 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001223 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001224 return p;
1225}
1226
1227stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001228Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229{
1230 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001231 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001233 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234 return NULL;
1235 }
1236 p->kind = Pass_kind;
1237 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001238 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239 return p;
1240}
1241
1242stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001243Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244{
1245 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001246 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001247 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001248 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 return NULL;
1250 }
1251 p->kind = Break_kind;
1252 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001253 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001254 return p;
1255}
1256
1257stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001258Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259{
1260 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001261 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001262 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001263 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264 return NULL;
1265 }
1266 p->kind = Continue_kind;
1267 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001268 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001269 return p;
1270}
1271
1272expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001273BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1274 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001275{
1276 expr_ty p;
1277 if (!op) {
1278 PyErr_SetString(PyExc_ValueError,
1279 "field op is required for BoolOp");
1280 return NULL;
1281 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001282 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001283 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001284 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001285 return NULL;
1286 }
1287 p->kind = BoolOp_kind;
1288 p->v.BoolOp.op = op;
1289 p->v.BoolOp.values = values;
1290 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001291 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292 return p;
1293}
1294
1295expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001296BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1297 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001298{
1299 expr_ty p;
1300 if (!left) {
1301 PyErr_SetString(PyExc_ValueError,
1302 "field left is required for BinOp");
1303 return NULL;
1304 }
1305 if (!op) {
1306 PyErr_SetString(PyExc_ValueError,
1307 "field op is required for BinOp");
1308 return NULL;
1309 }
1310 if (!right) {
1311 PyErr_SetString(PyExc_ValueError,
1312 "field right is required for BinOp");
1313 return NULL;
1314 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001315 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001316 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001317 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318 return NULL;
1319 }
1320 p->kind = BinOp_kind;
1321 p->v.BinOp.left = left;
1322 p->v.BinOp.op = op;
1323 p->v.BinOp.right = right;
1324 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001325 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001326 return p;
1327}
1328
1329expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001330UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1331 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001332{
1333 expr_ty p;
1334 if (!op) {
1335 PyErr_SetString(PyExc_ValueError,
1336 "field op is required for UnaryOp");
1337 return NULL;
1338 }
1339 if (!operand) {
1340 PyErr_SetString(PyExc_ValueError,
1341 "field operand is required for UnaryOp");
1342 return NULL;
1343 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001344 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001345 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001346 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001347 return NULL;
1348 }
1349 p->kind = UnaryOp_kind;
1350 p->v.UnaryOp.op = op;
1351 p->v.UnaryOp.operand = operand;
1352 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001353 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001354 return p;
1355}
1356
1357expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001358Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1359 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001360{
1361 expr_ty p;
1362 if (!args) {
1363 PyErr_SetString(PyExc_ValueError,
1364 "field args is required for Lambda");
1365 return NULL;
1366 }
1367 if (!body) {
1368 PyErr_SetString(PyExc_ValueError,
1369 "field body is required for Lambda");
1370 return NULL;
1371 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001372 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001373 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001374 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001375 return NULL;
1376 }
1377 p->kind = Lambda_kind;
1378 p->v.Lambda.args = args;
1379 p->v.Lambda.body = body;
1380 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001381 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001382 return p;
1383}
1384
1385expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001386IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1387 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001388{
1389 expr_ty p;
1390 if (!test) {
1391 PyErr_SetString(PyExc_ValueError,
1392 "field test is required for IfExp");
1393 return NULL;
1394 }
1395 if (!body) {
1396 PyErr_SetString(PyExc_ValueError,
1397 "field body is required for IfExp");
1398 return NULL;
1399 }
1400 if (!orelse) {
1401 PyErr_SetString(PyExc_ValueError,
1402 "field orelse is required for IfExp");
1403 return NULL;
1404 }
1405 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1406 if (!p) {
1407 PyErr_NoMemory();
1408 return NULL;
1409 }
1410 p->kind = IfExp_kind;
1411 p->v.IfExp.test = test;
1412 p->v.IfExp.body = body;
1413 p->v.IfExp.orelse = orelse;
1414 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001416 return p;
1417}
1418
1419expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001420Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1421 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422{
1423 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001424 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001425 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001426 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 return NULL;
1428 }
1429 p->kind = Dict_kind;
1430 p->v.Dict.keys = keys;
1431 p->v.Dict.values = values;
1432 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001433 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001434 return p;
1435}
1436
1437expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001438Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1439{
1440 expr_ty p;
1441 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1442 if (!p) {
1443 PyErr_NoMemory();
1444 return NULL;
1445 }
1446 p->kind = Set_kind;
1447 p->v.Set.elts = elts;
1448 p->lineno = lineno;
1449 p->col_offset = col_offset;
1450 return p;
1451}
1452
1453expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001454ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1455 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001456{
1457 expr_ty p;
1458 if (!elt) {
1459 PyErr_SetString(PyExc_ValueError,
1460 "field elt is required for ListComp");
1461 return NULL;
1462 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001463 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001464 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001465 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001466 return NULL;
1467 }
1468 p->kind = ListComp_kind;
1469 p->v.ListComp.elt = elt;
1470 p->v.ListComp.generators = generators;
1471 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001472 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001473 return p;
1474}
1475
1476expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001477GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1478 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479{
1480 expr_ty p;
1481 if (!elt) {
1482 PyErr_SetString(PyExc_ValueError,
1483 "field elt is required for GeneratorExp");
1484 return NULL;
1485 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001486 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001487 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001488 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001489 return NULL;
1490 }
1491 p->kind = GeneratorExp_kind;
1492 p->v.GeneratorExp.elt = elt;
1493 p->v.GeneratorExp.generators = generators;
1494 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001495 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001496 return p;
1497}
1498
1499expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001500Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001501{
1502 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001503 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001504 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001505 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506 return NULL;
1507 }
1508 p->kind = Yield_kind;
1509 p->v.Yield.value = value;
1510 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001511 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001512 return p;
1513}
1514
1515expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001516Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1517 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518{
1519 expr_ty p;
1520 if (!left) {
1521 PyErr_SetString(PyExc_ValueError,
1522 "field left is required for Compare");
1523 return NULL;
1524 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001525 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001527 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001528 return NULL;
1529 }
1530 p->kind = Compare_kind;
1531 p->v.Compare.left = left;
1532 p->v.Compare.ops = ops;
1533 p->v.Compare.comparators = comparators;
1534 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001535 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001536 return p;
1537}
1538
1539expr_ty
1540Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001541 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542{
1543 expr_ty p;
1544 if (!func) {
1545 PyErr_SetString(PyExc_ValueError,
1546 "field func is required for Call");
1547 return NULL;
1548 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001549 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001550 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001551 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001552 return NULL;
1553 }
1554 p->kind = Call_kind;
1555 p->v.Call.func = func;
1556 p->v.Call.args = args;
1557 p->v.Call.keywords = keywords;
1558 p->v.Call.starargs = starargs;
1559 p->v.Call.kwargs = kwargs;
1560 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001561 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001562 return p;
1563}
1564
1565expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001566Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567{
1568 expr_ty p;
1569 if (!n) {
1570 PyErr_SetString(PyExc_ValueError,
1571 "field n is required for Num");
1572 return NULL;
1573 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001574 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001575 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001576 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001577 return NULL;
1578 }
1579 p->kind = Num_kind;
1580 p->v.Num.n = n;
1581 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001582 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001583 return p;
1584}
1585
1586expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001587Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001588{
1589 expr_ty p;
1590 if (!s) {
1591 PyErr_SetString(PyExc_ValueError,
1592 "field s is required for Str");
1593 return NULL;
1594 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001595 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001596 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001597 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001598 return NULL;
1599 }
1600 p->kind = Str_kind;
1601 p->v.Str.s = s;
1602 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001603 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001604 return p;
1605}
1606
1607expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001608Ellipsis(int lineno, int col_offset, PyArena *arena)
1609{
1610 expr_ty p;
1611 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1612 if (!p) {
1613 PyErr_NoMemory();
1614 return NULL;
1615 }
1616 p->kind = Ellipsis_kind;
1617 p->lineno = lineno;
1618 p->col_offset = col_offset;
1619 return p;
1620}
1621
1622expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001623Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1624 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001625{
1626 expr_ty p;
1627 if (!value) {
1628 PyErr_SetString(PyExc_ValueError,
1629 "field value is required for Attribute");
1630 return NULL;
1631 }
1632 if (!attr) {
1633 PyErr_SetString(PyExc_ValueError,
1634 "field attr is required for Attribute");
1635 return NULL;
1636 }
1637 if (!ctx) {
1638 PyErr_SetString(PyExc_ValueError,
1639 "field ctx is required for Attribute");
1640 return NULL;
1641 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001642 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001643 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001644 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001645 return NULL;
1646 }
1647 p->kind = Attribute_kind;
1648 p->v.Attribute.value = value;
1649 p->v.Attribute.attr = attr;
1650 p->v.Attribute.ctx = ctx;
1651 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001652 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 return p;
1654}
1655
1656expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001657Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1658 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659{
1660 expr_ty p;
1661 if (!value) {
1662 PyErr_SetString(PyExc_ValueError,
1663 "field value is required for Subscript");
1664 return NULL;
1665 }
1666 if (!slice) {
1667 PyErr_SetString(PyExc_ValueError,
1668 "field slice is required for Subscript");
1669 return NULL;
1670 }
1671 if (!ctx) {
1672 PyErr_SetString(PyExc_ValueError,
1673 "field ctx is required for Subscript");
1674 return NULL;
1675 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001676 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001677 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001678 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679 return NULL;
1680 }
1681 p->kind = Subscript_kind;
1682 p->v.Subscript.value = value;
1683 p->v.Subscript.slice = slice;
1684 p->v.Subscript.ctx = ctx;
1685 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001686 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001687 return p;
1688}
1689
1690expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001691Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1692 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001693{
1694 expr_ty p;
1695 if (!id) {
1696 PyErr_SetString(PyExc_ValueError,
1697 "field id is required for Name");
1698 return NULL;
1699 }
1700 if (!ctx) {
1701 PyErr_SetString(PyExc_ValueError,
1702 "field ctx is required for Name");
1703 return NULL;
1704 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001705 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001707 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001708 return NULL;
1709 }
1710 p->kind = Name_kind;
1711 p->v.Name.id = id;
1712 p->v.Name.ctx = ctx;
1713 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001714 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 return p;
1716}
1717
1718expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001719List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1720 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001721{
1722 expr_ty p;
1723 if (!ctx) {
1724 PyErr_SetString(PyExc_ValueError,
1725 "field ctx is required for List");
1726 return NULL;
1727 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001728 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001729 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001730 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001731 return NULL;
1732 }
1733 p->kind = List_kind;
1734 p->v.List.elts = elts;
1735 p->v.List.ctx = ctx;
1736 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001737 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 return p;
1739}
1740
1741expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001742Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1743 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001744{
1745 expr_ty p;
1746 if (!ctx) {
1747 PyErr_SetString(PyExc_ValueError,
1748 "field ctx is required for Tuple");
1749 return NULL;
1750 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001751 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001752 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001753 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001754 return NULL;
1755 }
1756 p->kind = Tuple_kind;
1757 p->v.Tuple.elts = elts;
1758 p->v.Tuple.ctx = ctx;
1759 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001760 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 return p;
1762}
1763
1764slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001765Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001766{
1767 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001768 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001770 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771 return NULL;
1772 }
1773 p->kind = Slice_kind;
1774 p->v.Slice.lower = lower;
1775 p->v.Slice.upper = upper;
1776 p->v.Slice.step = step;
1777 return p;
1778}
1779
1780slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001781ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001782{
1783 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001784 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001785 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001786 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787 return NULL;
1788 }
1789 p->kind = ExtSlice_kind;
1790 p->v.ExtSlice.dims = dims;
1791 return p;
1792}
1793
1794slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001795Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001796{
1797 slice_ty p;
1798 if (!value) {
1799 PyErr_SetString(PyExc_ValueError,
1800 "field value is required for Index");
1801 return NULL;
1802 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001803 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001804 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001805 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001806 return NULL;
1807 }
1808 p->kind = Index_kind;
1809 p->v.Index.value = value;
1810 return p;
1811}
1812
1813comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001814comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815{
1816 comprehension_ty p;
1817 if (!target) {
1818 PyErr_SetString(PyExc_ValueError,
1819 "field target is required for comprehension");
1820 return NULL;
1821 }
1822 if (!iter) {
1823 PyErr_SetString(PyExc_ValueError,
1824 "field iter is required for comprehension");
1825 return NULL;
1826 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001827 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001828 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001829 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001830 return NULL;
1831 }
1832 p->target = target;
1833 p->iter = iter;
1834 p->ifs = ifs;
1835 return p;
1836}
1837
1838excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001839excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1840 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001841{
1842 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001843 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001844 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001845 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 return NULL;
1847 }
1848 p->type = type;
1849 p->name = name;
1850 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001851 p->lineno = lineno;
1852 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 return p;
1854}
1855
1856arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001857arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1858 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1859 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001860{
1861 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001862 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001864 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001865 return NULL;
1866 }
1867 p->args = args;
1868 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001869 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001870 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001871 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001872 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001873 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001874 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001875 return p;
1876}
1877
Neal Norwitzc1505362006-12-28 06:47:50 +00001878arg_ty
1879SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1880{
1881 arg_ty p;
1882 if (!arg) {
1883 PyErr_SetString(PyExc_ValueError,
1884 "field arg is required for SimpleArg");
1885 return NULL;
1886 }
1887 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1888 if (!p) {
1889 PyErr_NoMemory();
1890 return NULL;
1891 }
1892 p->kind = SimpleArg_kind;
1893 p->v.SimpleArg.arg = arg;
1894 p->v.SimpleArg.annotation = annotation;
1895 return p;
1896}
1897
1898arg_ty
1899NestedArgs(asdl_seq * args, PyArena *arena)
1900{
1901 arg_ty p;
1902 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1903 if (!p) {
1904 PyErr_NoMemory();
1905 return NULL;
1906 }
1907 p->kind = NestedArgs_kind;
1908 p->v.NestedArgs.args = args;
1909 return p;
1910}
1911
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001912keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001913keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001914{
1915 keyword_ty p;
1916 if (!arg) {
1917 PyErr_SetString(PyExc_ValueError,
1918 "field arg is required for keyword");
1919 return NULL;
1920 }
1921 if (!value) {
1922 PyErr_SetString(PyExc_ValueError,
1923 "field value is required for keyword");
1924 return NULL;
1925 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001926 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001927 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001928 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001929 return NULL;
1930 }
1931 p->arg = arg;
1932 p->value = value;
1933 return p;
1934}
1935
1936alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001937alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001938{
1939 alias_ty p;
1940 if (!name) {
1941 PyErr_SetString(PyExc_ValueError,
1942 "field name is required for alias");
1943 return NULL;
1944 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001945 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001946 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001947 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948 return NULL;
1949 }
1950 p->name = name;
1951 p->asname = asname;
1952 return p;
1953}
1954
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001955
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001956PyObject*
1957ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001958{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001959 mod_ty o = (mod_ty)_o;
1960 PyObject *result = NULL, *value = NULL;
1961 if (!o) {
1962 Py_INCREF(Py_None);
1963 return Py_None;
1964 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001965
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 switch (o->kind) {
1967 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Module_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "body", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "body", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(Expression_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_expr(o->v.Expression.body);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "body", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001993 break;
1994 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001995 result = PyType_GenericNew(Suite_type, NULL, NULL);
1996 if (!result) goto failed;
1997 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1998 if (!value) goto failed;
1999 if (PyObject_SetAttrString(result, "body", value) == -1)
2000 goto failed;
2001 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002002 break;
2003 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002004 return result;
2005failed:
2006 Py_XDECREF(value);
2007 Py_XDECREF(result);
2008 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002009}
2010
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002011PyObject*
2012ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002013{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002014 stmt_ty o = (stmt_ty)_o;
2015 PyObject *result = NULL, *value = NULL;
2016 if (!o) {
2017 Py_INCREF(Py_None);
2018 return Py_None;
2019 }
2020
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002021 switch (o->kind) {
2022 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002023 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2024 if (!result) goto failed;
2025 value = ast2obj_identifier(o->v.FunctionDef.name);
2026 if (!value) goto failed;
2027 if (PyObject_SetAttrString(result, "name", value) == -1)
2028 goto failed;
2029 Py_DECREF(value);
2030 value = ast2obj_arguments(o->v.FunctionDef.args);
2031 if (!value) goto failed;
2032 if (PyObject_SetAttrString(result, "args", value) == -1)
2033 goto failed;
2034 Py_DECREF(value);
2035 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2036 if (!value) goto failed;
2037 if (PyObject_SetAttrString(result, "body", value) == -1)
2038 goto failed;
2039 Py_DECREF(value);
2040 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002045 value = ast2obj_expr(o->v.FunctionDef.returns);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "returns", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002050 break;
2051 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002052 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2053 if (!result) goto failed;
2054 value = ast2obj_identifier(o->v.ClassDef.name);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "name", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
2059 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "bases", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
2064 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "body", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002069 break;
2070 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002071 result = PyType_GenericNew(Return_type, NULL, NULL);
2072 if (!result) goto failed;
2073 value = ast2obj_expr(o->v.Return.value);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "value", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002078 break;
2079 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002080 result = PyType_GenericNew(Delete_type, NULL, NULL);
2081 if (!result) goto failed;
2082 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "targets", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002087 break;
2088 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002089 result = PyType_GenericNew(Assign_type, NULL, NULL);
2090 if (!result) goto failed;
2091 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2092 if (!value) goto failed;
2093 if (PyObject_SetAttrString(result, "targets", value) == -1)
2094 goto failed;
2095 Py_DECREF(value);
2096 value = ast2obj_expr(o->v.Assign.value);
2097 if (!value) goto failed;
2098 if (PyObject_SetAttrString(result, "value", value) == -1)
2099 goto failed;
2100 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002101 break;
2102 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002103 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2104 if (!result) goto failed;
2105 value = ast2obj_expr(o->v.AugAssign.target);
2106 if (!value) goto failed;
2107 if (PyObject_SetAttrString(result, "target", value) == -1)
2108 goto failed;
2109 Py_DECREF(value);
2110 value = ast2obj_operator(o->v.AugAssign.op);
2111 if (!value) goto failed;
2112 if (PyObject_SetAttrString(result, "op", value) == -1)
2113 goto failed;
2114 Py_DECREF(value);
2115 value = ast2obj_expr(o->v.AugAssign.value);
2116 if (!value) goto failed;
2117 if (PyObject_SetAttrString(result, "value", value) == -1)
2118 goto failed;
2119 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002120 break;
2121 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002122 result = PyType_GenericNew(Print_type, NULL, NULL);
2123 if (!result) goto failed;
2124 value = ast2obj_expr(o->v.Print.dest);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "dest", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "values", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
2134 value = ast2obj_bool(o->v.Print.nl);
2135 if (!value) goto failed;
2136 if (PyObject_SetAttrString(result, "nl", value) == -1)
2137 goto failed;
2138 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002139 break;
2140 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002141 result = PyType_GenericNew(For_type, NULL, NULL);
2142 if (!result) goto failed;
2143 value = ast2obj_expr(o->v.For.target);
2144 if (!value) goto failed;
2145 if (PyObject_SetAttrString(result, "target", value) == -1)
2146 goto failed;
2147 Py_DECREF(value);
2148 value = ast2obj_expr(o->v.For.iter);
2149 if (!value) goto failed;
2150 if (PyObject_SetAttrString(result, "iter", value) == -1)
2151 goto failed;
2152 Py_DECREF(value);
2153 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2154 if (!value) goto failed;
2155 if (PyObject_SetAttrString(result, "body", value) == -1)
2156 goto failed;
2157 Py_DECREF(value);
2158 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002163 break;
2164 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002165 result = PyType_GenericNew(While_type, NULL, NULL);
2166 if (!result) goto failed;
2167 value = ast2obj_expr(o->v.While.test);
2168 if (!value) goto failed;
2169 if (PyObject_SetAttrString(result, "test", value) == -1)
2170 goto failed;
2171 Py_DECREF(value);
2172 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2173 if (!value) goto failed;
2174 if (PyObject_SetAttrString(result, "body", value) == -1)
2175 goto failed;
2176 Py_DECREF(value);
2177 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2178 if (!value) goto failed;
2179 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2180 goto failed;
2181 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182 break;
2183 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002184 result = PyType_GenericNew(If_type, NULL, NULL);
2185 if (!result) goto failed;
2186 value = ast2obj_expr(o->v.If.test);
2187 if (!value) goto failed;
2188 if (PyObject_SetAttrString(result, "test", value) == -1)
2189 goto failed;
2190 Py_DECREF(value);
2191 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2192 if (!value) goto failed;
2193 if (PyObject_SetAttrString(result, "body", value) == -1)
2194 goto failed;
2195 Py_DECREF(value);
2196 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2197 if (!value) goto failed;
2198 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2199 goto failed;
2200 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002201 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002202 case With_kind:
2203 result = PyType_GenericNew(With_type, NULL, NULL);
2204 if (!result) goto failed;
2205 value = ast2obj_expr(o->v.With.context_expr);
2206 if (!value) goto failed;
2207 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2208 goto failed;
2209 Py_DECREF(value);
2210 value = ast2obj_expr(o->v.With.optional_vars);
2211 if (!value) goto failed;
2212 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2213 -1)
2214 goto failed;
2215 Py_DECREF(value);
2216 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2217 if (!value) goto failed;
2218 if (PyObject_SetAttrString(result, "body", value) == -1)
2219 goto failed;
2220 Py_DECREF(value);
2221 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002222 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002223 result = PyType_GenericNew(Raise_type, NULL, NULL);
2224 if (!result) goto failed;
2225 value = ast2obj_expr(o->v.Raise.type);
2226 if (!value) goto failed;
2227 if (PyObject_SetAttrString(result, "type", value) == -1)
2228 goto failed;
2229 Py_DECREF(value);
2230 value = ast2obj_expr(o->v.Raise.inst);
2231 if (!value) goto failed;
2232 if (PyObject_SetAttrString(result, "inst", value) == -1)
2233 goto failed;
2234 Py_DECREF(value);
2235 value = ast2obj_expr(o->v.Raise.tback);
2236 if (!value) goto failed;
2237 if (PyObject_SetAttrString(result, "tback", value) == -1)
2238 goto failed;
2239 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002240 break;
2241 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002242 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2243 if (!result) goto failed;
2244 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2245 if (!value) goto failed;
2246 if (PyObject_SetAttrString(result, "body", value) == -1)
2247 goto failed;
2248 Py_DECREF(value);
2249 value = ast2obj_list(o->v.TryExcept.handlers,
2250 ast2obj_excepthandler);
2251 if (!value) goto failed;
2252 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2253 goto failed;
2254 Py_DECREF(value);
2255 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002260 break;
2261 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002262 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2263 if (!result) goto failed;
2264 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "body", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
2269 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002274 break;
2275 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002276 result = PyType_GenericNew(Assert_type, NULL, NULL);
2277 if (!result) goto failed;
2278 value = ast2obj_expr(o->v.Assert.test);
2279 if (!value) goto failed;
2280 if (PyObject_SetAttrString(result, "test", value) == -1)
2281 goto failed;
2282 Py_DECREF(value);
2283 value = ast2obj_expr(o->v.Assert.msg);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "msg", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288 break;
2289 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002290 result = PyType_GenericNew(Import_type, NULL, NULL);
2291 if (!result) goto failed;
2292 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2293 if (!value) goto failed;
2294 if (PyObject_SetAttrString(result, "names", value) == -1)
2295 goto failed;
2296 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002297 break;
2298 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002299 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2300 if (!result) goto failed;
2301 value = ast2obj_identifier(o->v.ImportFrom.module);
2302 if (!value) goto failed;
2303 if (PyObject_SetAttrString(result, "module", value) == -1)
2304 goto failed;
2305 Py_DECREF(value);
2306 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "names", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002311 value = ast2obj_int(o->v.ImportFrom.level);
2312 if (!value) goto failed;
2313 if (PyObject_SetAttrString(result, "level", value) == -1)
2314 goto failed;
2315 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002316 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002318 result = PyType_GenericNew(Global_type, NULL, NULL);
2319 if (!result) goto failed;
2320 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2321 if (!value) goto failed;
2322 if (PyObject_SetAttrString(result, "names", value) == -1)
2323 goto failed;
2324 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325 break;
2326 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002327 result = PyType_GenericNew(Expr_type, NULL, NULL);
2328 if (!result) goto failed;
2329 value = ast2obj_expr(o->v.Expr.value);
2330 if (!value) goto failed;
2331 if (PyObject_SetAttrString(result, "value", value) == -1)
2332 goto failed;
2333 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002334 break;
2335 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002336 result = PyType_GenericNew(Pass_type, NULL, NULL);
2337 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002338 break;
2339 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002340 result = PyType_GenericNew(Break_type, NULL, NULL);
2341 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342 break;
2343 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 result = PyType_GenericNew(Continue_type, NULL, NULL);
2345 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346 break;
2347 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002348 value = ast2obj_int(o->lineno);
2349 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002350 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2351 goto failed;
2352 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002353 value = ast2obj_int(o->col_offset);
2354 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002355 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2356 goto failed;
2357 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358 return result;
2359failed:
2360 Py_XDECREF(value);
2361 Py_XDECREF(result);
2362 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002363}
2364
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002365PyObject*
2366ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002367{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002368 expr_ty o = (expr_ty)_o;
2369 PyObject *result = NULL, *value = NULL;
2370 if (!o) {
2371 Py_INCREF(Py_None);
2372 return Py_None;
2373 }
2374
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375 switch (o->kind) {
2376 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002377 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2378 if (!result) goto failed;
2379 value = ast2obj_boolop(o->v.BoolOp.op);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "op", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "values", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002389 break;
2390 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002391 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2392 if (!result) goto failed;
2393 value = ast2obj_expr(o->v.BinOp.left);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "left", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
2398 value = ast2obj_operator(o->v.BinOp.op);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "op", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 value = ast2obj_expr(o->v.BinOp.right);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "right", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002408 break;
2409 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_unaryop(o->v.UnaryOp.op);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "op", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 value = ast2obj_expr(o->v.UnaryOp.operand);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "operand", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002422 break;
2423 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002424 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2425 if (!result) goto failed;
2426 value = ast2obj_arguments(o->v.Lambda.args);
2427 if (!value) goto failed;
2428 if (PyObject_SetAttrString(result, "args", value) == -1)
2429 goto failed;
2430 Py_DECREF(value);
2431 value = ast2obj_expr(o->v.Lambda.body);
2432 if (!value) goto failed;
2433 if (PyObject_SetAttrString(result, "body", value) == -1)
2434 goto failed;
2435 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002437 case IfExp_kind:
2438 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2439 if (!result) goto failed;
2440 value = ast2obj_expr(o->v.IfExp.test);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "test", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
2445 value = ast2obj_expr(o->v.IfExp.body);
2446 if (!value) goto failed;
2447 if (PyObject_SetAttrString(result, "body", value) == -1)
2448 goto failed;
2449 Py_DECREF(value);
2450 value = ast2obj_expr(o->v.IfExp.orelse);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
2455 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002456 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002457 result = PyType_GenericNew(Dict_type, NULL, NULL);
2458 if (!result) goto failed;
2459 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2460 if (!value) goto failed;
2461 if (PyObject_SetAttrString(result, "keys", value) == -1)
2462 goto failed;
2463 Py_DECREF(value);
2464 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2465 if (!value) goto failed;
2466 if (PyObject_SetAttrString(result, "values", value) == -1)
2467 goto failed;
2468 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002469 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002470 case Set_kind:
2471 result = PyType_GenericNew(Set_type, NULL, NULL);
2472 if (!result) goto failed;
2473 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2474 if (!value) goto failed;
2475 if (PyObject_SetAttrString(result, "elts", value) == -1)
2476 goto failed;
2477 Py_DECREF(value);
2478 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002480 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2481 if (!result) goto failed;
2482 value = ast2obj_expr(o->v.ListComp.elt);
2483 if (!value) goto failed;
2484 if (PyObject_SetAttrString(result, "elt", value) == -1)
2485 goto failed;
2486 Py_DECREF(value);
2487 value = ast2obj_list(o->v.ListComp.generators,
2488 ast2obj_comprehension);
2489 if (!value) goto failed;
2490 if (PyObject_SetAttrString(result, "generators", value) == -1)
2491 goto failed;
2492 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002493 break;
2494 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002495 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2496 if (!result) goto failed;
2497 value = ast2obj_expr(o->v.GeneratorExp.elt);
2498 if (!value) goto failed;
2499 if (PyObject_SetAttrString(result, "elt", value) == -1)
2500 goto failed;
2501 Py_DECREF(value);
2502 value = ast2obj_list(o->v.GeneratorExp.generators,
2503 ast2obj_comprehension);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "generators", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002508 break;
2509 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002510 result = PyType_GenericNew(Yield_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_expr(o->v.Yield.value);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "value", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517 break;
2518 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002519 result = PyType_GenericNew(Compare_type, NULL, NULL);
2520 if (!result) goto failed;
2521 value = ast2obj_expr(o->v.Compare.left);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "left", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002526 {
2527 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2528 value = PyList_New(n);
2529 if (!value) goto failed;
2530 for(i = 0; i < n; i++)
2531 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2532 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002533 if (!value) goto failed;
2534 if (PyObject_SetAttrString(result, "ops", value) == -1)
2535 goto failed;
2536 Py_DECREF(value);
2537 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2538 if (!value) goto failed;
2539 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2540 goto failed;
2541 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002542 break;
2543 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002544 result = PyType_GenericNew(Call_type, NULL, NULL);
2545 if (!result) goto failed;
2546 value = ast2obj_expr(o->v.Call.func);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "func", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
2551 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "args", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
2556 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2557 if (!value) goto failed;
2558 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2559 goto failed;
2560 Py_DECREF(value);
2561 value = ast2obj_expr(o->v.Call.starargs);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
2566 value = ast2obj_expr(o->v.Call.kwargs);
2567 if (!value) goto failed;
2568 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2569 goto failed;
2570 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002571 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002572 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002573 result = PyType_GenericNew(Num_type, NULL, NULL);
2574 if (!result) goto failed;
2575 value = ast2obj_object(o->v.Num.n);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "n", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002580 break;
2581 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002582 result = PyType_GenericNew(Str_type, NULL, NULL);
2583 if (!result) goto failed;
2584 value = ast2obj_string(o->v.Str.s);
2585 if (!value) goto failed;
2586 if (PyObject_SetAttrString(result, "s", value) == -1)
2587 goto failed;
2588 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002590 case Ellipsis_kind:
2591 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2592 if (!result) goto failed;
2593 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002594 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002595 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2596 if (!result) goto failed;
2597 value = ast2obj_expr(o->v.Attribute.value);
2598 if (!value) goto failed;
2599 if (PyObject_SetAttrString(result, "value", value) == -1)
2600 goto failed;
2601 Py_DECREF(value);
2602 value = ast2obj_identifier(o->v.Attribute.attr);
2603 if (!value) goto failed;
2604 if (PyObject_SetAttrString(result, "attr", value) == -1)
2605 goto failed;
2606 Py_DECREF(value);
2607 value = ast2obj_expr_context(o->v.Attribute.ctx);
2608 if (!value) goto failed;
2609 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2610 goto failed;
2611 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002612 break;
2613 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002614 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2615 if (!result) goto failed;
2616 value = ast2obj_expr(o->v.Subscript.value);
2617 if (!value) goto failed;
2618 if (PyObject_SetAttrString(result, "value", value) == -1)
2619 goto failed;
2620 Py_DECREF(value);
2621 value = ast2obj_slice(o->v.Subscript.slice);
2622 if (!value) goto failed;
2623 if (PyObject_SetAttrString(result, "slice", value) == -1)
2624 goto failed;
2625 Py_DECREF(value);
2626 value = ast2obj_expr_context(o->v.Subscript.ctx);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002631 break;
2632 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002633 result = PyType_GenericNew(Name_type, NULL, NULL);
2634 if (!result) goto failed;
2635 value = ast2obj_identifier(o->v.Name.id);
2636 if (!value) goto failed;
2637 if (PyObject_SetAttrString(result, "id", value) == -1)
2638 goto failed;
2639 Py_DECREF(value);
2640 value = ast2obj_expr_context(o->v.Name.ctx);
2641 if (!value) goto failed;
2642 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2643 goto failed;
2644 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002645 break;
2646 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002647 result = PyType_GenericNew(List_type, NULL, NULL);
2648 if (!result) goto failed;
2649 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2650 if (!value) goto failed;
2651 if (PyObject_SetAttrString(result, "elts", value) == -1)
2652 goto failed;
2653 Py_DECREF(value);
2654 value = ast2obj_expr_context(o->v.List.ctx);
2655 if (!value) goto failed;
2656 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2657 goto failed;
2658 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002659 break;
2660 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002661 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2662 if (!result) goto failed;
2663 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2664 if (!value) goto failed;
2665 if (PyObject_SetAttrString(result, "elts", value) == -1)
2666 goto failed;
2667 Py_DECREF(value);
2668 value = ast2obj_expr_context(o->v.Tuple.ctx);
2669 if (!value) goto failed;
2670 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2671 goto failed;
2672 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002673 break;
2674 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002675 value = ast2obj_int(o->lineno);
2676 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002677 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2678 goto failed;
2679 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002680 value = ast2obj_int(o->col_offset);
2681 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002682 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2683 goto failed;
2684 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002685 return result;
2686failed:
2687 Py_XDECREF(value);
2688 Py_XDECREF(result);
2689 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690}
2691
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002692PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 switch(o) {
2695 case Load:
2696 Py_INCREF(Load_singleton);
2697 return Load_singleton;
2698 case Store:
2699 Py_INCREF(Store_singleton);
2700 return Store_singleton;
2701 case Del:
2702 Py_INCREF(Del_singleton);
2703 return Del_singleton;
2704 case AugLoad:
2705 Py_INCREF(AugLoad_singleton);
2706 return AugLoad_singleton;
2707 case AugStore:
2708 Py_INCREF(AugStore_singleton);
2709 return AugStore_singleton;
2710 case Param:
2711 Py_INCREF(Param_singleton);
2712 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002713 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002714 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002716PyObject*
2717ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002718{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002719 slice_ty o = (slice_ty)_o;
2720 PyObject *result = NULL, *value = NULL;
2721 if (!o) {
2722 Py_INCREF(Py_None);
2723 return Py_None;
2724 }
2725
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002726 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002727 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002728 result = PyType_GenericNew(Slice_type, NULL, NULL);
2729 if (!result) goto failed;
2730 value = ast2obj_expr(o->v.Slice.lower);
2731 if (!value) goto failed;
2732 if (PyObject_SetAttrString(result, "lower", value) == -1)
2733 goto failed;
2734 Py_DECREF(value);
2735 value = ast2obj_expr(o->v.Slice.upper);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "upper", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
2740 value = ast2obj_expr(o->v.Slice.step);
2741 if (!value) goto failed;
2742 if (PyObject_SetAttrString(result, "step", value) == -1)
2743 goto failed;
2744 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002745 break;
2746 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002747 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2748 if (!result) goto failed;
2749 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2750 if (!value) goto failed;
2751 if (PyObject_SetAttrString(result, "dims", value) == -1)
2752 goto failed;
2753 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002754 break;
2755 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002756 result = PyType_GenericNew(Index_type, NULL, NULL);
2757 if (!result) goto failed;
2758 value = ast2obj_expr(o->v.Index.value);
2759 if (!value) goto failed;
2760 if (PyObject_SetAttrString(result, "value", value) == -1)
2761 goto failed;
2762 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002763 break;
2764 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002765 return result;
2766failed:
2767 Py_XDECREF(value);
2768 Py_XDECREF(result);
2769 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002770}
2771
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002772PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002773{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002774 switch(o) {
2775 case And:
2776 Py_INCREF(And_singleton);
2777 return And_singleton;
2778 case Or:
2779 Py_INCREF(Or_singleton);
2780 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002781 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002782 return NULL; /* cannot happen */
2783}
2784PyObject* ast2obj_operator(operator_ty o)
2785{
2786 switch(o) {
2787 case Add:
2788 Py_INCREF(Add_singleton);
2789 return Add_singleton;
2790 case Sub:
2791 Py_INCREF(Sub_singleton);
2792 return Sub_singleton;
2793 case Mult:
2794 Py_INCREF(Mult_singleton);
2795 return Mult_singleton;
2796 case Div:
2797 Py_INCREF(Div_singleton);
2798 return Div_singleton;
2799 case Mod:
2800 Py_INCREF(Mod_singleton);
2801 return Mod_singleton;
2802 case Pow:
2803 Py_INCREF(Pow_singleton);
2804 return Pow_singleton;
2805 case LShift:
2806 Py_INCREF(LShift_singleton);
2807 return LShift_singleton;
2808 case RShift:
2809 Py_INCREF(RShift_singleton);
2810 return RShift_singleton;
2811 case BitOr:
2812 Py_INCREF(BitOr_singleton);
2813 return BitOr_singleton;
2814 case BitXor:
2815 Py_INCREF(BitXor_singleton);
2816 return BitXor_singleton;
2817 case BitAnd:
2818 Py_INCREF(BitAnd_singleton);
2819 return BitAnd_singleton;
2820 case FloorDiv:
2821 Py_INCREF(FloorDiv_singleton);
2822 return FloorDiv_singleton;
2823 }
2824 return NULL; /* cannot happen */
2825}
2826PyObject* ast2obj_unaryop(unaryop_ty o)
2827{
2828 switch(o) {
2829 case Invert:
2830 Py_INCREF(Invert_singleton);
2831 return Invert_singleton;
2832 case Not:
2833 Py_INCREF(Not_singleton);
2834 return Not_singleton;
2835 case UAdd:
2836 Py_INCREF(UAdd_singleton);
2837 return UAdd_singleton;
2838 case USub:
2839 Py_INCREF(USub_singleton);
2840 return USub_singleton;
2841 }
2842 return NULL; /* cannot happen */
2843}
2844PyObject* ast2obj_cmpop(cmpop_ty o)
2845{
2846 switch(o) {
2847 case Eq:
2848 Py_INCREF(Eq_singleton);
2849 return Eq_singleton;
2850 case NotEq:
2851 Py_INCREF(NotEq_singleton);
2852 return NotEq_singleton;
2853 case Lt:
2854 Py_INCREF(Lt_singleton);
2855 return Lt_singleton;
2856 case LtE:
2857 Py_INCREF(LtE_singleton);
2858 return LtE_singleton;
2859 case Gt:
2860 Py_INCREF(Gt_singleton);
2861 return Gt_singleton;
2862 case GtE:
2863 Py_INCREF(GtE_singleton);
2864 return GtE_singleton;
2865 case Is:
2866 Py_INCREF(Is_singleton);
2867 return Is_singleton;
2868 case IsNot:
2869 Py_INCREF(IsNot_singleton);
2870 return IsNot_singleton;
2871 case In:
2872 Py_INCREF(In_singleton);
2873 return In_singleton;
2874 case NotIn:
2875 Py_INCREF(NotIn_singleton);
2876 return NotIn_singleton;
2877 }
2878 return NULL; /* cannot happen */
2879}
2880PyObject*
2881ast2obj_comprehension(void* _o)
2882{
2883 comprehension_ty o = (comprehension_ty)_o;
2884 PyObject *result = NULL, *value = NULL;
2885 if (!o) {
2886 Py_INCREF(Py_None);
2887 return Py_None;
2888 }
2889
2890 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2891 if (!result) return NULL;
2892 value = ast2obj_expr(o->target);
2893 if (!value) goto failed;
2894 if (PyObject_SetAttrString(result, "target", value) == -1)
2895 goto failed;
2896 Py_DECREF(value);
2897 value = ast2obj_expr(o->iter);
2898 if (!value) goto failed;
2899 if (PyObject_SetAttrString(result, "iter", value) == -1)
2900 goto failed;
2901 Py_DECREF(value);
2902 value = ast2obj_list(o->ifs, ast2obj_expr);
2903 if (!value) goto failed;
2904 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2905 goto failed;
2906 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002907 return result;
2908failed:
2909 Py_XDECREF(value);
2910 Py_XDECREF(result);
2911 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002912}
2913
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002914PyObject*
2915ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002916{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002917 excepthandler_ty o = (excepthandler_ty)_o;
2918 PyObject *result = NULL, *value = NULL;
2919 if (!o) {
2920 Py_INCREF(Py_None);
2921 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002922 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002923
2924 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2925 if (!result) return NULL;
2926 value = ast2obj_expr(o->type);
2927 if (!value) goto failed;
2928 if (PyObject_SetAttrString(result, "type", value) == -1)
2929 goto failed;
2930 Py_DECREF(value);
2931 value = ast2obj_expr(o->name);
2932 if (!value) goto failed;
2933 if (PyObject_SetAttrString(result, "name", value) == -1)
2934 goto failed;
2935 Py_DECREF(value);
2936 value = ast2obj_list(o->body, ast2obj_stmt);
2937 if (!value) goto failed;
2938 if (PyObject_SetAttrString(result, "body", value) == -1)
2939 goto failed;
2940 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002941 value = ast2obj_int(o->lineno);
2942 if (!value) goto failed;
2943 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2944 goto failed;
2945 Py_DECREF(value);
2946 value = ast2obj_int(o->col_offset);
2947 if (!value) goto failed;
2948 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2949 goto failed;
2950 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951 return result;
2952failed:
2953 Py_XDECREF(value);
2954 Py_XDECREF(result);
2955 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002956}
2957
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002958PyObject*
2959ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002960{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002961 arguments_ty o = (arguments_ty)_o;
2962 PyObject *result = NULL, *value = NULL;
2963 if (!o) {
2964 Py_INCREF(Py_None);
2965 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002966 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002967
2968 result = PyType_GenericNew(arguments_type, NULL, NULL);
2969 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002970 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "args", value) == -1)
2973 goto failed;
2974 Py_DECREF(value);
2975 value = ast2obj_identifier(o->vararg);
2976 if (!value) goto failed;
2977 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2978 goto failed;
2979 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002980 value = ast2obj_expr(o->varargannotation);
2981 if (!value) goto failed;
2982 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2983 goto failed;
2984 Py_DECREF(value);
2985 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002986 if (!value) goto failed;
2987 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2988 goto failed;
2989 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002990 value = ast2obj_identifier(o->kwarg);
2991 if (!value) goto failed;
2992 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2993 goto failed;
2994 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002995 value = ast2obj_expr(o->kwargannotation);
2996 if (!value) goto failed;
2997 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2998 goto failed;
2999 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003000 value = ast2obj_list(o->defaults, ast2obj_expr);
3001 if (!value) goto failed;
3002 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3003 goto failed;
3004 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003005 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3006 if (!value) goto failed;
3007 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3008 goto failed;
3009 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003010 return result;
3011failed:
3012 Py_XDECREF(value);
3013 Py_XDECREF(result);
3014 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003015}
3016
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003017PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003018ast2obj_arg(void* _o)
3019{
3020 arg_ty o = (arg_ty)_o;
3021 PyObject *result = NULL, *value = NULL;
3022 if (!o) {
3023 Py_INCREF(Py_None);
3024 return Py_None;
3025 }
3026
3027 switch (o->kind) {
3028 case SimpleArg_kind:
3029 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
3030 if (!result) goto failed;
3031 value = ast2obj_identifier(o->v.SimpleArg.arg);
3032 if (!value) goto failed;
3033 if (PyObject_SetAttrString(result, "arg", value) == -1)
3034 goto failed;
3035 Py_DECREF(value);
3036 value = ast2obj_expr(o->v.SimpleArg.annotation);
3037 if (!value) goto failed;
3038 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3039 goto failed;
3040 Py_DECREF(value);
3041 break;
3042 case NestedArgs_kind:
3043 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
3044 if (!result) goto failed;
3045 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3046 if (!value) goto failed;
3047 if (PyObject_SetAttrString(result, "args", value) == -1)
3048 goto failed;
3049 Py_DECREF(value);
3050 break;
3051 }
3052 return result;
3053failed:
3054 Py_XDECREF(value);
3055 Py_XDECREF(result);
3056 return NULL;
3057}
3058
3059PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003060ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003061{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003062 keyword_ty o = (keyword_ty)_o;
3063 PyObject *result = NULL, *value = NULL;
3064 if (!o) {
3065 Py_INCREF(Py_None);
3066 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003067 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003068
3069 result = PyType_GenericNew(keyword_type, NULL, NULL);
3070 if (!result) return NULL;
3071 value = ast2obj_identifier(o->arg);
3072 if (!value) goto failed;
3073 if (PyObject_SetAttrString(result, "arg", value) == -1)
3074 goto failed;
3075 Py_DECREF(value);
3076 value = ast2obj_expr(o->value);
3077 if (!value) goto failed;
3078 if (PyObject_SetAttrString(result, "value", value) == -1)
3079 goto failed;
3080 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003081 return result;
3082failed:
3083 Py_XDECREF(value);
3084 Py_XDECREF(result);
3085 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003086}
3087
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003088PyObject*
3089ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003090{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003091 alias_ty o = (alias_ty)_o;
3092 PyObject *result = NULL, *value = NULL;
3093 if (!o) {
3094 Py_INCREF(Py_None);
3095 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003096 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003097
3098 result = PyType_GenericNew(alias_type, NULL, NULL);
3099 if (!result) return NULL;
3100 value = ast2obj_identifier(o->name);
3101 if (!value) goto failed;
3102 if (PyObject_SetAttrString(result, "name", value) == -1)
3103 goto failed;
3104 Py_DECREF(value);
3105 value = ast2obj_identifier(o->asname);
3106 if (!value) goto failed;
3107 if (PyObject_SetAttrString(result, "asname", value) == -1)
3108 goto failed;
3109 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003110 return result;
3111failed:
3112 Py_XDECREF(value);
3113 Py_XDECREF(result);
3114 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003115}
3116
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003117
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003118PyMODINIT_FUNC
3119init_ast(void)
3120{
3121 PyObject *m, *d;
3122 if (!init_types()) return;
3123 m = Py_InitModule3("_ast", NULL, NULL);
3124 if (!m) return;
3125 d = PyModule_GetDict(m);
3126 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3127 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3128 return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003129 if (PyModule_AddStringConstant(m, "__version__", "52491") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003130 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003131 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3132 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3133 return;
3134 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3135 < 0) return;
3136 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3137 0) return;
3138 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3139 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3140 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3141 < 0) return;
3142 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3143 return;
3144 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3145 return;
3146 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3147 return;
3148 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3149 return;
3150 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3151 0) return;
3152 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3153 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3154 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3155 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3156 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3157 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3158 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3159 0) return;
3160 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3161 0) return;
3162 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3163 return;
3164 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3165 return;
3166 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3167 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003168 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3169 return;
3170 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3172 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3173 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3174 return;
3175 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3176 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3177 return;
3178 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3179 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3180 return;
3181 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3182 return;
3183 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3184 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003185 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003186 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3187 return;
3188 if (PyDict_SetItemString(d, "GeneratorExp",
3189 (PyObject*)GeneratorExp_type) < 0) return;
3190 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3191 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3192 return;
3193 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003194 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3195 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003196 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3197 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003198 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3199 0) return;
3200 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3201 0) return;
3202 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3203 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3204 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3205 if (PyDict_SetItemString(d, "expr_context",
3206 (PyObject*)expr_context_type) < 0) return;
3207 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3208 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3209 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3210 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3211 return;
3212 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3213 return;
3214 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3215 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003216 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3217 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3218 return;
3219 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3220 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3221 return;
3222 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3223 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3224 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3225 return;
3226 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3227 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3228 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3229 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3230 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3231 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3232 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3233 return;
3234 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3235 return;
3236 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3237 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3238 return;
3239 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3240 return;
3241 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3242 return;
3243 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3244 return;
3245 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3246 return;
3247 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3248 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3249 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3250 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3251 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3252 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3253 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3254 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3255 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3256 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3257 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3258 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3259 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3260 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3261 if (PyDict_SetItemString(d, "comprehension",
3262 (PyObject*)comprehension_type) < 0) return;
3263 if (PyDict_SetItemString(d, "excepthandler",
3264 (PyObject*)excepthandler_type) < 0) return;
3265 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3266 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003267 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3268 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3269 0) return;
3270 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3271 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}
3283
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003284