blob: b5621827ebf8a977046262098078efa73e2093a8 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Thomas Woutersa44f3a32007-02-26 18:20:15 +00005 __version__ 53873.
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
446static PyObject* ast2obj_bool(bool b)
447{
448 return PyBool_FromLong(b);
449}
450
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000451static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452{
453 return PyInt_FromLong(b);
454}
455
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456static int init_types(void)
457{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000458 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
461 mod_type = make_type("mod", AST_type, NULL, 0);
462 if (!mod_type) return 0;
463 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000465 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000466 Interactive_type = make_type("Interactive", mod_type,
467 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Expression_type = make_type("Expression", mod_type, Expression_fields,
470 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000471 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 if (!Suite_type) return 0;
474 stmt_type = make_type("stmt", AST_type, NULL, 0);
475 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000476 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000478 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000496 With_type = make_type("With", stmt_type, With_fields, 3);
497 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
503 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000510 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000516 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000518 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000520 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Continue_type) return 0;
522 expr_type = make_type("expr", AST_type, NULL, 0);
523 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000524 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000533 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000537 Set_type = make_type("Set", expr_type, Set_fields, 1);
538 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 GeneratorExp_type = make_type("GeneratorExp", expr_type,
542 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000554 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
555 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000556 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
557 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Tuple_type) return 0;
568 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
569 if (!expr_context_type) return 0;
570 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000571 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000573 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000575 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000579 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000583 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000587 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000589 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000591 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000592 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000593 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!Param_singleton) return 0;
595 slice_type = make_type("slice", AST_type, NULL, 0);
596 if (!slice_type) return 0;
597 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000600 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000602 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!Index_type) return 0;
604 boolop_type = make_type("boolop", AST_type, NULL, 0);
605 if (!boolop_type) return 0;
606 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Or_singleton) return 0;
615 operator_type = make_type("operator", AST_type, NULL, 0);
616 if (!operator_type) return 0;
617 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000618 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000619 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000620 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000622 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000624 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000626 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000628 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000630 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000632 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000634 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000636 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000638 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000640 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000642 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000644 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000646 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000648 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000650 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!FloorDiv_singleton) return 0;
666 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
667 if (!unaryop_type) return 0;
668 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!USub_singleton) return 0;
685 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
686 if (!cmpop_type) return 0;
687 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000688 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000690 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000692 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000694 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000696 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000698 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000700 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000704 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000706 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000708 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000710 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000712 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000714 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000716 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000718 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000720 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000722 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000724 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000725 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000726 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!NotIn_singleton) return 0;
728 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000729 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000730 if (!comprehension_type) return 0;
731 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000732 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000733 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000734 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000736 arg_type = make_type("arg", AST_type, NULL, 0);
737 if (!arg_type) return 0;
738 if (!add_attributes(arg_type, NULL, 0)) return 0;
739 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
740 if (!SimpleArg_type) return 0;
741 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
742 1);
743 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000744 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
745 if (!keyword_type) return 0;
746 alias_type = make_type("alias", AST_type, alias_fields, 2);
747 if (!alias_type) return 0;
748 initialized = 1;
749 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000750}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000751
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000752mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000753Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000754{
755 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000756 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000757 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000758 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759 p->kind = Module_kind;
760 p->v.Module.body = body;
761 return p;
762}
763
764mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000765Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766{
767 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000768 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000769 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000770 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771 p->kind = Interactive_kind;
772 p->v.Interactive.body = body;
773 return p;
774}
775
776mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000777Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778{
779 mod_ty p;
780 if (!body) {
781 PyErr_SetString(PyExc_ValueError,
782 "field body is required for Expression");
783 return NULL;
784 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000785 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000786 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000788 p->kind = Expression_kind;
789 p->v.Expression.body = body;
790 return p;
791}
792
793mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000794Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000795{
796 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000797 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000798 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000799 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 p->kind = Suite_kind;
801 p->v.Suite.body = body;
802 return p;
803}
804
805stmt_ty
806FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000807 decorators, expr_ty returns, int lineno, int col_offset, PyArena
808 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000809{
810 stmt_ty p;
811 if (!name) {
812 PyErr_SetString(PyExc_ValueError,
813 "field name is required for FunctionDef");
814 return NULL;
815 }
816 if (!args) {
817 PyErr_SetString(PyExc_ValueError,
818 "field args is required for FunctionDef");
819 return NULL;
820 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000821 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000822 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000823 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000824 p->kind = FunctionDef_kind;
825 p->v.FunctionDef.name = name;
826 p->v.FunctionDef.args = args;
827 p->v.FunctionDef.body = body;
828 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000829 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000830 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000831 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 return p;
833}
834
835stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000836ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
837 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000838{
839 stmt_ty p;
840 if (!name) {
841 PyErr_SetString(PyExc_ValueError,
842 "field name is required for ClassDef");
843 return NULL;
844 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000845 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000846 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000848 p->kind = ClassDef_kind;
849 p->v.ClassDef.name = name;
850 p->v.ClassDef.bases = bases;
851 p->v.ClassDef.body = body;
852 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000853 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000854 return p;
855}
856
857stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000858Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859{
860 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000861 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000862 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000863 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864 p->kind = Return_kind;
865 p->v.Return.value = value;
866 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000867 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868 return p;
869}
870
871stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000872Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873{
874 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000875 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000876 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000878 p->kind = Delete_kind;
879 p->v.Delete.targets = targets;
880 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882 return p;
883}
884
885stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000886Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
887 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000888{
889 stmt_ty p;
890 if (!value) {
891 PyErr_SetString(PyExc_ValueError,
892 "field value is required for Assign");
893 return NULL;
894 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000895 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000896 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000897 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898 p->kind = Assign_kind;
899 p->v.Assign.targets = targets;
900 p->v.Assign.value = value;
901 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000902 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000903 return p;
904}
905
906stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000907AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
908 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000909{
910 stmt_ty p;
911 if (!target) {
912 PyErr_SetString(PyExc_ValueError,
913 "field target is required for AugAssign");
914 return NULL;
915 }
916 if (!op) {
917 PyErr_SetString(PyExc_ValueError,
918 "field op is required for AugAssign");
919 return NULL;
920 }
921 if (!value) {
922 PyErr_SetString(PyExc_ValueError,
923 "field value is required for AugAssign");
924 return NULL;
925 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000926 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000927 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000928 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000929 p->kind = AugAssign_kind;
930 p->v.AugAssign.target = target;
931 p->v.AugAssign.op = op;
932 p->v.AugAssign.value = value;
933 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000934 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000935 return p;
936}
937
938stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000939For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000940 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941{
942 stmt_ty p;
943 if (!target) {
944 PyErr_SetString(PyExc_ValueError,
945 "field target is required for For");
946 return NULL;
947 }
948 if (!iter) {
949 PyErr_SetString(PyExc_ValueError,
950 "field iter is required for For");
951 return NULL;
952 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000953 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000954 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000956 p->kind = For_kind;
957 p->v.For.target = target;
958 p->v.For.iter = iter;
959 p->v.For.body = body;
960 p->v.For.orelse = orelse;
961 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000962 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000963 return p;
964}
965
966stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000967While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
968 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000969{
970 stmt_ty p;
971 if (!test) {
972 PyErr_SetString(PyExc_ValueError,
973 "field test is required for While");
974 return NULL;
975 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000976 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000977 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000978 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 p->kind = While_kind;
980 p->v.While.test = test;
981 p->v.While.body = body;
982 p->v.While.orelse = orelse;
983 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000984 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985 return p;
986}
987
988stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000989If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
990 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991{
992 stmt_ty p;
993 if (!test) {
994 PyErr_SetString(PyExc_ValueError,
995 "field test is required for If");
996 return NULL;
997 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000998 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000999 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001000 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 p->kind = If_kind;
1002 p->v.If.test = test;
1003 p->v.If.body = body;
1004 p->v.If.orelse = orelse;
1005 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001006 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001007 return p;
1008}
1009
1010stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001011With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001012 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001013{
1014 stmt_ty p;
1015 if (!context_expr) {
1016 PyErr_SetString(PyExc_ValueError,
1017 "field context_expr is required for With");
1018 return NULL;
1019 }
1020 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001021 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001022 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001023 p->kind = With_kind;
1024 p->v.With.context_expr = context_expr;
1025 p->v.With.optional_vars = optional_vars;
1026 p->v.With.body = body;
1027 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001028 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001029 return p;
1030}
1031
1032stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001033Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1034 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001035{
1036 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001037 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001038 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001039 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001040 p->kind = Raise_kind;
1041 p->v.Raise.type = type;
1042 p->v.Raise.inst = inst;
1043 p->v.Raise.tback = tback;
1044 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001045 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001046 return p;
1047}
1048
1049stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001050TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001051 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001052{
1053 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001054 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001055 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001056 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001057 p->kind = TryExcept_kind;
1058 p->v.TryExcept.body = body;
1059 p->v.TryExcept.handlers = handlers;
1060 p->v.TryExcept.orelse = orelse;
1061 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001062 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063 return p;
1064}
1065
1066stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001067TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1068 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001069{
1070 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001071 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001072 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001074 p->kind = TryFinally_kind;
1075 p->v.TryFinally.body = body;
1076 p->v.TryFinally.finalbody = finalbody;
1077 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001078 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 return p;
1080}
1081
1082stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001083Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001084{
1085 stmt_ty p;
1086 if (!test) {
1087 PyErr_SetString(PyExc_ValueError,
1088 "field test is required for Assert");
1089 return NULL;
1090 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001091 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001092 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001093 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001094 p->kind = Assert_kind;
1095 p->v.Assert.test = test;
1096 p->v.Assert.msg = msg;
1097 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001098 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001099 return p;
1100}
1101
1102stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001103Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104{
1105 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001106 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001107 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001108 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001109 p->kind = Import_kind;
1110 p->v.Import.names = names;
1111 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001112 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113 return p;
1114}
1115
1116stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001117ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1118 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001119{
1120 stmt_ty p;
1121 if (!module) {
1122 PyErr_SetString(PyExc_ValueError,
1123 "field module is required for ImportFrom");
1124 return NULL;
1125 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001126 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001127 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 p->kind = ImportFrom_kind;
1130 p->v.ImportFrom.module = module;
1131 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001132 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001133 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001134 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 return p;
1136}
1137
1138stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001139Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001140{
1141 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001142 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001143 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001144 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 p->kind = Global_kind;
1146 p->v.Global.names = names;
1147 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001148 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149 return p;
1150}
1151
1152stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001153Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154{
1155 stmt_ty p;
1156 if (!value) {
1157 PyErr_SetString(PyExc_ValueError,
1158 "field value is required for Expr");
1159 return NULL;
1160 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001161 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001162 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001164 p->kind = Expr_kind;
1165 p->v.Expr.value = value;
1166 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001167 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168 return p;
1169}
1170
1171stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001172Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173{
1174 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001175 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001176 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001178 p->kind = Pass_kind;
1179 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001180 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001181 return p;
1182}
1183
1184stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001185Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001186{
1187 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001188 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001189 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 p->kind = Break_kind;
1192 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001193 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194 return p;
1195}
1196
1197stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001198Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199{
1200 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001201 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001202 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204 p->kind = Continue_kind;
1205 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001206 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 return p;
1208}
1209
1210expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001211BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1212 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001213{
1214 expr_ty p;
1215 if (!op) {
1216 PyErr_SetString(PyExc_ValueError,
1217 "field op is required for BoolOp");
1218 return NULL;
1219 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001220 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001221 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 p->kind = BoolOp_kind;
1224 p->v.BoolOp.op = op;
1225 p->v.BoolOp.values = values;
1226 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001227 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001228 return p;
1229}
1230
1231expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001232BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1233 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234{
1235 expr_ty p;
1236 if (!left) {
1237 PyErr_SetString(PyExc_ValueError,
1238 "field left is required for BinOp");
1239 return NULL;
1240 }
1241 if (!op) {
1242 PyErr_SetString(PyExc_ValueError,
1243 "field op is required for BinOp");
1244 return NULL;
1245 }
1246 if (!right) {
1247 PyErr_SetString(PyExc_ValueError,
1248 "field right is required for BinOp");
1249 return NULL;
1250 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001251 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001252 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001253 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001254 p->kind = BinOp_kind;
1255 p->v.BinOp.left = left;
1256 p->v.BinOp.op = op;
1257 p->v.BinOp.right = right;
1258 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001259 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001260 return p;
1261}
1262
1263expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001264UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1265 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001266{
1267 expr_ty p;
1268 if (!op) {
1269 PyErr_SetString(PyExc_ValueError,
1270 "field op is required for UnaryOp");
1271 return NULL;
1272 }
1273 if (!operand) {
1274 PyErr_SetString(PyExc_ValueError,
1275 "field operand is required for UnaryOp");
1276 return NULL;
1277 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001278 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001279 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001280 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001281 p->kind = UnaryOp_kind;
1282 p->v.UnaryOp.op = op;
1283 p->v.UnaryOp.operand = operand;
1284 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001285 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001286 return p;
1287}
1288
1289expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001290Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1291 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292{
1293 expr_ty p;
1294 if (!args) {
1295 PyErr_SetString(PyExc_ValueError,
1296 "field args is required for Lambda");
1297 return NULL;
1298 }
1299 if (!body) {
1300 PyErr_SetString(PyExc_ValueError,
1301 "field body is required for Lambda");
1302 return NULL;
1303 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001304 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001305 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001306 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001307 p->kind = Lambda_kind;
1308 p->v.Lambda.args = args;
1309 p->v.Lambda.body = body;
1310 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001311 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001312 return p;
1313}
1314
1315expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001316IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1317 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001318{
1319 expr_ty p;
1320 if (!test) {
1321 PyErr_SetString(PyExc_ValueError,
1322 "field test is required for IfExp");
1323 return NULL;
1324 }
1325 if (!body) {
1326 PyErr_SetString(PyExc_ValueError,
1327 "field body is required for IfExp");
1328 return NULL;
1329 }
1330 if (!orelse) {
1331 PyErr_SetString(PyExc_ValueError,
1332 "field orelse is required for IfExp");
1333 return NULL;
1334 }
1335 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001336 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001337 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001338 p->kind = IfExp_kind;
1339 p->v.IfExp.test = test;
1340 p->v.IfExp.body = body;
1341 p->v.IfExp.orelse = orelse;
1342 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001343 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001344 return p;
1345}
1346
1347expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001348Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1349 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001350{
1351 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001352 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001353 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001354 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001355 p->kind = Dict_kind;
1356 p->v.Dict.keys = keys;
1357 p->v.Dict.values = values;
1358 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001359 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001360 return p;
1361}
1362
1363expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001364Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1365{
1366 expr_ty p;
1367 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001368 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001369 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001370 p->kind = Set_kind;
1371 p->v.Set.elts = elts;
1372 p->lineno = lineno;
1373 p->col_offset = col_offset;
1374 return p;
1375}
1376
1377expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001378ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1379 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001380{
1381 expr_ty p;
1382 if (!elt) {
1383 PyErr_SetString(PyExc_ValueError,
1384 "field elt is required for ListComp");
1385 return NULL;
1386 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001387 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001388 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001389 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001390 p->kind = ListComp_kind;
1391 p->v.ListComp.elt = elt;
1392 p->v.ListComp.generators = generators;
1393 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001394 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001395 return p;
1396}
1397
1398expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001399GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1400 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001401{
1402 expr_ty p;
1403 if (!elt) {
1404 PyErr_SetString(PyExc_ValueError,
1405 "field elt is required for GeneratorExp");
1406 return NULL;
1407 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001408 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001409 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001410 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001411 p->kind = GeneratorExp_kind;
1412 p->v.GeneratorExp.elt = elt;
1413 p->v.GeneratorExp.generators = generators;
1414 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001416 return p;
1417}
1418
1419expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001420Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001421{
1422 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001423 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001424 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001425 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426 p->kind = Yield_kind;
1427 p->v.Yield.value = value;
1428 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001429 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001430 return p;
1431}
1432
1433expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001434Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1435 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001436{
1437 expr_ty p;
1438 if (!left) {
1439 PyErr_SetString(PyExc_ValueError,
1440 "field left is required for Compare");
1441 return NULL;
1442 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001443 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001444 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001445 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001446 p->kind = Compare_kind;
1447 p->v.Compare.left = left;
1448 p->v.Compare.ops = ops;
1449 p->v.Compare.comparators = comparators;
1450 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001451 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452 return p;
1453}
1454
1455expr_ty
1456Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001457 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001458{
1459 expr_ty p;
1460 if (!func) {
1461 PyErr_SetString(PyExc_ValueError,
1462 "field func is required for Call");
1463 return NULL;
1464 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001465 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001466 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001467 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001468 p->kind = Call_kind;
1469 p->v.Call.func = func;
1470 p->v.Call.args = args;
1471 p->v.Call.keywords = keywords;
1472 p->v.Call.starargs = starargs;
1473 p->v.Call.kwargs = kwargs;
1474 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001475 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001476 return p;
1477}
1478
1479expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001480Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001481{
1482 expr_ty p;
1483 if (!n) {
1484 PyErr_SetString(PyExc_ValueError,
1485 "field n is required for Num");
1486 return NULL;
1487 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001488 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001489 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001490 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491 p->kind = Num_kind;
1492 p->v.Num.n = n;
1493 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001494 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001495 return p;
1496}
1497
1498expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001499Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500{
1501 expr_ty p;
1502 if (!s) {
1503 PyErr_SetString(PyExc_ValueError,
1504 "field s is required for Str");
1505 return NULL;
1506 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001507 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001508 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001509 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 p->kind = Str_kind;
1511 p->v.Str.s = s;
1512 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001513 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 return p;
1515}
1516
1517expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001518Bytes(string s, int lineno, int col_offset, PyArena *arena)
1519{
1520 expr_ty p;
1521 if (!s) {
1522 PyErr_SetString(PyExc_ValueError,
1523 "field s is required for Bytes");
1524 return NULL;
1525 }
1526 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001527 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001528 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001529 p->kind = Bytes_kind;
1530 p->v.Bytes.s = s;
1531 p->lineno = lineno;
1532 p->col_offset = col_offset;
1533 return p;
1534}
1535
1536expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001537Ellipsis(int lineno, int col_offset, PyArena *arena)
1538{
1539 expr_ty p;
1540 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001541 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001542 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001543 p->kind = Ellipsis_kind;
1544 p->lineno = lineno;
1545 p->col_offset = col_offset;
1546 return p;
1547}
1548
1549expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001550Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1551 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001552{
1553 expr_ty p;
1554 if (!value) {
1555 PyErr_SetString(PyExc_ValueError,
1556 "field value is required for Attribute");
1557 return NULL;
1558 }
1559 if (!attr) {
1560 PyErr_SetString(PyExc_ValueError,
1561 "field attr is required for Attribute");
1562 return NULL;
1563 }
1564 if (!ctx) {
1565 PyErr_SetString(PyExc_ValueError,
1566 "field ctx is required for Attribute");
1567 return NULL;
1568 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001569 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001570 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001571 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572 p->kind = Attribute_kind;
1573 p->v.Attribute.value = value;
1574 p->v.Attribute.attr = attr;
1575 p->v.Attribute.ctx = ctx;
1576 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001577 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001578 return p;
1579}
1580
1581expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001582Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1583 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584{
1585 expr_ty p;
1586 if (!value) {
1587 PyErr_SetString(PyExc_ValueError,
1588 "field value is required for Subscript");
1589 return NULL;
1590 }
1591 if (!slice) {
1592 PyErr_SetString(PyExc_ValueError,
1593 "field slice is required for Subscript");
1594 return NULL;
1595 }
1596 if (!ctx) {
1597 PyErr_SetString(PyExc_ValueError,
1598 "field ctx is required for Subscript");
1599 return NULL;
1600 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001601 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001602 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001603 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001604 p->kind = Subscript_kind;
1605 p->v.Subscript.value = value;
1606 p->v.Subscript.slice = slice;
1607 p->v.Subscript.ctx = ctx;
1608 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001609 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001610 return p;
1611}
1612
1613expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001614Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1615 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001616{
1617 expr_ty p;
1618 if (!id) {
1619 PyErr_SetString(PyExc_ValueError,
1620 "field id is required for Name");
1621 return NULL;
1622 }
1623 if (!ctx) {
1624 PyErr_SetString(PyExc_ValueError,
1625 "field ctx is required for Name");
1626 return NULL;
1627 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001628 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001629 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001630 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001631 p->kind = Name_kind;
1632 p->v.Name.id = id;
1633 p->v.Name.ctx = ctx;
1634 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001635 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001636 return p;
1637}
1638
1639expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001640List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1641 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001642{
1643 expr_ty p;
1644 if (!ctx) {
1645 PyErr_SetString(PyExc_ValueError,
1646 "field ctx is required for List");
1647 return NULL;
1648 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001649 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001650 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001651 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 p->kind = List_kind;
1653 p->v.List.elts = elts;
1654 p->v.List.ctx = ctx;
1655 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001656 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001657 return p;
1658}
1659
1660expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001661Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1662 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001663{
1664 expr_ty p;
1665 if (!ctx) {
1666 PyErr_SetString(PyExc_ValueError,
1667 "field ctx is required for Tuple");
1668 return NULL;
1669 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001670 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001671 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001672 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001673 p->kind = Tuple_kind;
1674 p->v.Tuple.elts = elts;
1675 p->v.Tuple.ctx = ctx;
1676 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001677 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001678 return p;
1679}
1680
1681slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001682Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001683{
1684 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001685 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001686 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001687 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 p->kind = Slice_kind;
1689 p->v.Slice.lower = lower;
1690 p->v.Slice.upper = upper;
1691 p->v.Slice.step = step;
1692 return p;
1693}
1694
1695slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001696ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697{
1698 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001699 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001700 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001701 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702 p->kind = ExtSlice_kind;
1703 p->v.ExtSlice.dims = dims;
1704 return p;
1705}
1706
1707slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001708Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001709{
1710 slice_ty p;
1711 if (!value) {
1712 PyErr_SetString(PyExc_ValueError,
1713 "field value is required for Index");
1714 return NULL;
1715 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001716 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001717 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001718 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001719 p->kind = Index_kind;
1720 p->v.Index.value = value;
1721 return p;
1722}
1723
1724comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001725comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726{
1727 comprehension_ty p;
1728 if (!target) {
1729 PyErr_SetString(PyExc_ValueError,
1730 "field target is required for comprehension");
1731 return NULL;
1732 }
1733 if (!iter) {
1734 PyErr_SetString(PyExc_ValueError,
1735 "field iter is required for comprehension");
1736 return NULL;
1737 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001738 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001739 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001741 p->target = target;
1742 p->iter = iter;
1743 p->ifs = ifs;
1744 return p;
1745}
1746
1747excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001748excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001749 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750{
1751 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001752 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001753 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001754 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001755 p->type = type;
1756 p->name = name;
1757 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001758 p->lineno = lineno;
1759 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760 return p;
1761}
1762
1763arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001764arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1765 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1766 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767{
1768 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001769 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001770 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772 p->args = args;
1773 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001774 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001775 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001777 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001779 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 return p;
1781}
1782
Neal Norwitzc1505362006-12-28 06:47:50 +00001783arg_ty
1784SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1785{
1786 arg_ty p;
1787 if (!arg) {
1788 PyErr_SetString(PyExc_ValueError,
1789 "field arg is required for SimpleArg");
1790 return NULL;
1791 }
1792 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001793 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001794 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001795 p->kind = SimpleArg_kind;
1796 p->v.SimpleArg.arg = arg;
1797 p->v.SimpleArg.annotation = annotation;
1798 return p;
1799}
1800
1801arg_ty
1802NestedArgs(asdl_seq * args, PyArena *arena)
1803{
1804 arg_ty p;
1805 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001806 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001807 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001808 p->kind = NestedArgs_kind;
1809 p->v.NestedArgs.args = args;
1810 return p;
1811}
1812
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001814keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815{
1816 keyword_ty p;
1817 if (!arg) {
1818 PyErr_SetString(PyExc_ValueError,
1819 "field arg is required for keyword");
1820 return NULL;
1821 }
1822 if (!value) {
1823 PyErr_SetString(PyExc_ValueError,
1824 "field value is required for keyword");
1825 return NULL;
1826 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001827 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001828 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001830 p->arg = arg;
1831 p->value = value;
1832 return p;
1833}
1834
1835alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001836alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001837{
1838 alias_ty p;
1839 if (!name) {
1840 PyErr_SetString(PyExc_ValueError,
1841 "field name is required for alias");
1842 return NULL;
1843 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001844 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001845 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847 p->name = name;
1848 p->asname = asname;
1849 return p;
1850}
1851
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001852
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001853PyObject*
1854ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001855{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001856 mod_ty o = (mod_ty)_o;
1857 PyObject *result = NULL, *value = NULL;
1858 if (!o) {
1859 Py_INCREF(Py_None);
1860 return Py_None;
1861 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001862
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863 switch (o->kind) {
1864 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001865 result = PyType_GenericNew(Module_type, NULL, NULL);
1866 if (!result) goto failed;
1867 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1868 if (!value) goto failed;
1869 if (PyObject_SetAttrString(result, "body", value) == -1)
1870 goto failed;
1871 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001872 break;
1873 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001874 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1875 if (!result) goto failed;
1876 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1877 if (!value) goto failed;
1878 if (PyObject_SetAttrString(result, "body", value) == -1)
1879 goto failed;
1880 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881 break;
1882 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001883 result = PyType_GenericNew(Expression_type, NULL, NULL);
1884 if (!result) goto failed;
1885 value = ast2obj_expr(o->v.Expression.body);
1886 if (!value) goto failed;
1887 if (PyObject_SetAttrString(result, "body", value) == -1)
1888 goto failed;
1889 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001890 break;
1891 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001892 result = PyType_GenericNew(Suite_type, NULL, NULL);
1893 if (!result) goto failed;
1894 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1895 if (!value) goto failed;
1896 if (PyObject_SetAttrString(result, "body", value) == -1)
1897 goto failed;
1898 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899 break;
1900 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001901 return result;
1902failed:
1903 Py_XDECREF(value);
1904 Py_XDECREF(result);
1905 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906}
1907
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001908PyObject*
1909ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001910{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001911 stmt_ty o = (stmt_ty)_o;
1912 PyObject *result = NULL, *value = NULL;
1913 if (!o) {
1914 Py_INCREF(Py_None);
1915 return Py_None;
1916 }
1917
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001918 switch (o->kind) {
1919 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001920 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1921 if (!result) goto failed;
1922 value = ast2obj_identifier(o->v.FunctionDef.name);
1923 if (!value) goto failed;
1924 if (PyObject_SetAttrString(result, "name", value) == -1)
1925 goto failed;
1926 Py_DECREF(value);
1927 value = ast2obj_arguments(o->v.FunctionDef.args);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "args", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
1932 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1933 if (!value) goto failed;
1934 if (PyObject_SetAttrString(result, "body", value) == -1)
1935 goto failed;
1936 Py_DECREF(value);
1937 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1938 if (!value) goto failed;
1939 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1940 goto failed;
1941 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00001942 value = ast2obj_expr(o->v.FunctionDef.returns);
1943 if (!value) goto failed;
1944 if (PyObject_SetAttrString(result, "returns", value) == -1)
1945 goto failed;
1946 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947 break;
1948 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001949 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1950 if (!result) goto failed;
1951 value = ast2obj_identifier(o->v.ClassDef.name);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "name", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
1956 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1957 if (!value) goto failed;
1958 if (PyObject_SetAttrString(result, "bases", value) == -1)
1959 goto failed;
1960 Py_DECREF(value);
1961 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1962 if (!value) goto failed;
1963 if (PyObject_SetAttrString(result, "body", value) == -1)
1964 goto failed;
1965 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 break;
1967 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Return_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_expr(o->v.Return.value);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "value", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Delete_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "targets", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(Assign_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "targets", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_expr(o->v.Assign.value);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "value", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001998 break;
1999 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002000 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2001 if (!result) goto failed;
2002 value = ast2obj_expr(o->v.AugAssign.target);
2003 if (!value) goto failed;
2004 if (PyObject_SetAttrString(result, "target", value) == -1)
2005 goto failed;
2006 Py_DECREF(value);
2007 value = ast2obj_operator(o->v.AugAssign.op);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "op", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
2012 value = ast2obj_expr(o->v.AugAssign.value);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "value", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002017 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002018 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002019 result = PyType_GenericNew(For_type, NULL, NULL);
2020 if (!result) goto failed;
2021 value = ast2obj_expr(o->v.For.target);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "target", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
2026 value = ast2obj_expr(o->v.For.iter);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "iter", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
2031 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "body", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
2036 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041 break;
2042 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002043 result = PyType_GenericNew(While_type, NULL, NULL);
2044 if (!result) goto failed;
2045 value = ast2obj_expr(o->v.While.test);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "test", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
2050 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "body", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
2055 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002060 break;
2061 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002062 result = PyType_GenericNew(If_type, NULL, NULL);
2063 if (!result) goto failed;
2064 value = ast2obj_expr(o->v.If.test);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "test", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
2069 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2070 if (!value) goto failed;
2071 if (PyObject_SetAttrString(result, "body", value) == -1)
2072 goto failed;
2073 Py_DECREF(value);
2074 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2075 if (!value) goto failed;
2076 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2077 goto failed;
2078 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002079 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002080 case With_kind:
2081 result = PyType_GenericNew(With_type, NULL, NULL);
2082 if (!result) goto failed;
2083 value = ast2obj_expr(o->v.With.context_expr);
2084 if (!value) goto failed;
2085 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2086 goto failed;
2087 Py_DECREF(value);
2088 value = ast2obj_expr(o->v.With.optional_vars);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2091 -1)
2092 goto failed;
2093 Py_DECREF(value);
2094 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2095 if (!value) goto failed;
2096 if (PyObject_SetAttrString(result, "body", value) == -1)
2097 goto failed;
2098 Py_DECREF(value);
2099 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002100 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002101 result = PyType_GenericNew(Raise_type, NULL, NULL);
2102 if (!result) goto failed;
2103 value = ast2obj_expr(o->v.Raise.type);
2104 if (!value) goto failed;
2105 if (PyObject_SetAttrString(result, "type", value) == -1)
2106 goto failed;
2107 Py_DECREF(value);
2108 value = ast2obj_expr(o->v.Raise.inst);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "inst", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_expr(o->v.Raise.tback);
2114 if (!value) goto failed;
2115 if (PyObject_SetAttrString(result, "tback", value) == -1)
2116 goto failed;
2117 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002118 break;
2119 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002120 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2121 if (!result) goto failed;
2122 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2123 if (!value) goto failed;
2124 if (PyObject_SetAttrString(result, "body", value) == -1)
2125 goto failed;
2126 Py_DECREF(value);
2127 value = ast2obj_list(o->v.TryExcept.handlers,
2128 ast2obj_excepthandler);
2129 if (!value) goto failed;
2130 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2131 goto failed;
2132 Py_DECREF(value);
2133 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002138 break;
2139 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002140 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2141 if (!result) goto failed;
2142 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2143 if (!value) goto failed;
2144 if (PyObject_SetAttrString(result, "body", value) == -1)
2145 goto failed;
2146 Py_DECREF(value);
2147 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002152 break;
2153 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002154 result = PyType_GenericNew(Assert_type, NULL, NULL);
2155 if (!result) goto failed;
2156 value = ast2obj_expr(o->v.Assert.test);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "test", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
2161 value = ast2obj_expr(o->v.Assert.msg);
2162 if (!value) goto failed;
2163 if (PyObject_SetAttrString(result, "msg", value) == -1)
2164 goto failed;
2165 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002166 break;
2167 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002168 result = PyType_GenericNew(Import_type, NULL, NULL);
2169 if (!result) goto failed;
2170 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "names", value) == -1)
2173 goto failed;
2174 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002175 break;
2176 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002177 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2178 if (!result) goto failed;
2179 value = ast2obj_identifier(o->v.ImportFrom.module);
2180 if (!value) goto failed;
2181 if (PyObject_SetAttrString(result, "module", value) == -1)
2182 goto failed;
2183 Py_DECREF(value);
2184 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "names", value) == -1)
2187 goto failed;
2188 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002189 value = ast2obj_int(o->v.ImportFrom.level);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "level", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002194 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002195 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002196 result = PyType_GenericNew(Global_type, NULL, NULL);
2197 if (!result) goto failed;
2198 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2199 if (!value) goto failed;
2200 if (PyObject_SetAttrString(result, "names", value) == -1)
2201 goto failed;
2202 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002203 break;
2204 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002205 result = PyType_GenericNew(Expr_type, NULL, NULL);
2206 if (!result) goto failed;
2207 value = ast2obj_expr(o->v.Expr.value);
2208 if (!value) goto failed;
2209 if (PyObject_SetAttrString(result, "value", value) == -1)
2210 goto failed;
2211 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002212 break;
2213 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002214 result = PyType_GenericNew(Pass_type, NULL, NULL);
2215 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002216 break;
2217 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002218 result = PyType_GenericNew(Break_type, NULL, NULL);
2219 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220 break;
2221 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002222 result = PyType_GenericNew(Continue_type, NULL, NULL);
2223 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002224 break;
2225 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002226 value = ast2obj_int(o->lineno);
2227 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002228 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2229 goto failed;
2230 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002231 value = ast2obj_int(o->col_offset);
2232 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002233 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2234 goto failed;
2235 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002236 return result;
2237failed:
2238 Py_XDECREF(value);
2239 Py_XDECREF(result);
2240 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241}
2242
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002243PyObject*
2244ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002245{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002246 expr_ty o = (expr_ty)_o;
2247 PyObject *result = NULL, *value = NULL;
2248 if (!o) {
2249 Py_INCREF(Py_None);
2250 return Py_None;
2251 }
2252
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253 switch (o->kind) {
2254 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002255 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2256 if (!result) goto failed;
2257 value = ast2obj_boolop(o->v.BoolOp.op);
2258 if (!value) goto failed;
2259 if (PyObject_SetAttrString(result, "op", value) == -1)
2260 goto failed;
2261 Py_DECREF(value);
2262 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2263 if (!value) goto failed;
2264 if (PyObject_SetAttrString(result, "values", value) == -1)
2265 goto failed;
2266 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002267 break;
2268 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002269 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2270 if (!result) goto failed;
2271 value = ast2obj_expr(o->v.BinOp.left);
2272 if (!value) goto failed;
2273 if (PyObject_SetAttrString(result, "left", value) == -1)
2274 goto failed;
2275 Py_DECREF(value);
2276 value = ast2obj_operator(o->v.BinOp.op);
2277 if (!value) goto failed;
2278 if (PyObject_SetAttrString(result, "op", value) == -1)
2279 goto failed;
2280 Py_DECREF(value);
2281 value = ast2obj_expr(o->v.BinOp.right);
2282 if (!value) goto failed;
2283 if (PyObject_SetAttrString(result, "right", value) == -1)
2284 goto failed;
2285 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002286 break;
2287 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002288 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2289 if (!result) goto failed;
2290 value = ast2obj_unaryop(o->v.UnaryOp.op);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "op", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
2295 value = ast2obj_expr(o->v.UnaryOp.operand);
2296 if (!value) goto failed;
2297 if (PyObject_SetAttrString(result, "operand", value) == -1)
2298 goto failed;
2299 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002300 break;
2301 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002302 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2303 if (!result) goto failed;
2304 value = ast2obj_arguments(o->v.Lambda.args);
2305 if (!value) goto failed;
2306 if (PyObject_SetAttrString(result, "args", value) == -1)
2307 goto failed;
2308 Py_DECREF(value);
2309 value = ast2obj_expr(o->v.Lambda.body);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "body", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002314 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002315 case IfExp_kind:
2316 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2317 if (!result) goto failed;
2318 value = ast2obj_expr(o->v.IfExp.test);
2319 if (!value) goto failed;
2320 if (PyObject_SetAttrString(result, "test", value) == -1)
2321 goto failed;
2322 Py_DECREF(value);
2323 value = ast2obj_expr(o->v.IfExp.body);
2324 if (!value) goto failed;
2325 if (PyObject_SetAttrString(result, "body", value) == -1)
2326 goto failed;
2327 Py_DECREF(value);
2328 value = ast2obj_expr(o->v.IfExp.orelse);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
2333 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002334 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002335 result = PyType_GenericNew(Dict_type, NULL, NULL);
2336 if (!result) goto failed;
2337 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2338 if (!value) goto failed;
2339 if (PyObject_SetAttrString(result, "keys", value) == -1)
2340 goto failed;
2341 Py_DECREF(value);
2342 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "values", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002347 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002348 case Set_kind:
2349 result = PyType_GenericNew(Set_type, NULL, NULL);
2350 if (!result) goto failed;
2351 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2352 if (!value) goto failed;
2353 if (PyObject_SetAttrString(result, "elts", value) == -1)
2354 goto failed;
2355 Py_DECREF(value);
2356 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002357 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2359 if (!result) goto failed;
2360 value = ast2obj_expr(o->v.ListComp.elt);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "elt", value) == -1)
2363 goto failed;
2364 Py_DECREF(value);
2365 value = ast2obj_list(o->v.ListComp.generators,
2366 ast2obj_comprehension);
2367 if (!value) goto failed;
2368 if (PyObject_SetAttrString(result, "generators", value) == -1)
2369 goto failed;
2370 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002371 break;
2372 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002373 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2374 if (!result) goto failed;
2375 value = ast2obj_expr(o->v.GeneratorExp.elt);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "elt", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_list(o->v.GeneratorExp.generators,
2381 ast2obj_comprehension);
2382 if (!value) goto failed;
2383 if (PyObject_SetAttrString(result, "generators", value) == -1)
2384 goto failed;
2385 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002386 break;
2387 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002388 result = PyType_GenericNew(Yield_type, NULL, NULL);
2389 if (!result) goto failed;
2390 value = ast2obj_expr(o->v.Yield.value);
2391 if (!value) goto failed;
2392 if (PyObject_SetAttrString(result, "value", value) == -1)
2393 goto failed;
2394 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002395 break;
2396 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002397 result = PyType_GenericNew(Compare_type, NULL, NULL);
2398 if (!result) goto failed;
2399 value = ast2obj_expr(o->v.Compare.left);
2400 if (!value) goto failed;
2401 if (PyObject_SetAttrString(result, "left", value) == -1)
2402 goto failed;
2403 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002404 {
2405 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2406 value = PyList_New(n);
2407 if (!value) goto failed;
2408 for(i = 0; i < n; i++)
2409 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2410 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "ops", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
2415 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2416 if (!value) goto failed;
2417 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2418 goto failed;
2419 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002420 break;
2421 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002422 result = PyType_GenericNew(Call_type, NULL, NULL);
2423 if (!result) goto failed;
2424 value = ast2obj_expr(o->v.Call.func);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "func", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
2429 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2430 if (!value) goto failed;
2431 if (PyObject_SetAttrString(result, "args", value) == -1)
2432 goto failed;
2433 Py_DECREF(value);
2434 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2435 if (!value) goto failed;
2436 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2437 goto failed;
2438 Py_DECREF(value);
2439 value = ast2obj_expr(o->v.Call.starargs);
2440 if (!value) goto failed;
2441 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2442 goto failed;
2443 Py_DECREF(value);
2444 value = ast2obj_expr(o->v.Call.kwargs);
2445 if (!value) goto failed;
2446 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2447 goto failed;
2448 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002449 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002450 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002451 result = PyType_GenericNew(Num_type, NULL, NULL);
2452 if (!result) goto failed;
2453 value = ast2obj_object(o->v.Num.n);
2454 if (!value) goto failed;
2455 if (PyObject_SetAttrString(result, "n", value) == -1)
2456 goto failed;
2457 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002458 break;
2459 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002460 result = PyType_GenericNew(Str_type, NULL, NULL);
2461 if (!result) goto failed;
2462 value = ast2obj_string(o->v.Str.s);
2463 if (!value) goto failed;
2464 if (PyObject_SetAttrString(result, "s", value) == -1)
2465 goto failed;
2466 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002467 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002468 case Bytes_kind:
2469 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2470 if (!result) goto failed;
2471 value = ast2obj_string(o->v.Bytes.s);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "s", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
2476 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002477 case Ellipsis_kind:
2478 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2479 if (!result) goto failed;
2480 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002481 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002482 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2483 if (!result) goto failed;
2484 value = ast2obj_expr(o->v.Attribute.value);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "value", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
2489 value = ast2obj_identifier(o->v.Attribute.attr);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "attr", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2494 value = ast2obj_expr_context(o->v.Attribute.ctx);
2495 if (!value) goto failed;
2496 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2497 goto failed;
2498 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002499 break;
2500 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002501 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2502 if (!result) goto failed;
2503 value = ast2obj_expr(o->v.Subscript.value);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "value", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
2508 value = ast2obj_slice(o->v.Subscript.slice);
2509 if (!value) goto failed;
2510 if (PyObject_SetAttrString(result, "slice", value) == -1)
2511 goto failed;
2512 Py_DECREF(value);
2513 value = ast2obj_expr_context(o->v.Subscript.ctx);
2514 if (!value) goto failed;
2515 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2516 goto failed;
2517 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002518 break;
2519 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002520 result = PyType_GenericNew(Name_type, NULL, NULL);
2521 if (!result) goto failed;
2522 value = ast2obj_identifier(o->v.Name.id);
2523 if (!value) goto failed;
2524 if (PyObject_SetAttrString(result, "id", value) == -1)
2525 goto failed;
2526 Py_DECREF(value);
2527 value = ast2obj_expr_context(o->v.Name.ctx);
2528 if (!value) goto failed;
2529 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2530 goto failed;
2531 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002532 break;
2533 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002534 result = PyType_GenericNew(List_type, NULL, NULL);
2535 if (!result) goto failed;
2536 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "elts", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 value = ast2obj_expr_context(o->v.List.ctx);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002546 break;
2547 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002548 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2549 if (!result) goto failed;
2550 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "elts", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
2555 value = ast2obj_expr_context(o->v.Tuple.ctx);
2556 if (!value) goto failed;
2557 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2558 goto failed;
2559 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002560 break;
2561 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002562 value = ast2obj_int(o->lineno);
2563 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002564 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2565 goto failed;
2566 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002567 value = ast2obj_int(o->col_offset);
2568 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002569 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2570 goto failed;
2571 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002572 return result;
2573failed:
2574 Py_XDECREF(value);
2575 Py_XDECREF(result);
2576 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002577}
2578
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002579PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002580{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002581 switch(o) {
2582 case Load:
2583 Py_INCREF(Load_singleton);
2584 return Load_singleton;
2585 case Store:
2586 Py_INCREF(Store_singleton);
2587 return Store_singleton;
2588 case Del:
2589 Py_INCREF(Del_singleton);
2590 return Del_singleton;
2591 case AugLoad:
2592 Py_INCREF(AugLoad_singleton);
2593 return AugLoad_singleton;
2594 case AugStore:
2595 Py_INCREF(AugStore_singleton);
2596 return AugStore_singleton;
2597 case Param:
2598 Py_INCREF(Param_singleton);
2599 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002600 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002601 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002602}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002603PyObject*
2604ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002605{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002606 slice_ty o = (slice_ty)_o;
2607 PyObject *result = NULL, *value = NULL;
2608 if (!o) {
2609 Py_INCREF(Py_None);
2610 return Py_None;
2611 }
2612
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002613 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002614 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002615 result = PyType_GenericNew(Slice_type, NULL, NULL);
2616 if (!result) goto failed;
2617 value = ast2obj_expr(o->v.Slice.lower);
2618 if (!value) goto failed;
2619 if (PyObject_SetAttrString(result, "lower", value) == -1)
2620 goto failed;
2621 Py_DECREF(value);
2622 value = ast2obj_expr(o->v.Slice.upper);
2623 if (!value) goto failed;
2624 if (PyObject_SetAttrString(result, "upper", value) == -1)
2625 goto failed;
2626 Py_DECREF(value);
2627 value = ast2obj_expr(o->v.Slice.step);
2628 if (!value) goto failed;
2629 if (PyObject_SetAttrString(result, "step", value) == -1)
2630 goto failed;
2631 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632 break;
2633 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002634 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2635 if (!result) goto failed;
2636 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2637 if (!value) goto failed;
2638 if (PyObject_SetAttrString(result, "dims", value) == -1)
2639 goto failed;
2640 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002641 break;
2642 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002643 result = PyType_GenericNew(Index_type, NULL, NULL);
2644 if (!result) goto failed;
2645 value = ast2obj_expr(o->v.Index.value);
2646 if (!value) goto failed;
2647 if (PyObject_SetAttrString(result, "value", value) == -1)
2648 goto failed;
2649 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002650 break;
2651 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002652 return result;
2653failed:
2654 Py_XDECREF(value);
2655 Py_XDECREF(result);
2656 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002657}
2658
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002659PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002660{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002661 switch(o) {
2662 case And:
2663 Py_INCREF(And_singleton);
2664 return And_singleton;
2665 case Or:
2666 Py_INCREF(Or_singleton);
2667 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002668 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002669 return NULL; /* cannot happen */
2670}
2671PyObject* ast2obj_operator(operator_ty o)
2672{
2673 switch(o) {
2674 case Add:
2675 Py_INCREF(Add_singleton);
2676 return Add_singleton;
2677 case Sub:
2678 Py_INCREF(Sub_singleton);
2679 return Sub_singleton;
2680 case Mult:
2681 Py_INCREF(Mult_singleton);
2682 return Mult_singleton;
2683 case Div:
2684 Py_INCREF(Div_singleton);
2685 return Div_singleton;
2686 case Mod:
2687 Py_INCREF(Mod_singleton);
2688 return Mod_singleton;
2689 case Pow:
2690 Py_INCREF(Pow_singleton);
2691 return Pow_singleton;
2692 case LShift:
2693 Py_INCREF(LShift_singleton);
2694 return LShift_singleton;
2695 case RShift:
2696 Py_INCREF(RShift_singleton);
2697 return RShift_singleton;
2698 case BitOr:
2699 Py_INCREF(BitOr_singleton);
2700 return BitOr_singleton;
2701 case BitXor:
2702 Py_INCREF(BitXor_singleton);
2703 return BitXor_singleton;
2704 case BitAnd:
2705 Py_INCREF(BitAnd_singleton);
2706 return BitAnd_singleton;
2707 case FloorDiv:
2708 Py_INCREF(FloorDiv_singleton);
2709 return FloorDiv_singleton;
2710 }
2711 return NULL; /* cannot happen */
2712}
2713PyObject* ast2obj_unaryop(unaryop_ty o)
2714{
2715 switch(o) {
2716 case Invert:
2717 Py_INCREF(Invert_singleton);
2718 return Invert_singleton;
2719 case Not:
2720 Py_INCREF(Not_singleton);
2721 return Not_singleton;
2722 case UAdd:
2723 Py_INCREF(UAdd_singleton);
2724 return UAdd_singleton;
2725 case USub:
2726 Py_INCREF(USub_singleton);
2727 return USub_singleton;
2728 }
2729 return NULL; /* cannot happen */
2730}
2731PyObject* ast2obj_cmpop(cmpop_ty o)
2732{
2733 switch(o) {
2734 case Eq:
2735 Py_INCREF(Eq_singleton);
2736 return Eq_singleton;
2737 case NotEq:
2738 Py_INCREF(NotEq_singleton);
2739 return NotEq_singleton;
2740 case Lt:
2741 Py_INCREF(Lt_singleton);
2742 return Lt_singleton;
2743 case LtE:
2744 Py_INCREF(LtE_singleton);
2745 return LtE_singleton;
2746 case Gt:
2747 Py_INCREF(Gt_singleton);
2748 return Gt_singleton;
2749 case GtE:
2750 Py_INCREF(GtE_singleton);
2751 return GtE_singleton;
2752 case Is:
2753 Py_INCREF(Is_singleton);
2754 return Is_singleton;
2755 case IsNot:
2756 Py_INCREF(IsNot_singleton);
2757 return IsNot_singleton;
2758 case In:
2759 Py_INCREF(In_singleton);
2760 return In_singleton;
2761 case NotIn:
2762 Py_INCREF(NotIn_singleton);
2763 return NotIn_singleton;
2764 }
2765 return NULL; /* cannot happen */
2766}
2767PyObject*
2768ast2obj_comprehension(void* _o)
2769{
2770 comprehension_ty o = (comprehension_ty)_o;
2771 PyObject *result = NULL, *value = NULL;
2772 if (!o) {
2773 Py_INCREF(Py_None);
2774 return Py_None;
2775 }
2776
2777 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2778 if (!result) return NULL;
2779 value = ast2obj_expr(o->target);
2780 if (!value) goto failed;
2781 if (PyObject_SetAttrString(result, "target", value) == -1)
2782 goto failed;
2783 Py_DECREF(value);
2784 value = ast2obj_expr(o->iter);
2785 if (!value) goto failed;
2786 if (PyObject_SetAttrString(result, "iter", value) == -1)
2787 goto failed;
2788 Py_DECREF(value);
2789 value = ast2obj_list(o->ifs, ast2obj_expr);
2790 if (!value) goto failed;
2791 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2792 goto failed;
2793 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002794 return result;
2795failed:
2796 Py_XDECREF(value);
2797 Py_XDECREF(result);
2798 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002799}
2800
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002801PyObject*
2802ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002803{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002804 excepthandler_ty o = (excepthandler_ty)_o;
2805 PyObject *result = NULL, *value = NULL;
2806 if (!o) {
2807 Py_INCREF(Py_None);
2808 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002809 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002810
2811 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2812 if (!result) return NULL;
2813 value = ast2obj_expr(o->type);
2814 if (!value) goto failed;
2815 if (PyObject_SetAttrString(result, "type", value) == -1)
2816 goto failed;
2817 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002818 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002819 if (!value) goto failed;
2820 if (PyObject_SetAttrString(result, "name", value) == -1)
2821 goto failed;
2822 Py_DECREF(value);
2823 value = ast2obj_list(o->body, ast2obj_stmt);
2824 if (!value) goto failed;
2825 if (PyObject_SetAttrString(result, "body", value) == -1)
2826 goto failed;
2827 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002828 value = ast2obj_int(o->lineno);
2829 if (!value) goto failed;
2830 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2831 goto failed;
2832 Py_DECREF(value);
2833 value = ast2obj_int(o->col_offset);
2834 if (!value) goto failed;
2835 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2836 goto failed;
2837 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002838 return result;
2839failed:
2840 Py_XDECREF(value);
2841 Py_XDECREF(result);
2842 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002843}
2844
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002845PyObject*
2846ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002847{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002848 arguments_ty o = (arguments_ty)_o;
2849 PyObject *result = NULL, *value = NULL;
2850 if (!o) {
2851 Py_INCREF(Py_None);
2852 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002853 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002854
2855 result = PyType_GenericNew(arguments_type, NULL, NULL);
2856 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002857 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002858 if (!value) goto failed;
2859 if (PyObject_SetAttrString(result, "args", value) == -1)
2860 goto failed;
2861 Py_DECREF(value);
2862 value = ast2obj_identifier(o->vararg);
2863 if (!value) goto failed;
2864 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2865 goto failed;
2866 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002867 value = ast2obj_expr(o->varargannotation);
2868 if (!value) goto failed;
2869 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2870 goto failed;
2871 Py_DECREF(value);
2872 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002873 if (!value) goto failed;
2874 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2875 goto failed;
2876 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002877 value = ast2obj_identifier(o->kwarg);
2878 if (!value) goto failed;
2879 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2880 goto failed;
2881 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002882 value = ast2obj_expr(o->kwargannotation);
2883 if (!value) goto failed;
2884 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2885 goto failed;
2886 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002887 value = ast2obj_list(o->defaults, ast2obj_expr);
2888 if (!value) goto failed;
2889 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2890 goto failed;
2891 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002892 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2893 if (!value) goto failed;
2894 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2895 goto failed;
2896 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002897 return result;
2898failed:
2899 Py_XDECREF(value);
2900 Py_XDECREF(result);
2901 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002902}
2903
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002904PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002905ast2obj_arg(void* _o)
2906{
2907 arg_ty o = (arg_ty)_o;
2908 PyObject *result = NULL, *value = NULL;
2909 if (!o) {
2910 Py_INCREF(Py_None);
2911 return Py_None;
2912 }
2913
2914 switch (o->kind) {
2915 case SimpleArg_kind:
2916 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2917 if (!result) goto failed;
2918 value = ast2obj_identifier(o->v.SimpleArg.arg);
2919 if (!value) goto failed;
2920 if (PyObject_SetAttrString(result, "arg", value) == -1)
2921 goto failed;
2922 Py_DECREF(value);
2923 value = ast2obj_expr(o->v.SimpleArg.annotation);
2924 if (!value) goto failed;
2925 if (PyObject_SetAttrString(result, "annotation", value) == -1)
2926 goto failed;
2927 Py_DECREF(value);
2928 break;
2929 case NestedArgs_kind:
2930 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
2931 if (!result) goto failed;
2932 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
2933 if (!value) goto failed;
2934 if (PyObject_SetAttrString(result, "args", value) == -1)
2935 goto failed;
2936 Py_DECREF(value);
2937 break;
2938 }
2939 return result;
2940failed:
2941 Py_XDECREF(value);
2942 Py_XDECREF(result);
2943 return NULL;
2944}
2945
2946PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002947ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002948{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002949 keyword_ty o = (keyword_ty)_o;
2950 PyObject *result = NULL, *value = NULL;
2951 if (!o) {
2952 Py_INCREF(Py_None);
2953 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002954 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002955
2956 result = PyType_GenericNew(keyword_type, NULL, NULL);
2957 if (!result) return NULL;
2958 value = ast2obj_identifier(o->arg);
2959 if (!value) goto failed;
2960 if (PyObject_SetAttrString(result, "arg", value) == -1)
2961 goto failed;
2962 Py_DECREF(value);
2963 value = ast2obj_expr(o->value);
2964 if (!value) goto failed;
2965 if (PyObject_SetAttrString(result, "value", value) == -1)
2966 goto failed;
2967 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002968 return result;
2969failed:
2970 Py_XDECREF(value);
2971 Py_XDECREF(result);
2972 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002973}
2974
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002975PyObject*
2976ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002977{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002978 alias_ty o = (alias_ty)_o;
2979 PyObject *result = NULL, *value = NULL;
2980 if (!o) {
2981 Py_INCREF(Py_None);
2982 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002983 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002984
2985 result = PyType_GenericNew(alias_type, NULL, NULL);
2986 if (!result) return NULL;
2987 value = ast2obj_identifier(o->name);
2988 if (!value) goto failed;
2989 if (PyObject_SetAttrString(result, "name", value) == -1)
2990 goto failed;
2991 Py_DECREF(value);
2992 value = ast2obj_identifier(o->asname);
2993 if (!value) goto failed;
2994 if (PyObject_SetAttrString(result, "asname", value) == -1)
2995 goto failed;
2996 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002997 return result;
2998failed:
2999 Py_XDECREF(value);
3000 Py_XDECREF(result);
3001 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003002}
3003
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003004
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003005PyMODINIT_FUNC
3006init_ast(void)
3007{
3008 PyObject *m, *d;
3009 if (!init_types()) return;
3010 m = Py_InitModule3("_ast", NULL, NULL);
3011 if (!m) return;
3012 d = PyModule_GetDict(m);
3013 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3014 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3015 return;
Thomas Woutersa44f3a32007-02-26 18:20:15 +00003016 if (PyModule_AddStringConstant(m, "__version__", "53873") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003017 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003018 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3019 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3020 return;
3021 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3022 < 0) return;
3023 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3024 0) return;
3025 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3026 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3027 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3028 < 0) return;
3029 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3030 return;
3031 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3032 return;
3033 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3034 return;
3035 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3036 return;
3037 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3038 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003039 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3040 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3041 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3042 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3043 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3044 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3045 0) return;
3046 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3047 0) return;
3048 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3049 return;
3050 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3051 return;
3052 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3053 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003054 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3055 return;
3056 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3057 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3058 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3059 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3060 return;
3061 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3062 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3063 return;
3064 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3065 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3066 return;
3067 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3068 return;
3069 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3070 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003071 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003072 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3073 return;
3074 if (PyDict_SetItemString(d, "GeneratorExp",
3075 (PyObject*)GeneratorExp_type) < 0) return;
3076 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3078 return;
3079 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003080 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3081 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003082 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003083 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3084 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003085 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3086 0) return;
3087 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3088 0) return;
3089 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3090 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3092 if (PyDict_SetItemString(d, "expr_context",
3093 (PyObject*)expr_context_type) < 0) return;
3094 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3095 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3096 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3097 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3098 return;
3099 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3100 return;
3101 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3102 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003103 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3104 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3105 return;
3106 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3107 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3108 return;
3109 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3110 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3111 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3114 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3115 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3116 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3117 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3118 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3119 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3120 return;
3121 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3122 return;
3123 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3124 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3125 return;
3126 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3129 return;
3130 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3131 return;
3132 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3133 return;
3134 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3135 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3136 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3137 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3138 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3139 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3140 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3141 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3142 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3143 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3144 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3145 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3146 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3147 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3148 if (PyDict_SetItemString(d, "comprehension",
3149 (PyObject*)comprehension_type) < 0) return;
3150 if (PyDict_SetItemString(d, "excepthandler",
3151 (PyObject*)excepthandler_type) < 0) return;
3152 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3153 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003154 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3155 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3156 0) return;
3157 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3158 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003159 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3160 return;
3161 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003162}
3163
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003164
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003165PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003166{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003167 init_types();
3168 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003169}
3170
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003171