blob: 5aefbacf65302bfcfed77dfdc41e38f7e91a9f45 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Neal Norwitz6baa4c42007-02-26 19:14:12 +00005 __version__ 53956.
Thomas Wouterscf297e42007-02-23 15:07:44 +00006
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
10*/
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000011
12#include "Python.h"
13#include "Python-ast.h"
14
Neal Norwitz53d960c2006-02-28 22:47:29 +000015static PyTypeObject* AST_type;
16static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000017static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000018static PyTypeObject *Module_type;
19static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000020 "body",
21};
Neal Norwitz53d960c2006-02-28 22:47:29 +000022static PyTypeObject *Interactive_type;
23static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000024 "body",
25};
Neal Norwitz53d960c2006-02-28 22:47:29 +000026static PyTypeObject *Expression_type;
27static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000028 "body",
29};
Neal Norwitz53d960c2006-02-28 22:47:29 +000030static PyTypeObject *Suite_type;
31static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000032 "body",
33};
Neal Norwitz53d960c2006-02-28 22:47:29 +000034static PyTypeObject *stmt_type;
35static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000036 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000037 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000038};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000039static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000040static PyTypeObject *FunctionDef_type;
41static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000042 "name",
43 "args",
44 "body",
45 "decorators",
Neal Norwitzc1505362006-12-28 06:47:50 +000046 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *ClassDef_type;
49static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "name",
51 "bases",
52 "body",
53};
Neal Norwitz53d960c2006-02-28 22:47:29 +000054static PyTypeObject *Return_type;
55static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000056 "value",
57};
Neal Norwitz53d960c2006-02-28 22:47:29 +000058static PyTypeObject *Delete_type;
59static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000060 "targets",
61};
Neal Norwitz53d960c2006-02-28 22:47:29 +000062static PyTypeObject *Assign_type;
63static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000064 "targets",
65 "value",
66};
Neal Norwitz53d960c2006-02-28 22:47:29 +000067static PyTypeObject *AugAssign_type;
68static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000069 "target",
70 "op",
71 "value",
72};
Neal Norwitz53d960c2006-02-28 22:47:29 +000073static PyTypeObject *For_type;
74static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000075 "target",
76 "iter",
77 "body",
78 "orelse",
79};
Neal Norwitz53d960c2006-02-28 22:47:29 +000080static PyTypeObject *While_type;
81static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000082 "test",
83 "body",
84 "orelse",
85};
Neal Norwitz53d960c2006-02-28 22:47:29 +000086static PyTypeObject *If_type;
87static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000088 "test",
89 "body",
90 "orelse",
91};
Neal Norwitz53d960c2006-02-28 22:47:29 +000092static PyTypeObject *With_type;
93static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000094 "context_expr",
95 "optional_vars",
96 "body",
97};
Neal Norwitz53d960c2006-02-28 22:47:29 +000098static PyTypeObject *Raise_type;
99static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000100 "type",
101 "inst",
102 "tback",
103};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000104static PyTypeObject *TryExcept_type;
105static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000106 "body",
107 "handlers",
108 "orelse",
109};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000110static PyTypeObject *TryFinally_type;
111static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000112 "body",
113 "finalbody",
114};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000115static PyTypeObject *Assert_type;
116static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000117 "test",
118 "msg",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *Import_type;
121static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "names",
123};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000124static PyTypeObject *ImportFrom_type;
125static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000126 "module",
127 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000128 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000129};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000130static PyTypeObject *Global_type;
131static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000132 "names",
133};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000134static PyTypeObject *Expr_type;
135static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000136 "value",
137};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000138static PyTypeObject *Pass_type;
139static PyTypeObject *Break_type;
140static PyTypeObject *Continue_type;
141static PyTypeObject *expr_type;
142static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000143 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000144 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000145};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000146static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000147static PyTypeObject *BoolOp_type;
148static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000149 "op",
150 "values",
151};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000152static PyTypeObject *BinOp_type;
153static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000154 "left",
155 "op",
156 "right",
157};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000158static PyTypeObject *UnaryOp_type;
159static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000160 "op",
161 "operand",
162};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000163static PyTypeObject *Lambda_type;
164static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000165 "args",
166 "body",
167};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000168static PyTypeObject *IfExp_type;
169static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000170 "test",
171 "body",
172 "orelse",
173};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000174static PyTypeObject *Dict_type;
175static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000176 "keys",
177 "values",
178};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000179static PyTypeObject *Set_type;
180static char *Set_fields[]={
181 "elts",
182};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000183static PyTypeObject *ListComp_type;
184static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000185 "elt",
186 "generators",
187};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000188static PyTypeObject *GeneratorExp_type;
189static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000190 "elt",
191 "generators",
192};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000193static PyTypeObject *Yield_type;
194static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000195 "value",
196};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000197static PyTypeObject *Compare_type;
198static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000199 "left",
200 "ops",
201 "comparators",
202};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000203static PyTypeObject *Call_type;
204static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000205 "func",
206 "args",
207 "keywords",
208 "starargs",
209 "kwargs",
210};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000211static PyTypeObject *Num_type;
212static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213 "n",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Str_type;
216static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "s",
218};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000219static PyTypeObject *Bytes_type;
220static char *Bytes_fields[]={
221 "s",
222};
Georg Brandl52318d62006-09-06 07:06:08 +0000223static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000224static PyTypeObject *Attribute_type;
225static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000226 "value",
227 "attr",
228 "ctx",
229};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000230static PyTypeObject *Subscript_type;
231static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000232 "value",
233 "slice",
234 "ctx",
235};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000236static PyTypeObject *Name_type;
237static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000238 "id",
239 "ctx",
240};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000241static PyTypeObject *List_type;
242static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000243 "elts",
244 "ctx",
245};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000246static PyTypeObject *Tuple_type;
247static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000248 "elts",
249 "ctx",
250};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000251static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000252static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
253*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
254static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000255static PyTypeObject *Load_type;
256static PyTypeObject *Store_type;
257static PyTypeObject *Del_type;
258static PyTypeObject *AugLoad_type;
259static PyTypeObject *AugStore_type;
260static PyTypeObject *Param_type;
261static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000262static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000263static PyTypeObject *Slice_type;
264static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000265 "lower",
266 "upper",
267 "step",
268};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *ExtSlice_type;
270static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271 "dims",
272};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000273static PyTypeObject *Index_type;
274static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000275 "value",
276};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000277static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000278static PyObject *And_singleton, *Or_singleton;
279static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *And_type;
281static PyTypeObject *Or_type;
282static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000283static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
284*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
285*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
286*FloorDiv_singleton;
287static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000288static PyTypeObject *Add_type;
289static PyTypeObject *Sub_type;
290static PyTypeObject *Mult_type;
291static PyTypeObject *Div_type;
292static PyTypeObject *Mod_type;
293static PyTypeObject *Pow_type;
294static PyTypeObject *LShift_type;
295static PyTypeObject *RShift_type;
296static PyTypeObject *BitOr_type;
297static PyTypeObject *BitXor_type;
298static PyTypeObject *BitAnd_type;
299static PyTypeObject *FloorDiv_type;
300static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000301static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
302*USub_singleton;
303static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000304static PyTypeObject *Invert_type;
305static PyTypeObject *Not_type;
306static PyTypeObject *UAdd_type;
307static PyTypeObject *USub_type;
308static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000309static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
310*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
311*NotIn_singleton;
312static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000313static PyTypeObject *Eq_type;
314static PyTypeObject *NotEq_type;
315static PyTypeObject *Lt_type;
316static PyTypeObject *LtE_type;
317static PyTypeObject *Gt_type;
318static PyTypeObject *GtE_type;
319static PyTypeObject *Is_type;
320static PyTypeObject *IsNot_type;
321static PyTypeObject *In_type;
322static PyTypeObject *NotIn_type;
323static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000325static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000326 "target",
327 "iter",
328 "ifs",
329};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000332static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333 "type",
334 "name",
335 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000336 "lineno",
337 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000339static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000341static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342 "args",
343 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000344 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000345 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000347 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000349 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350};
Neal Norwitzc1505362006-12-28 06:47:50 +0000351static PyTypeObject *arg_type;
352static PyObject* ast2obj_arg(void*);
353static PyTypeObject *SimpleArg_type;
354static char *SimpleArg_fields[]={
355 "arg",
356 "annotation",
357};
358static PyTypeObject *NestedArgs_type;
359static char *NestedArgs_fields[]={
360 "args",
361};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000362static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000363static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000364static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000365 "arg",
366 "value",
367};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000368static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000369static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000370static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000371 "name",
372 "asname",
373};
374
375
376static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
377{
378 PyObject *fnames, *result;
379 int i;
380 if (num_fields) {
381 fnames = PyTuple_New(num_fields);
382 if (!fnames) return NULL;
383 } else {
384 fnames = Py_None;
385 Py_INCREF(Py_None);
386 }
387 for(i=0; i < num_fields; i++) {
388 PyObject *field = PyString_FromString(fields[i]);
389 if (!field) {
390 Py_DECREF(fnames);
391 return NULL;
392 }
393 PyTuple_SET_ITEM(fnames, i, field);
394 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000395 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000396 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000397 Py_DECREF(fnames);
398 return (PyTypeObject*)result;
399}
400
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000401static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
402{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000403 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000404 PyObject *s, *l = PyList_New(num_fields);
405 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000406 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000407 s = PyString_FromString(attrs[i]);
408 if (!s) {
409 Py_DECREF(l);
410 return 0;
411 }
412 PyList_SET_ITEM(l, i, s);
413 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000414 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
415 Py_DECREF(l);
416 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000417}
418
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000419static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
420{
421 int i, n = asdl_seq_LEN(seq);
422 PyObject *result = PyList_New(n);
423 PyObject *value;
424 if (!result)
425 return NULL;
426 for (i = 0; i < n; i++) {
427 value = func(asdl_seq_GET(seq, i));
428 if (!value) {
429 Py_DECREF(result);
430 return NULL;
431 }
432 PyList_SET_ITEM(result, i, value);
433 }
434 return result;
435}
436
437static PyObject* ast2obj_object(void *o)
438{
439 if (!o)
440 o = Py_None;
441 Py_INCREF((PyObject*)o);
442 return (PyObject*)o;
443}
444#define ast2obj_identifier ast2obj_object
445#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000446
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000447static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000448{
449 return PyInt_FromLong(b);
450}
451
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000452static int init_types(void)
453{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000454 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000455 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000456 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
457 mod_type = make_type("mod", AST_type, NULL, 0);
458 if (!mod_type) return 0;
459 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000460 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000461 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000462 Interactive_type = make_type("Interactive", mod_type,
463 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Expression_type = make_type("Expression", mod_type, Expression_fields,
466 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000467 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000468 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000469 if (!Suite_type) return 0;
470 stmt_type = make_type("stmt", AST_type, NULL, 0);
471 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000472 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000474 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000475 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000476 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000477 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000478 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000492 With_type = make_type("With", stmt_type, With_fields, 3);
493 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000497 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
499 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000506 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000512 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000514 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000516 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Continue_type) return 0;
518 expr_type = make_type("expr", AST_type, NULL, 0);
519 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000520 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000521 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000523 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000529 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000533 Set_type = make_type("Set", expr_type, Set_fields, 1);
534 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 GeneratorExp_type = make_type("GeneratorExp", expr_type,
538 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000539 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000550 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
551 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000552 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
553 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Tuple_type) return 0;
564 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
565 if (!expr_context_type) return 0;
566 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000567 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000569 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000571 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000573 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000575 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000579 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000583 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000587 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000589 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!Param_singleton) return 0;
591 slice_type = make_type("slice", AST_type, NULL, 0);
592 if (!slice_type) return 0;
593 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Index_type) return 0;
600 boolop_type = make_type("boolop", AST_type, NULL, 0);
601 if (!boolop_type) return 0;
602 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Or_singleton) return 0;
611 operator_type = make_type("operator", AST_type, NULL, 0);
612 if (!operator_type) return 0;
613 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000614 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000616 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000618 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000619 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000620 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000622 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000624 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000626 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000628 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000630 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000632 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000634 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000636 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000638 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000640 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000642 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000644 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000646 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000648 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000650 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!FloorDiv_singleton) return 0;
662 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
663 if (!unaryop_type) return 0;
664 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000665 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000667 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!USub_singleton) return 0;
681 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
682 if (!cmpop_type) return 0;
683 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000684 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000686 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000688 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000690 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000692 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000694 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000696 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000698 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000700 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000704 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000706 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000708 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000710 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000712 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000714 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000716 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000718 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000720 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000722 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!NotIn_singleton) return 0;
724 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000725 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!comprehension_type) return 0;
727 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000728 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000730 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000731 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000732 arg_type = make_type("arg", AST_type, NULL, 0);
733 if (!arg_type) return 0;
734 if (!add_attributes(arg_type, NULL, 0)) return 0;
735 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
736 if (!SimpleArg_type) return 0;
737 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
738 1);
739 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000740 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
741 if (!keyword_type) return 0;
742 alias_type = make_type("alias", AST_type, alias_fields, 2);
743 if (!alias_type) return 0;
744 initialized = 1;
745 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000746}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000747
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000748mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000749Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000750{
751 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000752 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000753 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000754 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000755 p->kind = Module_kind;
756 p->v.Module.body = body;
757 return p;
758}
759
760mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000761Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000762{
763 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000764 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000765 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 p->kind = Interactive_kind;
768 p->v.Interactive.body = body;
769 return p;
770}
771
772mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000773Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000774{
775 mod_ty p;
776 if (!body) {
777 PyErr_SetString(PyExc_ValueError,
778 "field body is required for Expression");
779 return NULL;
780 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000781 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000782 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000784 p->kind = Expression_kind;
785 p->v.Expression.body = body;
786 return p;
787}
788
789mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000790Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000791{
792 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000793 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000794 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000795 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000796 p->kind = Suite_kind;
797 p->v.Suite.body = body;
798 return p;
799}
800
801stmt_ty
802FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000803 decorators, expr_ty returns, int lineno, int col_offset, PyArena
804 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000805{
806 stmt_ty p;
807 if (!name) {
808 PyErr_SetString(PyExc_ValueError,
809 "field name is required for FunctionDef");
810 return NULL;
811 }
812 if (!args) {
813 PyErr_SetString(PyExc_ValueError,
814 "field args is required for FunctionDef");
815 return NULL;
816 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000817 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000818 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000819 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000820 p->kind = FunctionDef_kind;
821 p->v.FunctionDef.name = name;
822 p->v.FunctionDef.args = args;
823 p->v.FunctionDef.body = body;
824 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000825 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000827 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000828 return p;
829}
830
831stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000832ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
833 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000834{
835 stmt_ty p;
836 if (!name) {
837 PyErr_SetString(PyExc_ValueError,
838 "field name is required for ClassDef");
839 return NULL;
840 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000841 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000842 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000844 p->kind = ClassDef_kind;
845 p->v.ClassDef.name = name;
846 p->v.ClassDef.bases = bases;
847 p->v.ClassDef.body = body;
848 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000849 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000850 return p;
851}
852
853stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000854Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000855{
856 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000857 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000858 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860 p->kind = Return_kind;
861 p->v.Return.value = value;
862 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000863 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864 return p;
865}
866
867stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000868Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000869{
870 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000871 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000872 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 p->kind = Delete_kind;
875 p->v.Delete.targets = targets;
876 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000877 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000878 return p;
879}
880
881stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000882Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
883 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000884{
885 stmt_ty p;
886 if (!value) {
887 PyErr_SetString(PyExc_ValueError,
888 "field value is required for Assign");
889 return NULL;
890 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000891 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000892 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000893 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894 p->kind = Assign_kind;
895 p->v.Assign.targets = targets;
896 p->v.Assign.value = value;
897 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000898 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 return p;
900}
901
902stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000903AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
904 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000905{
906 stmt_ty p;
907 if (!target) {
908 PyErr_SetString(PyExc_ValueError,
909 "field target is required for AugAssign");
910 return NULL;
911 }
912 if (!op) {
913 PyErr_SetString(PyExc_ValueError,
914 "field op is required for AugAssign");
915 return NULL;
916 }
917 if (!value) {
918 PyErr_SetString(PyExc_ValueError,
919 "field value is required for AugAssign");
920 return NULL;
921 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000922 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000923 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000924 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000925 p->kind = AugAssign_kind;
926 p->v.AugAssign.target = target;
927 p->v.AugAssign.op = op;
928 p->v.AugAssign.value = value;
929 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000930 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931 return p;
932}
933
934stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000935For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000936 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000937{
938 stmt_ty p;
939 if (!target) {
940 PyErr_SetString(PyExc_ValueError,
941 "field target is required for For");
942 return NULL;
943 }
944 if (!iter) {
945 PyErr_SetString(PyExc_ValueError,
946 "field iter is required for For");
947 return NULL;
948 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000949 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000950 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000952 p->kind = For_kind;
953 p->v.For.target = target;
954 p->v.For.iter = iter;
955 p->v.For.body = body;
956 p->v.For.orelse = orelse;
957 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000958 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000959 return p;
960}
961
962stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000963While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
964 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000965{
966 stmt_ty p;
967 if (!test) {
968 PyErr_SetString(PyExc_ValueError,
969 "field test is required for While");
970 return NULL;
971 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000972 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000973 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000974 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000975 p->kind = While_kind;
976 p->v.While.test = test;
977 p->v.While.body = body;
978 p->v.While.orelse = orelse;
979 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000980 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000981 return p;
982}
983
984stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000985If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
986 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987{
988 stmt_ty p;
989 if (!test) {
990 PyErr_SetString(PyExc_ValueError,
991 "field test is required for If");
992 return NULL;
993 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000994 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000995 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000996 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000997 p->kind = If_kind;
998 p->v.If.test = test;
999 p->v.If.body = body;
1000 p->v.If.orelse = orelse;
1001 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001002 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003 return p;
1004}
1005
1006stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001007With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001008 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001009{
1010 stmt_ty p;
1011 if (!context_expr) {
1012 PyErr_SetString(PyExc_ValueError,
1013 "field context_expr is required for With");
1014 return NULL;
1015 }
1016 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001017 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001018 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001019 p->kind = With_kind;
1020 p->v.With.context_expr = context_expr;
1021 p->v.With.optional_vars = optional_vars;
1022 p->v.With.body = body;
1023 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001024 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025 return p;
1026}
1027
1028stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001029Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1030 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001031{
1032 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001033 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001034 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001035 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001036 p->kind = Raise_kind;
1037 p->v.Raise.type = type;
1038 p->v.Raise.inst = inst;
1039 p->v.Raise.tback = tback;
1040 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001041 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001042 return p;
1043}
1044
1045stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001046TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001047 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001048{
1049 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001050 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001051 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001052 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001053 p->kind = TryExcept_kind;
1054 p->v.TryExcept.body = body;
1055 p->v.TryExcept.handlers = handlers;
1056 p->v.TryExcept.orelse = orelse;
1057 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001058 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001059 return p;
1060}
1061
1062stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001063TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1064 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001065{
1066 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001067 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001068 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001069 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070 p->kind = TryFinally_kind;
1071 p->v.TryFinally.body = body;
1072 p->v.TryFinally.finalbody = finalbody;
1073 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001074 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return p;
1076}
1077
1078stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001079Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001080{
1081 stmt_ty p;
1082 if (!test) {
1083 PyErr_SetString(PyExc_ValueError,
1084 "field test is required for Assert");
1085 return NULL;
1086 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001087 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001088 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001090 p->kind = Assert_kind;
1091 p->v.Assert.test = test;
1092 p->v.Assert.msg = msg;
1093 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001094 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 return p;
1096}
1097
1098stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001099Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001100{
1101 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001102 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001103 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001105 p->kind = Import_kind;
1106 p->v.Import.names = names;
1107 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001108 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001109 return p;
1110}
1111
1112stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001113ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1114 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001115{
1116 stmt_ty p;
1117 if (!module) {
1118 PyErr_SetString(PyExc_ValueError,
1119 "field module is required for ImportFrom");
1120 return NULL;
1121 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001122 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001123 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001124 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 p->kind = ImportFrom_kind;
1126 p->v.ImportFrom.module = module;
1127 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001128 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001130 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 return p;
1132}
1133
1134stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001135Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001136{
1137 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001138 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001139 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001140 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001141 p->kind = Global_kind;
1142 p->v.Global.names = names;
1143 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001144 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 return p;
1146}
1147
1148stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001149Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001150{
1151 stmt_ty p;
1152 if (!value) {
1153 PyErr_SetString(PyExc_ValueError,
1154 "field value is required for Expr");
1155 return NULL;
1156 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001157 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001158 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001160 p->kind = Expr_kind;
1161 p->v.Expr.value = value;
1162 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001163 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001164 return p;
1165}
1166
1167stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001168Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169{
1170 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001171 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001172 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001174 p->kind = Pass_kind;
1175 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001176 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 return p;
1178}
1179
1180stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001181Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001182{
1183 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001184 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001185 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001186 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001187 p->kind = Break_kind;
1188 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001189 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190 return p;
1191}
1192
1193stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001194Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001195{
1196 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001197 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001198 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 p->kind = Continue_kind;
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
1206expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001207BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1208 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209{
1210 expr_ty p;
1211 if (!op) {
1212 PyErr_SetString(PyExc_ValueError,
1213 "field op is required for BoolOp");
1214 return NULL;
1215 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001216 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001217 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001219 p->kind = BoolOp_kind;
1220 p->v.BoolOp.op = op;
1221 p->v.BoolOp.values = values;
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
1227expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001228BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1229 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230{
1231 expr_ty p;
1232 if (!left) {
1233 PyErr_SetString(PyExc_ValueError,
1234 "field left is required for BinOp");
1235 return NULL;
1236 }
1237 if (!op) {
1238 PyErr_SetString(PyExc_ValueError,
1239 "field op is required for BinOp");
1240 return NULL;
1241 }
1242 if (!right) {
1243 PyErr_SetString(PyExc_ValueError,
1244 "field right is required for BinOp");
1245 return NULL;
1246 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001247 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001248 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250 p->kind = BinOp_kind;
1251 p->v.BinOp.left = left;
1252 p->v.BinOp.op = op;
1253 p->v.BinOp.right = right;
1254 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001255 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001256 return p;
1257}
1258
1259expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001260UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1261 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001262{
1263 expr_ty p;
1264 if (!op) {
1265 PyErr_SetString(PyExc_ValueError,
1266 "field op is required for UnaryOp");
1267 return NULL;
1268 }
1269 if (!operand) {
1270 PyErr_SetString(PyExc_ValueError,
1271 "field operand is required for UnaryOp");
1272 return NULL;
1273 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001274 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001275 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001276 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001277 p->kind = UnaryOp_kind;
1278 p->v.UnaryOp.op = op;
1279 p->v.UnaryOp.operand = operand;
1280 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001281 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001282 return p;
1283}
1284
1285expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001286Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1287 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001288{
1289 expr_ty p;
1290 if (!args) {
1291 PyErr_SetString(PyExc_ValueError,
1292 "field args is required for Lambda");
1293 return NULL;
1294 }
1295 if (!body) {
1296 PyErr_SetString(PyExc_ValueError,
1297 "field body is required for Lambda");
1298 return NULL;
1299 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001300 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001301 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001303 p->kind = Lambda_kind;
1304 p->v.Lambda.args = args;
1305 p->v.Lambda.body = body;
1306 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001307 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001308 return p;
1309}
1310
1311expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001312IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1313 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001314{
1315 expr_ty p;
1316 if (!test) {
1317 PyErr_SetString(PyExc_ValueError,
1318 "field test is required for IfExp");
1319 return NULL;
1320 }
1321 if (!body) {
1322 PyErr_SetString(PyExc_ValueError,
1323 "field body is required for IfExp");
1324 return NULL;
1325 }
1326 if (!orelse) {
1327 PyErr_SetString(PyExc_ValueError,
1328 "field orelse is required for IfExp");
1329 return NULL;
1330 }
1331 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001332 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001333 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001334 p->kind = IfExp_kind;
1335 p->v.IfExp.test = test;
1336 p->v.IfExp.body = body;
1337 p->v.IfExp.orelse = orelse;
1338 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001339 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001340 return p;
1341}
1342
1343expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001344Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1345 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001346{
1347 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001348 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001349 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001350 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 p->kind = Dict_kind;
1352 p->v.Dict.keys = keys;
1353 p->v.Dict.values = values;
1354 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001355 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001356 return p;
1357}
1358
1359expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001360Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1361{
1362 expr_ty p;
1363 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001364 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001365 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001366 p->kind = Set_kind;
1367 p->v.Set.elts = elts;
1368 p->lineno = lineno;
1369 p->col_offset = col_offset;
1370 return p;
1371}
1372
1373expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001374ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1375 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001376{
1377 expr_ty p;
1378 if (!elt) {
1379 PyErr_SetString(PyExc_ValueError,
1380 "field elt is required for ListComp");
1381 return NULL;
1382 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001383 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001384 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001385 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001386 p->kind = ListComp_kind;
1387 p->v.ListComp.elt = elt;
1388 p->v.ListComp.generators = generators;
1389 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001390 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001391 return p;
1392}
1393
1394expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001395GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1396 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001397{
1398 expr_ty p;
1399 if (!elt) {
1400 PyErr_SetString(PyExc_ValueError,
1401 "field elt is required for GeneratorExp");
1402 return NULL;
1403 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001404 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001405 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001406 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001407 p->kind = GeneratorExp_kind;
1408 p->v.GeneratorExp.elt = elt;
1409 p->v.GeneratorExp.generators = generators;
1410 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001411 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001412 return p;
1413}
1414
1415expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001416Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001417{
1418 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001419 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001420 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001421 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422 p->kind = Yield_kind;
1423 p->v.Yield.value = value;
1424 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001425 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426 return p;
1427}
1428
1429expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001430Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1431 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001432{
1433 expr_ty p;
1434 if (!left) {
1435 PyErr_SetString(PyExc_ValueError,
1436 "field left is required for Compare");
1437 return NULL;
1438 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001439 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001440 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001441 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001442 p->kind = Compare_kind;
1443 p->v.Compare.left = left;
1444 p->v.Compare.ops = ops;
1445 p->v.Compare.comparators = comparators;
1446 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001447 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001448 return p;
1449}
1450
1451expr_ty
1452Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001453 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001454{
1455 expr_ty p;
1456 if (!func) {
1457 PyErr_SetString(PyExc_ValueError,
1458 "field func is required for Call");
1459 return NULL;
1460 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001461 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001462 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001464 p->kind = Call_kind;
1465 p->v.Call.func = func;
1466 p->v.Call.args = args;
1467 p->v.Call.keywords = keywords;
1468 p->v.Call.starargs = starargs;
1469 p->v.Call.kwargs = kwargs;
1470 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001471 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472 return p;
1473}
1474
1475expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001476Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477{
1478 expr_ty p;
1479 if (!n) {
1480 PyErr_SetString(PyExc_ValueError,
1481 "field n is required for Num");
1482 return NULL;
1483 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001484 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001485 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001486 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001487 p->kind = Num_kind;
1488 p->v.Num.n = n;
1489 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001490 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491 return p;
1492}
1493
1494expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001495Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001496{
1497 expr_ty p;
1498 if (!s) {
1499 PyErr_SetString(PyExc_ValueError,
1500 "field s is required for Str");
1501 return NULL;
1502 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001503 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001504 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001505 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506 p->kind = Str_kind;
1507 p->v.Str.s = s;
1508 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001509 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 return p;
1511}
1512
1513expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001514Bytes(string s, int lineno, int col_offset, PyArena *arena)
1515{
1516 expr_ty p;
1517 if (!s) {
1518 PyErr_SetString(PyExc_ValueError,
1519 "field s is required for Bytes");
1520 return NULL;
1521 }
1522 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001523 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001524 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001525 p->kind = Bytes_kind;
1526 p->v.Bytes.s = s;
1527 p->lineno = lineno;
1528 p->col_offset = col_offset;
1529 return p;
1530}
1531
1532expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001533Ellipsis(int lineno, int col_offset, PyArena *arena)
1534{
1535 expr_ty p;
1536 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001537 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001538 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001539 p->kind = Ellipsis_kind;
1540 p->lineno = lineno;
1541 p->col_offset = col_offset;
1542 return p;
1543}
1544
1545expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001546Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1547 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548{
1549 expr_ty p;
1550 if (!value) {
1551 PyErr_SetString(PyExc_ValueError,
1552 "field value is required for Attribute");
1553 return NULL;
1554 }
1555 if (!attr) {
1556 PyErr_SetString(PyExc_ValueError,
1557 "field attr is required for Attribute");
1558 return NULL;
1559 }
1560 if (!ctx) {
1561 PyErr_SetString(PyExc_ValueError,
1562 "field ctx is required for Attribute");
1563 return NULL;
1564 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001565 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001566 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001568 p->kind = Attribute_kind;
1569 p->v.Attribute.value = value;
1570 p->v.Attribute.attr = attr;
1571 p->v.Attribute.ctx = ctx;
1572 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001573 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001574 return p;
1575}
1576
1577expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001578Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1579 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001580{
1581 expr_ty p;
1582 if (!value) {
1583 PyErr_SetString(PyExc_ValueError,
1584 "field value is required for Subscript");
1585 return NULL;
1586 }
1587 if (!slice) {
1588 PyErr_SetString(PyExc_ValueError,
1589 "field slice is required for Subscript");
1590 return NULL;
1591 }
1592 if (!ctx) {
1593 PyErr_SetString(PyExc_ValueError,
1594 "field ctx is required for Subscript");
1595 return NULL;
1596 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001597 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001598 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001599 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001600 p->kind = Subscript_kind;
1601 p->v.Subscript.value = value;
1602 p->v.Subscript.slice = slice;
1603 p->v.Subscript.ctx = ctx;
1604 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001605 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001606 return p;
1607}
1608
1609expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001610Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1611 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001612{
1613 expr_ty p;
1614 if (!id) {
1615 PyErr_SetString(PyExc_ValueError,
1616 "field id is required for Name");
1617 return NULL;
1618 }
1619 if (!ctx) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field ctx is required for Name");
1622 return NULL;
1623 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001625 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001626 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 p->kind = Name_kind;
1628 p->v.Name.id = id;
1629 p->v.Name.ctx = ctx;
1630 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001631 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001632 return p;
1633}
1634
1635expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001636List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1637 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001638{
1639 expr_ty p;
1640 if (!ctx) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field ctx is required for List");
1643 return NULL;
1644 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001645 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001646 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001647 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001648 p->kind = List_kind;
1649 p->v.List.elts = elts;
1650 p->v.List.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 +00001657Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1658 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659{
1660 expr_ty p;
1661 if (!ctx) {
1662 PyErr_SetString(PyExc_ValueError,
1663 "field ctx is required for Tuple");
1664 return NULL;
1665 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001666 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001667 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669 p->kind = Tuple_kind;
1670 p->v.Tuple.elts = elts;
1671 p->v.Tuple.ctx = ctx;
1672 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001673 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001674 return p;
1675}
1676
1677slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001678Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679{
1680 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001681 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001682 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001683 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 p->kind = Slice_kind;
1685 p->v.Slice.lower = lower;
1686 p->v.Slice.upper = upper;
1687 p->v.Slice.step = step;
1688 return p;
1689}
1690
1691slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001692ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001693{
1694 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001695 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001696 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001698 p->kind = ExtSlice_kind;
1699 p->v.ExtSlice.dims = dims;
1700 return p;
1701}
1702
1703slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001704Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001705{
1706 slice_ty p;
1707 if (!value) {
1708 PyErr_SetString(PyExc_ValueError,
1709 "field value is required for Index");
1710 return NULL;
1711 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001712 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001713 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001714 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 p->kind = Index_kind;
1716 p->v.Index.value = value;
1717 return p;
1718}
1719
1720comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001721comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001722{
1723 comprehension_ty p;
1724 if (!target) {
1725 PyErr_SetString(PyExc_ValueError,
1726 "field target is required for comprehension");
1727 return NULL;
1728 }
1729 if (!iter) {
1730 PyErr_SetString(PyExc_ValueError,
1731 "field iter is required for comprehension");
1732 return NULL;
1733 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001734 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001735 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001736 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001737 p->target = target;
1738 p->iter = iter;
1739 p->ifs = ifs;
1740 return p;
1741}
1742
1743excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001744excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001745 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001746{
1747 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001748 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001749 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001751 p->type = type;
1752 p->name = name;
1753 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001754 p->lineno = lineno;
1755 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756 return p;
1757}
1758
1759arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001760arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1761 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1762 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763{
1764 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001765 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001766 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001768 p->args = args;
1769 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001770 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001771 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001773 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001774 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001775 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 return p;
1777}
1778
Neal Norwitzc1505362006-12-28 06:47:50 +00001779arg_ty
1780SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1781{
1782 arg_ty p;
1783 if (!arg) {
1784 PyErr_SetString(PyExc_ValueError,
1785 "field arg is required for SimpleArg");
1786 return NULL;
1787 }
1788 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001789 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001790 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001791 p->kind = SimpleArg_kind;
1792 p->v.SimpleArg.arg = arg;
1793 p->v.SimpleArg.annotation = annotation;
1794 return p;
1795}
1796
1797arg_ty
1798NestedArgs(asdl_seq * args, PyArena *arena)
1799{
1800 arg_ty p;
1801 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001802 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001803 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001804 p->kind = NestedArgs_kind;
1805 p->v.NestedArgs.args = args;
1806 return p;
1807}
1808
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001809keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001810keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001811{
1812 keyword_ty p;
1813 if (!arg) {
1814 PyErr_SetString(PyExc_ValueError,
1815 "field arg is required for keyword");
1816 return NULL;
1817 }
1818 if (!value) {
1819 PyErr_SetString(PyExc_ValueError,
1820 "field value is required for keyword");
1821 return NULL;
1822 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001823 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001824 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001825 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001826 p->arg = arg;
1827 p->value = value;
1828 return p;
1829}
1830
1831alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001832alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833{
1834 alias_ty p;
1835 if (!name) {
1836 PyErr_SetString(PyExc_ValueError,
1837 "field name is required for alias");
1838 return NULL;
1839 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001840 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001841 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001842 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001843 p->name = name;
1844 p->asname = asname;
1845 return p;
1846}
1847
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001848
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001849PyObject*
1850ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001851{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001852 mod_ty o = (mod_ty)_o;
1853 PyObject *result = NULL, *value = NULL;
1854 if (!o) {
1855 Py_INCREF(Py_None);
1856 return Py_None;
1857 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001858
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001859 switch (o->kind) {
1860 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001861 result = PyType_GenericNew(Module_type, NULL, NULL);
1862 if (!result) goto failed;
1863 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1864 if (!value) goto failed;
1865 if (PyObject_SetAttrString(result, "body", value) == -1)
1866 goto failed;
1867 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868 break;
1869 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001870 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1871 if (!result) goto failed;
1872 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1873 if (!value) goto failed;
1874 if (PyObject_SetAttrString(result, "body", value) == -1)
1875 goto failed;
1876 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877 break;
1878 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001879 result = PyType_GenericNew(Expression_type, NULL, NULL);
1880 if (!result) goto failed;
1881 value = ast2obj_expr(o->v.Expression.body);
1882 if (!value) goto failed;
1883 if (PyObject_SetAttrString(result, "body", value) == -1)
1884 goto failed;
1885 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886 break;
1887 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001888 result = PyType_GenericNew(Suite_type, NULL, NULL);
1889 if (!result) goto failed;
1890 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1891 if (!value) goto failed;
1892 if (PyObject_SetAttrString(result, "body", value) == -1)
1893 goto failed;
1894 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001895 break;
1896 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001897 return result;
1898failed:
1899 Py_XDECREF(value);
1900 Py_XDECREF(result);
1901 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001902}
1903
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001904PyObject*
1905ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001907 stmt_ty o = (stmt_ty)_o;
1908 PyObject *result = NULL, *value = NULL;
1909 if (!o) {
1910 Py_INCREF(Py_None);
1911 return Py_None;
1912 }
1913
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001914 switch (o->kind) {
1915 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001916 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1917 if (!result) goto failed;
1918 value = ast2obj_identifier(o->v.FunctionDef.name);
1919 if (!value) goto failed;
1920 if (PyObject_SetAttrString(result, "name", value) == -1)
1921 goto failed;
1922 Py_DECREF(value);
1923 value = ast2obj_arguments(o->v.FunctionDef.args);
1924 if (!value) goto failed;
1925 if (PyObject_SetAttrString(result, "args", value) == -1)
1926 goto failed;
1927 Py_DECREF(value);
1928 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1929 if (!value) goto failed;
1930 if (PyObject_SetAttrString(result, "body", value) == -1)
1931 goto failed;
1932 Py_DECREF(value);
1933 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1934 if (!value) goto failed;
1935 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1936 goto failed;
1937 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00001938 value = ast2obj_expr(o->v.FunctionDef.returns);
1939 if (!value) goto failed;
1940 if (PyObject_SetAttrString(result, "returns", value) == -1)
1941 goto failed;
1942 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001943 break;
1944 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001945 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1946 if (!result) goto failed;
1947 value = ast2obj_identifier(o->v.ClassDef.name);
1948 if (!value) goto failed;
1949 if (PyObject_SetAttrString(result, "name", value) == -1)
1950 goto failed;
1951 Py_DECREF(value);
1952 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1953 if (!value) goto failed;
1954 if (PyObject_SetAttrString(result, "bases", value) == -1)
1955 goto failed;
1956 Py_DECREF(value);
1957 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1958 if (!value) goto failed;
1959 if (PyObject_SetAttrString(result, "body", value) == -1)
1960 goto failed;
1961 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001962 break;
1963 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001964 result = PyType_GenericNew(Return_type, NULL, NULL);
1965 if (!result) goto failed;
1966 value = ast2obj_expr(o->v.Return.value);
1967 if (!value) goto failed;
1968 if (PyObject_SetAttrString(result, "value", value) == -1)
1969 goto failed;
1970 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001971 break;
1972 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001973 result = PyType_GenericNew(Delete_type, NULL, NULL);
1974 if (!result) goto failed;
1975 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1976 if (!value) goto failed;
1977 if (PyObject_SetAttrString(result, "targets", value) == -1)
1978 goto failed;
1979 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001980 break;
1981 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001982 result = PyType_GenericNew(Assign_type, NULL, NULL);
1983 if (!result) goto failed;
1984 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1985 if (!value) goto failed;
1986 if (PyObject_SetAttrString(result, "targets", value) == -1)
1987 goto failed;
1988 Py_DECREF(value);
1989 value = ast2obj_expr(o->v.Assign.value);
1990 if (!value) goto failed;
1991 if (PyObject_SetAttrString(result, "value", value) == -1)
1992 goto failed;
1993 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001994 break;
1995 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001996 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
1997 if (!result) goto failed;
1998 value = ast2obj_expr(o->v.AugAssign.target);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "target", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
2003 value = ast2obj_operator(o->v.AugAssign.op);
2004 if (!value) goto failed;
2005 if (PyObject_SetAttrString(result, "op", value) == -1)
2006 goto failed;
2007 Py_DECREF(value);
2008 value = ast2obj_expr(o->v.AugAssign.value);
2009 if (!value) goto failed;
2010 if (PyObject_SetAttrString(result, "value", value) == -1)
2011 goto failed;
2012 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002013 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002014 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002015 result = PyType_GenericNew(For_type, NULL, NULL);
2016 if (!result) goto failed;
2017 value = ast2obj_expr(o->v.For.target);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "target", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_expr(o->v.For.iter);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "iter", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
2027 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2028 if (!value) goto failed;
2029 if (PyObject_SetAttrString(result, "body", value) == -1)
2030 goto failed;
2031 Py_DECREF(value);
2032 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2033 if (!value) goto failed;
2034 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2035 goto failed;
2036 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002037 break;
2038 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002039 result = PyType_GenericNew(While_type, NULL, NULL);
2040 if (!result) goto failed;
2041 value = ast2obj_expr(o->v.While.test);
2042 if (!value) goto failed;
2043 if (PyObject_SetAttrString(result, "test", value) == -1)
2044 goto failed;
2045 Py_DECREF(value);
2046 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2047 if (!value) goto failed;
2048 if (PyObject_SetAttrString(result, "body", value) == -1)
2049 goto failed;
2050 Py_DECREF(value);
2051 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2052 if (!value) goto failed;
2053 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2054 goto failed;
2055 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002056 break;
2057 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002058 result = PyType_GenericNew(If_type, NULL, NULL);
2059 if (!result) goto failed;
2060 value = ast2obj_expr(o->v.If.test);
2061 if (!value) goto failed;
2062 if (PyObject_SetAttrString(result, "test", value) == -1)
2063 goto failed;
2064 Py_DECREF(value);
2065 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "body", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
2070 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002075 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002076 case With_kind:
2077 result = PyType_GenericNew(With_type, NULL, NULL);
2078 if (!result) goto failed;
2079 value = ast2obj_expr(o->v.With.context_expr);
2080 if (!value) goto failed;
2081 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2082 goto failed;
2083 Py_DECREF(value);
2084 value = ast2obj_expr(o->v.With.optional_vars);
2085 if (!value) goto failed;
2086 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2087 -1)
2088 goto failed;
2089 Py_DECREF(value);
2090 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2091 if (!value) goto failed;
2092 if (PyObject_SetAttrString(result, "body", value) == -1)
2093 goto failed;
2094 Py_DECREF(value);
2095 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002097 result = PyType_GenericNew(Raise_type, NULL, NULL);
2098 if (!result) goto failed;
2099 value = ast2obj_expr(o->v.Raise.type);
2100 if (!value) goto failed;
2101 if (PyObject_SetAttrString(result, "type", value) == -1)
2102 goto failed;
2103 Py_DECREF(value);
2104 value = ast2obj_expr(o->v.Raise.inst);
2105 if (!value) goto failed;
2106 if (PyObject_SetAttrString(result, "inst", value) == -1)
2107 goto failed;
2108 Py_DECREF(value);
2109 value = ast2obj_expr(o->v.Raise.tback);
2110 if (!value) goto failed;
2111 if (PyObject_SetAttrString(result, "tback", value) == -1)
2112 goto failed;
2113 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002114 break;
2115 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002116 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2117 if (!result) goto failed;
2118 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2119 if (!value) goto failed;
2120 if (PyObject_SetAttrString(result, "body", value) == -1)
2121 goto failed;
2122 Py_DECREF(value);
2123 value = ast2obj_list(o->v.TryExcept.handlers,
2124 ast2obj_excepthandler);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002134 break;
2135 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002136 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2137 if (!result) goto failed;
2138 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "body", value) == -1)
2141 goto failed;
2142 Py_DECREF(value);
2143 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2144 if (!value) goto failed;
2145 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2146 goto failed;
2147 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002148 break;
2149 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002150 result = PyType_GenericNew(Assert_type, NULL, NULL);
2151 if (!result) goto failed;
2152 value = ast2obj_expr(o->v.Assert.test);
2153 if (!value) goto failed;
2154 if (PyObject_SetAttrString(result, "test", value) == -1)
2155 goto failed;
2156 Py_DECREF(value);
2157 value = ast2obj_expr(o->v.Assert.msg);
2158 if (!value) goto failed;
2159 if (PyObject_SetAttrString(result, "msg", value) == -1)
2160 goto failed;
2161 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002162 break;
2163 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002164 result = PyType_GenericNew(Import_type, NULL, NULL);
2165 if (!result) goto failed;
2166 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2167 if (!value) goto failed;
2168 if (PyObject_SetAttrString(result, "names", value) == -1)
2169 goto failed;
2170 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002171 break;
2172 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002173 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2174 if (!result) goto failed;
2175 value = ast2obj_identifier(o->v.ImportFrom.module);
2176 if (!value) goto failed;
2177 if (PyObject_SetAttrString(result, "module", value) == -1)
2178 goto failed;
2179 Py_DECREF(value);
2180 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2181 if (!value) goto failed;
2182 if (PyObject_SetAttrString(result, "names", value) == -1)
2183 goto failed;
2184 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002185 value = ast2obj_int(o->v.ImportFrom.level);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "level", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002190 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002191 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002192 result = PyType_GenericNew(Global_type, NULL, NULL);
2193 if (!result) goto failed;
2194 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "names", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199 break;
2200 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002201 result = PyType_GenericNew(Expr_type, NULL, NULL);
2202 if (!result) goto failed;
2203 value = ast2obj_expr(o->v.Expr.value);
2204 if (!value) goto failed;
2205 if (PyObject_SetAttrString(result, "value", value) == -1)
2206 goto failed;
2207 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002208 break;
2209 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002210 result = PyType_GenericNew(Pass_type, NULL, NULL);
2211 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002212 break;
2213 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002214 result = PyType_GenericNew(Break_type, NULL, NULL);
2215 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002216 break;
2217 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002218 result = PyType_GenericNew(Continue_type, NULL, NULL);
2219 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220 break;
2221 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002222 value = ast2obj_int(o->lineno);
2223 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002224 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2225 goto failed;
2226 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002227 value = ast2obj_int(o->col_offset);
2228 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002229 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2230 goto failed;
2231 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002232 return result;
2233failed:
2234 Py_XDECREF(value);
2235 Py_XDECREF(result);
2236 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002237}
2238
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002239PyObject*
2240ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002242 expr_ty o = (expr_ty)_o;
2243 PyObject *result = NULL, *value = NULL;
2244 if (!o) {
2245 Py_INCREF(Py_None);
2246 return Py_None;
2247 }
2248
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002249 switch (o->kind) {
2250 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002251 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2252 if (!result) goto failed;
2253 value = ast2obj_boolop(o->v.BoolOp.op);
2254 if (!value) goto failed;
2255 if (PyObject_SetAttrString(result, "op", value) == -1)
2256 goto failed;
2257 Py_DECREF(value);
2258 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2259 if (!value) goto failed;
2260 if (PyObject_SetAttrString(result, "values", value) == -1)
2261 goto failed;
2262 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002263 break;
2264 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002265 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2266 if (!result) goto failed;
2267 value = ast2obj_expr(o->v.BinOp.left);
2268 if (!value) goto failed;
2269 if (PyObject_SetAttrString(result, "left", value) == -1)
2270 goto failed;
2271 Py_DECREF(value);
2272 value = ast2obj_operator(o->v.BinOp.op);
2273 if (!value) goto failed;
2274 if (PyObject_SetAttrString(result, "op", value) == -1)
2275 goto failed;
2276 Py_DECREF(value);
2277 value = ast2obj_expr(o->v.BinOp.right);
2278 if (!value) goto failed;
2279 if (PyObject_SetAttrString(result, "right", value) == -1)
2280 goto failed;
2281 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002282 break;
2283 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002284 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2285 if (!result) goto failed;
2286 value = ast2obj_unaryop(o->v.UnaryOp.op);
2287 if (!value) goto failed;
2288 if (PyObject_SetAttrString(result, "op", value) == -1)
2289 goto failed;
2290 Py_DECREF(value);
2291 value = ast2obj_expr(o->v.UnaryOp.operand);
2292 if (!value) goto failed;
2293 if (PyObject_SetAttrString(result, "operand", value) == -1)
2294 goto failed;
2295 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002296 break;
2297 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002298 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2299 if (!result) goto failed;
2300 value = ast2obj_arguments(o->v.Lambda.args);
2301 if (!value) goto failed;
2302 if (PyObject_SetAttrString(result, "args", value) == -1)
2303 goto failed;
2304 Py_DECREF(value);
2305 value = ast2obj_expr(o->v.Lambda.body);
2306 if (!value) goto failed;
2307 if (PyObject_SetAttrString(result, "body", value) == -1)
2308 goto failed;
2309 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002310 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002311 case IfExp_kind:
2312 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2313 if (!result) goto failed;
2314 value = ast2obj_expr(o->v.IfExp.test);
2315 if (!value) goto failed;
2316 if (PyObject_SetAttrString(result, "test", value) == -1)
2317 goto failed;
2318 Py_DECREF(value);
2319 value = ast2obj_expr(o->v.IfExp.body);
2320 if (!value) goto failed;
2321 if (PyObject_SetAttrString(result, "body", value) == -1)
2322 goto failed;
2323 Py_DECREF(value);
2324 value = ast2obj_expr(o->v.IfExp.orelse);
2325 if (!value) goto failed;
2326 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2327 goto failed;
2328 Py_DECREF(value);
2329 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002330 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002331 result = PyType_GenericNew(Dict_type, NULL, NULL);
2332 if (!result) goto failed;
2333 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2334 if (!value) goto failed;
2335 if (PyObject_SetAttrString(result, "keys", value) == -1)
2336 goto failed;
2337 Py_DECREF(value);
2338 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2339 if (!value) goto failed;
2340 if (PyObject_SetAttrString(result, "values", value) == -1)
2341 goto failed;
2342 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002343 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002344 case Set_kind:
2345 result = PyType_GenericNew(Set_type, NULL, NULL);
2346 if (!result) goto failed;
2347 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "elts", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
2352 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002353 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_expr(o->v.ListComp.elt);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "elt", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_list(o->v.ListComp.generators,
2362 ast2obj_comprehension);
2363 if (!value) goto failed;
2364 if (PyObject_SetAttrString(result, "generators", value) == -1)
2365 goto failed;
2366 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002367 break;
2368 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002369 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2370 if (!result) goto failed;
2371 value = ast2obj_expr(o->v.GeneratorExp.elt);
2372 if (!value) goto failed;
2373 if (PyObject_SetAttrString(result, "elt", value) == -1)
2374 goto failed;
2375 Py_DECREF(value);
2376 value = ast2obj_list(o->v.GeneratorExp.generators,
2377 ast2obj_comprehension);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "generators", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002382 break;
2383 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002384 result = PyType_GenericNew(Yield_type, NULL, NULL);
2385 if (!result) goto failed;
2386 value = ast2obj_expr(o->v.Yield.value);
2387 if (!value) goto failed;
2388 if (PyObject_SetAttrString(result, "value", value) == -1)
2389 goto failed;
2390 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002391 break;
2392 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002393 result = PyType_GenericNew(Compare_type, NULL, NULL);
2394 if (!result) goto failed;
2395 value = ast2obj_expr(o->v.Compare.left);
2396 if (!value) goto failed;
2397 if (PyObject_SetAttrString(result, "left", value) == -1)
2398 goto failed;
2399 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002400 {
2401 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2402 value = PyList_New(n);
2403 if (!value) goto failed;
2404 for(i = 0; i < n; i++)
2405 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2406 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002407 if (!value) goto failed;
2408 if (PyObject_SetAttrString(result, "ops", value) == -1)
2409 goto failed;
2410 Py_DECREF(value);
2411 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2412 if (!value) goto failed;
2413 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2414 goto failed;
2415 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002416 break;
2417 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002418 result = PyType_GenericNew(Call_type, NULL, NULL);
2419 if (!result) goto failed;
2420 value = ast2obj_expr(o->v.Call.func);
2421 if (!value) goto failed;
2422 if (PyObject_SetAttrString(result, "func", value) == -1)
2423 goto failed;
2424 Py_DECREF(value);
2425 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2426 if (!value) goto failed;
2427 if (PyObject_SetAttrString(result, "args", value) == -1)
2428 goto failed;
2429 Py_DECREF(value);
2430 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2431 if (!value) goto failed;
2432 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2433 goto failed;
2434 Py_DECREF(value);
2435 value = ast2obj_expr(o->v.Call.starargs);
2436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 value = ast2obj_expr(o->v.Call.kwargs);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002445 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002446 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002447 result = PyType_GenericNew(Num_type, NULL, NULL);
2448 if (!result) goto failed;
2449 value = ast2obj_object(o->v.Num.n);
2450 if (!value) goto failed;
2451 if (PyObject_SetAttrString(result, "n", value) == -1)
2452 goto failed;
2453 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002454 break;
2455 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002456 result = PyType_GenericNew(Str_type, NULL, NULL);
2457 if (!result) goto failed;
2458 value = ast2obj_string(o->v.Str.s);
2459 if (!value) goto failed;
2460 if (PyObject_SetAttrString(result, "s", value) == -1)
2461 goto failed;
2462 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002463 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002464 case Bytes_kind:
2465 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2466 if (!result) goto failed;
2467 value = ast2obj_string(o->v.Bytes.s);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "s", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
2472 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002473 case Ellipsis_kind:
2474 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2475 if (!result) goto failed;
2476 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002478 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2479 if (!result) goto failed;
2480 value = ast2obj_expr(o->v.Attribute.value);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "value", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
2485 value = ast2obj_identifier(o->v.Attribute.attr);
2486 if (!value) goto failed;
2487 if (PyObject_SetAttrString(result, "attr", value) == -1)
2488 goto failed;
2489 Py_DECREF(value);
2490 value = ast2obj_expr_context(o->v.Attribute.ctx);
2491 if (!value) goto failed;
2492 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2493 goto failed;
2494 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002495 break;
2496 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002497 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2498 if (!result) goto failed;
2499 value = ast2obj_expr(o->v.Subscript.value);
2500 if (!value) goto failed;
2501 if (PyObject_SetAttrString(result, "value", value) == -1)
2502 goto failed;
2503 Py_DECREF(value);
2504 value = ast2obj_slice(o->v.Subscript.slice);
2505 if (!value) goto failed;
2506 if (PyObject_SetAttrString(result, "slice", value) == -1)
2507 goto failed;
2508 Py_DECREF(value);
2509 value = ast2obj_expr_context(o->v.Subscript.ctx);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002514 break;
2515 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002516 result = PyType_GenericNew(Name_type, NULL, NULL);
2517 if (!result) goto failed;
2518 value = ast2obj_identifier(o->v.Name.id);
2519 if (!value) goto failed;
2520 if (PyObject_SetAttrString(result, "id", value) == -1)
2521 goto failed;
2522 Py_DECREF(value);
2523 value = ast2obj_expr_context(o->v.Name.ctx);
2524 if (!value) goto failed;
2525 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2526 goto failed;
2527 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528 break;
2529 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002530 result = PyType_GenericNew(List_type, NULL, NULL);
2531 if (!result) goto failed;
2532 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2533 if (!value) goto failed;
2534 if (PyObject_SetAttrString(result, "elts", value) == -1)
2535 goto failed;
2536 Py_DECREF(value);
2537 value = ast2obj_expr_context(o->v.List.ctx);
2538 if (!value) goto failed;
2539 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2540 goto failed;
2541 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002542 break;
2543 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002544 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2545 if (!result) goto failed;
2546 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "elts", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
2551 value = ast2obj_expr_context(o->v.Tuple.ctx);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002556 break;
2557 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002558 value = ast2obj_int(o->lineno);
2559 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002560 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2561 goto failed;
2562 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002563 value = ast2obj_int(o->col_offset);
2564 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002565 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2566 goto failed;
2567 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002568 return result;
2569failed:
2570 Py_XDECREF(value);
2571 Py_XDECREF(result);
2572 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002573}
2574
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002575PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002576{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002577 switch(o) {
2578 case Load:
2579 Py_INCREF(Load_singleton);
2580 return Load_singleton;
2581 case Store:
2582 Py_INCREF(Store_singleton);
2583 return Store_singleton;
2584 case Del:
2585 Py_INCREF(Del_singleton);
2586 return Del_singleton;
2587 case AugLoad:
2588 Py_INCREF(AugLoad_singleton);
2589 return AugLoad_singleton;
2590 case AugStore:
2591 Py_INCREF(AugStore_singleton);
2592 return AugStore_singleton;
2593 case Param:
2594 Py_INCREF(Param_singleton);
2595 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002596 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002597 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002598}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002599PyObject*
2600ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002601{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002602 slice_ty o = (slice_ty)_o;
2603 PyObject *result = NULL, *value = NULL;
2604 if (!o) {
2605 Py_INCREF(Py_None);
2606 return Py_None;
2607 }
2608
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002609 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002610 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002611 result = PyType_GenericNew(Slice_type, NULL, NULL);
2612 if (!result) goto failed;
2613 value = ast2obj_expr(o->v.Slice.lower);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "lower", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
2618 value = ast2obj_expr(o->v.Slice.upper);
2619 if (!value) goto failed;
2620 if (PyObject_SetAttrString(result, "upper", value) == -1)
2621 goto failed;
2622 Py_DECREF(value);
2623 value = ast2obj_expr(o->v.Slice.step);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "step", value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002628 break;
2629 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002630 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2631 if (!result) goto failed;
2632 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2633 if (!value) goto failed;
2634 if (PyObject_SetAttrString(result, "dims", value) == -1)
2635 goto failed;
2636 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002637 break;
2638 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002639 result = PyType_GenericNew(Index_type, NULL, NULL);
2640 if (!result) goto failed;
2641 value = ast2obj_expr(o->v.Index.value);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "value", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002646 break;
2647 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648 return result;
2649failed:
2650 Py_XDECREF(value);
2651 Py_XDECREF(result);
2652 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002653}
2654
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002655PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002657 switch(o) {
2658 case And:
2659 Py_INCREF(And_singleton);
2660 return And_singleton;
2661 case Or:
2662 Py_INCREF(Or_singleton);
2663 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002664 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002665 return NULL; /* cannot happen */
2666}
2667PyObject* ast2obj_operator(operator_ty o)
2668{
2669 switch(o) {
2670 case Add:
2671 Py_INCREF(Add_singleton);
2672 return Add_singleton;
2673 case Sub:
2674 Py_INCREF(Sub_singleton);
2675 return Sub_singleton;
2676 case Mult:
2677 Py_INCREF(Mult_singleton);
2678 return Mult_singleton;
2679 case Div:
2680 Py_INCREF(Div_singleton);
2681 return Div_singleton;
2682 case Mod:
2683 Py_INCREF(Mod_singleton);
2684 return Mod_singleton;
2685 case Pow:
2686 Py_INCREF(Pow_singleton);
2687 return Pow_singleton;
2688 case LShift:
2689 Py_INCREF(LShift_singleton);
2690 return LShift_singleton;
2691 case RShift:
2692 Py_INCREF(RShift_singleton);
2693 return RShift_singleton;
2694 case BitOr:
2695 Py_INCREF(BitOr_singleton);
2696 return BitOr_singleton;
2697 case BitXor:
2698 Py_INCREF(BitXor_singleton);
2699 return BitXor_singleton;
2700 case BitAnd:
2701 Py_INCREF(BitAnd_singleton);
2702 return BitAnd_singleton;
2703 case FloorDiv:
2704 Py_INCREF(FloorDiv_singleton);
2705 return FloorDiv_singleton;
2706 }
2707 return NULL; /* cannot happen */
2708}
2709PyObject* ast2obj_unaryop(unaryop_ty o)
2710{
2711 switch(o) {
2712 case Invert:
2713 Py_INCREF(Invert_singleton);
2714 return Invert_singleton;
2715 case Not:
2716 Py_INCREF(Not_singleton);
2717 return Not_singleton;
2718 case UAdd:
2719 Py_INCREF(UAdd_singleton);
2720 return UAdd_singleton;
2721 case USub:
2722 Py_INCREF(USub_singleton);
2723 return USub_singleton;
2724 }
2725 return NULL; /* cannot happen */
2726}
2727PyObject* ast2obj_cmpop(cmpop_ty o)
2728{
2729 switch(o) {
2730 case Eq:
2731 Py_INCREF(Eq_singleton);
2732 return Eq_singleton;
2733 case NotEq:
2734 Py_INCREF(NotEq_singleton);
2735 return NotEq_singleton;
2736 case Lt:
2737 Py_INCREF(Lt_singleton);
2738 return Lt_singleton;
2739 case LtE:
2740 Py_INCREF(LtE_singleton);
2741 return LtE_singleton;
2742 case Gt:
2743 Py_INCREF(Gt_singleton);
2744 return Gt_singleton;
2745 case GtE:
2746 Py_INCREF(GtE_singleton);
2747 return GtE_singleton;
2748 case Is:
2749 Py_INCREF(Is_singleton);
2750 return Is_singleton;
2751 case IsNot:
2752 Py_INCREF(IsNot_singleton);
2753 return IsNot_singleton;
2754 case In:
2755 Py_INCREF(In_singleton);
2756 return In_singleton;
2757 case NotIn:
2758 Py_INCREF(NotIn_singleton);
2759 return NotIn_singleton;
2760 }
2761 return NULL; /* cannot happen */
2762}
2763PyObject*
2764ast2obj_comprehension(void* _o)
2765{
2766 comprehension_ty o = (comprehension_ty)_o;
2767 PyObject *result = NULL, *value = NULL;
2768 if (!o) {
2769 Py_INCREF(Py_None);
2770 return Py_None;
2771 }
2772
2773 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2774 if (!result) return NULL;
2775 value = ast2obj_expr(o->target);
2776 if (!value) goto failed;
2777 if (PyObject_SetAttrString(result, "target", value) == -1)
2778 goto failed;
2779 Py_DECREF(value);
2780 value = ast2obj_expr(o->iter);
2781 if (!value) goto failed;
2782 if (PyObject_SetAttrString(result, "iter", value) == -1)
2783 goto failed;
2784 Py_DECREF(value);
2785 value = ast2obj_list(o->ifs, ast2obj_expr);
2786 if (!value) goto failed;
2787 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2788 goto failed;
2789 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002790 return result;
2791failed:
2792 Py_XDECREF(value);
2793 Py_XDECREF(result);
2794 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002795}
2796
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002797PyObject*
2798ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002799{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002800 excepthandler_ty o = (excepthandler_ty)_o;
2801 PyObject *result = NULL, *value = NULL;
2802 if (!o) {
2803 Py_INCREF(Py_None);
2804 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002805 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002806
2807 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2808 if (!result) return NULL;
2809 value = ast2obj_expr(o->type);
2810 if (!value) goto failed;
2811 if (PyObject_SetAttrString(result, "type", value) == -1)
2812 goto failed;
2813 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002814 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002815 if (!value) goto failed;
2816 if (PyObject_SetAttrString(result, "name", value) == -1)
2817 goto failed;
2818 Py_DECREF(value);
2819 value = ast2obj_list(o->body, ast2obj_stmt);
2820 if (!value) goto failed;
2821 if (PyObject_SetAttrString(result, "body", value) == -1)
2822 goto failed;
2823 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002824 value = ast2obj_int(o->lineno);
2825 if (!value) goto failed;
2826 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
2829 value = ast2obj_int(o->col_offset);
2830 if (!value) goto failed;
2831 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2832 goto failed;
2833 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002834 return result;
2835failed:
2836 Py_XDECREF(value);
2837 Py_XDECREF(result);
2838 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002839}
2840
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002841PyObject*
2842ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002843{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002844 arguments_ty o = (arguments_ty)_o;
2845 PyObject *result = NULL, *value = NULL;
2846 if (!o) {
2847 Py_INCREF(Py_None);
2848 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002849 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002850
2851 result = PyType_GenericNew(arguments_type, NULL, NULL);
2852 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002853 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002854 if (!value) goto failed;
2855 if (PyObject_SetAttrString(result, "args", value) == -1)
2856 goto failed;
2857 Py_DECREF(value);
2858 value = ast2obj_identifier(o->vararg);
2859 if (!value) goto failed;
2860 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2861 goto failed;
2862 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002863 value = ast2obj_expr(o->varargannotation);
2864 if (!value) goto failed;
2865 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2866 goto failed;
2867 Py_DECREF(value);
2868 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002869 if (!value) goto failed;
2870 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2871 goto failed;
2872 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002873 value = ast2obj_identifier(o->kwarg);
2874 if (!value) goto failed;
2875 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2876 goto failed;
2877 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002878 value = ast2obj_expr(o->kwargannotation);
2879 if (!value) goto failed;
2880 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2881 goto failed;
2882 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002883 value = ast2obj_list(o->defaults, ast2obj_expr);
2884 if (!value) goto failed;
2885 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2886 goto failed;
2887 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002888 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2889 if (!value) goto failed;
2890 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2891 goto failed;
2892 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002893 return result;
2894failed:
2895 Py_XDECREF(value);
2896 Py_XDECREF(result);
2897 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002898}
2899
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002900PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002901ast2obj_arg(void* _o)
2902{
2903 arg_ty o = (arg_ty)_o;
2904 PyObject *result = NULL, *value = NULL;
2905 if (!o) {
2906 Py_INCREF(Py_None);
2907 return Py_None;
2908 }
2909
2910 switch (o->kind) {
2911 case SimpleArg_kind:
2912 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2913 if (!result) goto failed;
2914 value = ast2obj_identifier(o->v.SimpleArg.arg);
2915 if (!value) goto failed;
2916 if (PyObject_SetAttrString(result, "arg", value) == -1)
2917 goto failed;
2918 Py_DECREF(value);
2919 value = ast2obj_expr(o->v.SimpleArg.annotation);
2920 if (!value) goto failed;
2921 if (PyObject_SetAttrString(result, "annotation", value) == -1)
2922 goto failed;
2923 Py_DECREF(value);
2924 break;
2925 case NestedArgs_kind:
2926 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
2927 if (!result) goto failed;
2928 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
2929 if (!value) goto failed;
2930 if (PyObject_SetAttrString(result, "args", value) == -1)
2931 goto failed;
2932 Py_DECREF(value);
2933 break;
2934 }
2935 return result;
2936failed:
2937 Py_XDECREF(value);
2938 Py_XDECREF(result);
2939 return NULL;
2940}
2941
2942PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002943ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002944{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002945 keyword_ty o = (keyword_ty)_o;
2946 PyObject *result = NULL, *value = NULL;
2947 if (!o) {
2948 Py_INCREF(Py_None);
2949 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002950 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951
2952 result = PyType_GenericNew(keyword_type, NULL, NULL);
2953 if (!result) return NULL;
2954 value = ast2obj_identifier(o->arg);
2955 if (!value) goto failed;
2956 if (PyObject_SetAttrString(result, "arg", value) == -1)
2957 goto failed;
2958 Py_DECREF(value);
2959 value = ast2obj_expr(o->value);
2960 if (!value) goto failed;
2961 if (PyObject_SetAttrString(result, "value", value) == -1)
2962 goto failed;
2963 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002964 return result;
2965failed:
2966 Py_XDECREF(value);
2967 Py_XDECREF(result);
2968 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002969}
2970
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002971PyObject*
2972ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002973{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002974 alias_ty o = (alias_ty)_o;
2975 PyObject *result = NULL, *value = NULL;
2976 if (!o) {
2977 Py_INCREF(Py_None);
2978 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002979 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002980
2981 result = PyType_GenericNew(alias_type, NULL, NULL);
2982 if (!result) return NULL;
2983 value = ast2obj_identifier(o->name);
2984 if (!value) goto failed;
2985 if (PyObject_SetAttrString(result, "name", value) == -1)
2986 goto failed;
2987 Py_DECREF(value);
2988 value = ast2obj_identifier(o->asname);
2989 if (!value) goto failed;
2990 if (PyObject_SetAttrString(result, "asname", value) == -1)
2991 goto failed;
2992 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002993 return result;
2994failed:
2995 Py_XDECREF(value);
2996 Py_XDECREF(result);
2997 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002998}
2999
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003000
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003001PyMODINIT_FUNC
3002init_ast(void)
3003{
3004 PyObject *m, *d;
3005 if (!init_types()) return;
3006 m = Py_InitModule3("_ast", NULL, NULL);
3007 if (!m) return;
3008 d = PyModule_GetDict(m);
3009 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3010 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3011 return;
Neal Norwitz6baa4c42007-02-26 19:14:12 +00003012 if (PyModule_AddStringConstant(m, "__version__", "53956") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003013 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003014 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3015 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3016 return;
3017 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3018 < 0) return;
3019 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3020 0) return;
3021 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3022 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3023 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3024 < 0) return;
3025 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3026 return;
3027 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3028 return;
3029 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3030 return;
3031 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3032 return;
3033 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3034 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003035 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3036 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3037 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3038 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3040 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3041 0) return;
3042 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3043 0) return;
3044 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3045 return;
3046 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3047 return;
3048 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3049 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003050 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3051 return;
3052 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3053 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3054 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3055 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3056 return;
3057 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3058 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3059 return;
3060 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3061 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3062 return;
3063 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3066 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003067 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003068 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3069 return;
3070 if (PyDict_SetItemString(d, "GeneratorExp",
3071 (PyObject*)GeneratorExp_type) < 0) return;
3072 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3073 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3074 return;
3075 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003076 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003078 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003079 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3080 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003081 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3082 0) return;
3083 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3084 0) return;
3085 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3086 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3087 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3088 if (PyDict_SetItemString(d, "expr_context",
3089 (PyObject*)expr_context_type) < 0) return;
3090 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3092 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3093 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3094 return;
3095 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3096 return;
3097 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3098 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003099 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3100 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3103 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3104 return;
3105 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3106 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3107 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3108 return;
3109 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3110 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3111 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3112 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3114 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3115 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3116 return;
3117 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3118 return;
3119 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3120 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3121 return;
3122 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3123 return;
3124 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3125 return;
3126 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3129 return;
3130 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3131 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3132 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3133 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3134 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3135 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3136 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3137 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3138 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3139 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3140 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3141 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3142 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3143 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3144 if (PyDict_SetItemString(d, "comprehension",
3145 (PyObject*)comprehension_type) < 0) return;
3146 if (PyDict_SetItemString(d, "excepthandler",
3147 (PyObject*)excepthandler_type) < 0) return;
3148 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3149 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003150 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3151 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3152 0) return;
3153 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3154 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003155 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3156 return;
3157 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003158}
3159
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003161PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003162{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003163 init_types();
3164 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003165}
3166
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003167