blob: 390ba157e831865c59ff8793561bd7a64193d898 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Thomas Wouters00e41de2007-02-23 19:56:57 +00005 __version__ 53866.
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
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000451static PyObject* ast2obj_int(bool b)
452{
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));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000757 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000758 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759 return NULL;
760 }
761 p->kind = Module_kind;
762 p->v.Module.body = body;
763 return p;
764}
765
766mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000767Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000768{
769 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000770 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000772 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000773 return NULL;
774 }
775 p->kind = Interactive_kind;
776 p->v.Interactive.body = body;
777 return p;
778}
779
780mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000781Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000782{
783 mod_ty p;
784 if (!body) {
785 PyErr_SetString(PyExc_ValueError,
786 "field body is required for Expression");
787 return NULL;
788 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000789 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000790 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000791 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000792 return NULL;
793 }
794 p->kind = Expression_kind;
795 p->v.Expression.body = body;
796 return p;
797}
798
799mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000800Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000801{
802 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000803 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000805 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000806 return NULL;
807 }
808 p->kind = Suite_kind;
809 p->v.Suite.body = body;
810 return p;
811}
812
813stmt_ty
814FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000815 decorators, expr_ty returns, int lineno, int col_offset, PyArena
816 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817{
818 stmt_ty p;
819 if (!name) {
820 PyErr_SetString(PyExc_ValueError,
821 "field name is required for FunctionDef");
822 return NULL;
823 }
824 if (!args) {
825 PyErr_SetString(PyExc_ValueError,
826 "field args is required for FunctionDef");
827 return NULL;
828 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000829 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000830 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000831 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 return NULL;
833 }
834 p->kind = FunctionDef_kind;
835 p->v.FunctionDef.name = name;
836 p->v.FunctionDef.args = args;
837 p->v.FunctionDef.body = body;
838 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000839 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000841 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842 return p;
843}
844
845stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000846ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
847 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000848{
849 stmt_ty p;
850 if (!name) {
851 PyErr_SetString(PyExc_ValueError,
852 "field name is required for ClassDef");
853 return NULL;
854 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000855 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000857 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858 return NULL;
859 }
860 p->kind = ClassDef_kind;
861 p->v.ClassDef.name = name;
862 p->v.ClassDef.bases = bases;
863 p->v.ClassDef.body = body;
864 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000865 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 return p;
867}
868
869stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000870Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871{
872 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000873 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000875 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 return NULL;
877 }
878 p->kind = Return_kind;
879 p->v.Return.value = value;
880 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882 return p;
883}
884
885stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000886Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887{
888 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000889 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000891 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000892 return NULL;
893 }
894 p->kind = Delete_kind;
895 p->v.Delete.targets = targets;
896 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000897 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898 return p;
899}
900
901stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000902Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
903 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000904{
905 stmt_ty p;
906 if (!value) {
907 PyErr_SetString(PyExc_ValueError,
908 "field value is required for Assign");
909 return NULL;
910 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000911 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000912 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000913 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 return NULL;
915 }
916 p->kind = Assign_kind;
917 p->v.Assign.targets = targets;
918 p->v.Assign.value = value;
919 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000920 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000921 return p;
922}
923
924stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000925AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
926 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000927{
928 stmt_ty p;
929 if (!target) {
930 PyErr_SetString(PyExc_ValueError,
931 "field target is required for AugAssign");
932 return NULL;
933 }
934 if (!op) {
935 PyErr_SetString(PyExc_ValueError,
936 "field op is required for AugAssign");
937 return NULL;
938 }
939 if (!value) {
940 PyErr_SetString(PyExc_ValueError,
941 "field value is required for AugAssign");
942 return NULL;
943 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000944 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000945 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000946 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000947 return NULL;
948 }
949 p->kind = AugAssign_kind;
950 p->v.AugAssign.target = target;
951 p->v.AugAssign.op = op;
952 p->v.AugAssign.value = value;
953 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000954 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955 return p;
956}
957
958stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000959For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000960 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000961{
962 stmt_ty p;
963 if (!target) {
964 PyErr_SetString(PyExc_ValueError,
965 "field target is required for For");
966 return NULL;
967 }
968 if (!iter) {
969 PyErr_SetString(PyExc_ValueError,
970 "field iter is required for For");
971 return NULL;
972 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000973 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000974 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000975 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000976 return NULL;
977 }
978 p->kind = For_kind;
979 p->v.For.target = target;
980 p->v.For.iter = iter;
981 p->v.For.body = body;
982 p->v.For.orelse = orelse;
983 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000984 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985 return p;
986}
987
988stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000989While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
990 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991{
992 stmt_ty p;
993 if (!test) {
994 PyErr_SetString(PyExc_ValueError,
995 "field test is required for While");
996 return NULL;
997 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000998 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000999 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001000 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 return NULL;
1002 }
1003 p->kind = While_kind;
1004 p->v.While.test = test;
1005 p->v.While.body = body;
1006 p->v.While.orelse = orelse;
1007 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001008 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009 return p;
1010}
1011
1012stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001013If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1014 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001015{
1016 stmt_ty p;
1017 if (!test) {
1018 PyErr_SetString(PyExc_ValueError,
1019 "field test is required for If");
1020 return NULL;
1021 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001022 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001023 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001024 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001025 return NULL;
1026 }
1027 p->kind = If_kind;
1028 p->v.If.test = test;
1029 p->v.If.body = body;
1030 p->v.If.orelse = orelse;
1031 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001032 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001033 return p;
1034}
1035
1036stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001037With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001038 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001039{
1040 stmt_ty p;
1041 if (!context_expr) {
1042 PyErr_SetString(PyExc_ValueError,
1043 "field context_expr is required for With");
1044 return NULL;
1045 }
1046 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1047 if (!p) {
1048 PyErr_NoMemory();
1049 return NULL;
1050 }
1051 p->kind = With_kind;
1052 p->v.With.context_expr = context_expr;
1053 p->v.With.optional_vars = optional_vars;
1054 p->v.With.body = body;
1055 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001056 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001057 return p;
1058}
1059
1060stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001061Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1062 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063{
1064 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001065 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001066 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001067 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068 return NULL;
1069 }
1070 p->kind = Raise_kind;
1071 p->v.Raise.type = type;
1072 p->v.Raise.inst = inst;
1073 p->v.Raise.tback = tback;
1074 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001075 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076 return p;
1077}
1078
1079stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001080TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001081 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001082{
1083 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001084 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001086 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087 return NULL;
1088 }
1089 p->kind = TryExcept_kind;
1090 p->v.TryExcept.body = body;
1091 p->v.TryExcept.handlers = handlers;
1092 p->v.TryExcept.orelse = orelse;
1093 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001094 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 return p;
1096}
1097
1098stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001099TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1100 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101{
1102 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001103 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001105 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106 return NULL;
1107 }
1108 p->kind = TryFinally_kind;
1109 p->v.TryFinally.body = body;
1110 p->v.TryFinally.finalbody = finalbody;
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 +00001117Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118{
1119 stmt_ty p;
1120 if (!test) {
1121 PyErr_SetString(PyExc_ValueError,
1122 "field test is required for Assert");
1123 return NULL;
1124 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001125 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001126 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001127 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128 return NULL;
1129 }
1130 p->kind = Assert_kind;
1131 p->v.Assert.test = test;
1132 p->v.Assert.msg = msg;
1133 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001134 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 return p;
1136}
1137
1138stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001139Import(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));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001143 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001144 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 return NULL;
1146 }
1147 p->kind = Import_kind;
1148 p->v.Import.names = names;
1149 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001150 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151 return p;
1152}
1153
1154stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001155ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1156 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157{
1158 stmt_ty p;
1159 if (!module) {
1160 PyErr_SetString(PyExc_ValueError,
1161 "field module is required for ImportFrom");
1162 return NULL;
1163 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001164 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001165 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001166 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 return NULL;
1168 }
1169 p->kind = ImportFrom_kind;
1170 p->v.ImportFrom.module = module;
1171 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001172 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001174 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001175 return p;
1176}
1177
1178stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001179Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001180{
1181 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001182 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001184 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001185 return NULL;
1186 }
1187 p->kind = Global_kind;
1188 p->v.Global.names = names;
1189 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001190 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 return p;
1192}
1193
1194stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001195Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001196{
1197 stmt_ty p;
1198 if (!value) {
1199 PyErr_SetString(PyExc_ValueError,
1200 "field value is required for Expr");
1201 return NULL;
1202 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001203 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001205 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 return NULL;
1207 }
1208 p->kind = Expr_kind;
1209 p->v.Expr.value = value;
1210 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001211 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001212 return p;
1213}
1214
1215stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001216Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217{
1218 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001219 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001221 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return NULL;
1223 }
1224 p->kind = Pass_kind;
1225 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001226 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 return p;
1228}
1229
1230stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001231Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232{
1233 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001234 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001235 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001236 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001237 return NULL;
1238 }
1239 p->kind = Break_kind;
1240 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001241 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001242 return p;
1243}
1244
1245stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001246Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001247{
1248 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001249 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001251 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001252 return NULL;
1253 }
1254 p->kind = Continue_kind;
1255 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001256 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001257 return p;
1258}
1259
1260expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001261BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1262 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001263{
1264 expr_ty p;
1265 if (!op) {
1266 PyErr_SetString(PyExc_ValueError,
1267 "field op is required for BoolOp");
1268 return NULL;
1269 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001270 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001271 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001272 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001273 return NULL;
1274 }
1275 p->kind = BoolOp_kind;
1276 p->v.BoolOp.op = op;
1277 p->v.BoolOp.values = values;
1278 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001279 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001280 return p;
1281}
1282
1283expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001284BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1285 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001286{
1287 expr_ty p;
1288 if (!left) {
1289 PyErr_SetString(PyExc_ValueError,
1290 "field left is required for BinOp");
1291 return NULL;
1292 }
1293 if (!op) {
1294 PyErr_SetString(PyExc_ValueError,
1295 "field op is required for BinOp");
1296 return NULL;
1297 }
1298 if (!right) {
1299 PyErr_SetString(PyExc_ValueError,
1300 "field right is required for BinOp");
1301 return NULL;
1302 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001303 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001304 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001305 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001306 return NULL;
1307 }
1308 p->kind = BinOp_kind;
1309 p->v.BinOp.left = left;
1310 p->v.BinOp.op = op;
1311 p->v.BinOp.right = right;
1312 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001313 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001314 return p;
1315}
1316
1317expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001318UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1319 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001320{
1321 expr_ty p;
1322 if (!op) {
1323 PyErr_SetString(PyExc_ValueError,
1324 "field op is required for UnaryOp");
1325 return NULL;
1326 }
1327 if (!operand) {
1328 PyErr_SetString(PyExc_ValueError,
1329 "field operand is required for UnaryOp");
1330 return NULL;
1331 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001332 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001333 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001334 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001335 return NULL;
1336 }
1337 p->kind = UnaryOp_kind;
1338 p->v.UnaryOp.op = op;
1339 p->v.UnaryOp.operand = operand;
1340 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001341 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001342 return p;
1343}
1344
1345expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001346Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1347 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001348{
1349 expr_ty p;
1350 if (!args) {
1351 PyErr_SetString(PyExc_ValueError,
1352 "field args is required for Lambda");
1353 return NULL;
1354 }
1355 if (!body) {
1356 PyErr_SetString(PyExc_ValueError,
1357 "field body is required for Lambda");
1358 return NULL;
1359 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001360 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001361 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001362 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001363 return NULL;
1364 }
1365 p->kind = Lambda_kind;
1366 p->v.Lambda.args = args;
1367 p->v.Lambda.body = body;
1368 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001369 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001370 return p;
1371}
1372
1373expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001374IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1375 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001376{
1377 expr_ty p;
1378 if (!test) {
1379 PyErr_SetString(PyExc_ValueError,
1380 "field test is required for IfExp");
1381 return NULL;
1382 }
1383 if (!body) {
1384 PyErr_SetString(PyExc_ValueError,
1385 "field body is required for IfExp");
1386 return NULL;
1387 }
1388 if (!orelse) {
1389 PyErr_SetString(PyExc_ValueError,
1390 "field orelse is required for IfExp");
1391 return NULL;
1392 }
1393 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1394 if (!p) {
1395 PyErr_NoMemory();
1396 return NULL;
1397 }
1398 p->kind = IfExp_kind;
1399 p->v.IfExp.test = test;
1400 p->v.IfExp.body = body;
1401 p->v.IfExp.orelse = orelse;
1402 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001403 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001404 return p;
1405}
1406
1407expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001408Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1409 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001410{
1411 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001412 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001413 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001414 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001415 return NULL;
1416 }
1417 p->kind = Dict_kind;
1418 p->v.Dict.keys = keys;
1419 p->v.Dict.values = values;
1420 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001421 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422 return p;
1423}
1424
1425expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001426Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1427{
1428 expr_ty p;
1429 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1430 if (!p) {
1431 PyErr_NoMemory();
1432 return NULL;
1433 }
1434 p->kind = Set_kind;
1435 p->v.Set.elts = elts;
1436 p->lineno = lineno;
1437 p->col_offset = col_offset;
1438 return p;
1439}
1440
1441expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001442ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1443 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001444{
1445 expr_ty p;
1446 if (!elt) {
1447 PyErr_SetString(PyExc_ValueError,
1448 "field elt is required for ListComp");
1449 return NULL;
1450 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001451 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001453 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001454 return NULL;
1455 }
1456 p->kind = ListComp_kind;
1457 p->v.ListComp.elt = elt;
1458 p->v.ListComp.generators = generators;
1459 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001460 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001461 return p;
1462}
1463
1464expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001465GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1466 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001467{
1468 expr_ty p;
1469 if (!elt) {
1470 PyErr_SetString(PyExc_ValueError,
1471 "field elt is required for GeneratorExp");
1472 return NULL;
1473 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001474 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001476 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 return NULL;
1478 }
1479 p->kind = GeneratorExp_kind;
1480 p->v.GeneratorExp.elt = elt;
1481 p->v.GeneratorExp.generators = generators;
1482 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001483 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001484 return p;
1485}
1486
1487expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001488Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001489{
1490 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001491 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001493 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494 return NULL;
1495 }
1496 p->kind = Yield_kind;
1497 p->v.Yield.value = value;
1498 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001499 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500 return p;
1501}
1502
1503expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001504Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1505 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506{
1507 expr_ty p;
1508 if (!left) {
1509 PyErr_SetString(PyExc_ValueError,
1510 "field left is required for Compare");
1511 return NULL;
1512 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001513 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001515 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516 return NULL;
1517 }
1518 p->kind = Compare_kind;
1519 p->v.Compare.left = left;
1520 p->v.Compare.ops = ops;
1521 p->v.Compare.comparators = comparators;
1522 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001523 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524 return p;
1525}
1526
1527expr_ty
1528Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001529 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530{
1531 expr_ty p;
1532 if (!func) {
1533 PyErr_SetString(PyExc_ValueError,
1534 "field func is required for Call");
1535 return NULL;
1536 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001537 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001539 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540 return NULL;
1541 }
1542 p->kind = Call_kind;
1543 p->v.Call.func = func;
1544 p->v.Call.args = args;
1545 p->v.Call.keywords = keywords;
1546 p->v.Call.starargs = starargs;
1547 p->v.Call.kwargs = kwargs;
1548 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001549 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001550 return p;
1551}
1552
1553expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001554Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001555{
1556 expr_ty p;
1557 if (!n) {
1558 PyErr_SetString(PyExc_ValueError,
1559 "field n is required for Num");
1560 return NULL;
1561 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001562 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001563 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001564 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565 return NULL;
1566 }
1567 p->kind = Num_kind;
1568 p->v.Num.n = n;
1569 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001570 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001571 return p;
1572}
1573
1574expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001575Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001576{
1577 expr_ty p;
1578 if (!s) {
1579 PyErr_SetString(PyExc_ValueError,
1580 "field s is required for Str");
1581 return NULL;
1582 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001583 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001585 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001586 return NULL;
1587 }
1588 p->kind = Str_kind;
1589 p->v.Str.s = s;
1590 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001591 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001592 return p;
1593}
1594
1595expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001596Bytes(string s, int lineno, int col_offset, PyArena *arena)
1597{
1598 expr_ty p;
1599 if (!s) {
1600 PyErr_SetString(PyExc_ValueError,
1601 "field s is required for Bytes");
1602 return NULL;
1603 }
1604 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1605 if (!p) {
1606 PyErr_NoMemory();
1607 return NULL;
1608 }
1609 p->kind = Bytes_kind;
1610 p->v.Bytes.s = s;
1611 p->lineno = lineno;
1612 p->col_offset = col_offset;
1613 return p;
1614}
1615
1616expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001617Ellipsis(int lineno, int col_offset, PyArena *arena)
1618{
1619 expr_ty p;
1620 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1621 if (!p) {
1622 PyErr_NoMemory();
1623 return NULL;
1624 }
1625 p->kind = Ellipsis_kind;
1626 p->lineno = lineno;
1627 p->col_offset = col_offset;
1628 return p;
1629}
1630
1631expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001632Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1633 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001634{
1635 expr_ty p;
1636 if (!value) {
1637 PyErr_SetString(PyExc_ValueError,
1638 "field value is required for Attribute");
1639 return NULL;
1640 }
1641 if (!attr) {
1642 PyErr_SetString(PyExc_ValueError,
1643 "field attr is required for Attribute");
1644 return NULL;
1645 }
1646 if (!ctx) {
1647 PyErr_SetString(PyExc_ValueError,
1648 "field ctx is required for Attribute");
1649 return NULL;
1650 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001651 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001653 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001654 return NULL;
1655 }
1656 p->kind = Attribute_kind;
1657 p->v.Attribute.value = value;
1658 p->v.Attribute.attr = attr;
1659 p->v.Attribute.ctx = ctx;
1660 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001661 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001662 return p;
1663}
1664
1665expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001666Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1667 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668{
1669 expr_ty p;
1670 if (!value) {
1671 PyErr_SetString(PyExc_ValueError,
1672 "field value is required for Subscript");
1673 return NULL;
1674 }
1675 if (!slice) {
1676 PyErr_SetString(PyExc_ValueError,
1677 "field slice is required for Subscript");
1678 return NULL;
1679 }
1680 if (!ctx) {
1681 PyErr_SetString(PyExc_ValueError,
1682 "field ctx is required for Subscript");
1683 return NULL;
1684 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001685 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001686 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001687 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 return NULL;
1689 }
1690 p->kind = Subscript_kind;
1691 p->v.Subscript.value = value;
1692 p->v.Subscript.slice = slice;
1693 p->v.Subscript.ctx = ctx;
1694 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001695 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001696 return p;
1697}
1698
1699expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001700Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1701 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702{
1703 expr_ty p;
1704 if (!id) {
1705 PyErr_SetString(PyExc_ValueError,
1706 "field id is required for Name");
1707 return NULL;
1708 }
1709 if (!ctx) {
1710 PyErr_SetString(PyExc_ValueError,
1711 "field ctx is required for Name");
1712 return NULL;
1713 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001714 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001716 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001717 return NULL;
1718 }
1719 p->kind = Name_kind;
1720 p->v.Name.id = id;
1721 p->v.Name.ctx = ctx;
1722 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001723 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001724 return p;
1725}
1726
1727expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001728List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1729 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730{
1731 expr_ty p;
1732 if (!ctx) {
1733 PyErr_SetString(PyExc_ValueError,
1734 "field ctx is required for List");
1735 return NULL;
1736 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001737 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001739 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740 return NULL;
1741 }
1742 p->kind = List_kind;
1743 p->v.List.elts = elts;
1744 p->v.List.ctx = ctx;
1745 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001746 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001747 return p;
1748}
1749
1750expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001751Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1752 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753{
1754 expr_ty p;
1755 if (!ctx) {
1756 PyErr_SetString(PyExc_ValueError,
1757 "field ctx is required for Tuple");
1758 return NULL;
1759 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001760 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001762 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763 return NULL;
1764 }
1765 p->kind = Tuple_kind;
1766 p->v.Tuple.elts = elts;
1767 p->v.Tuple.ctx = ctx;
1768 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001769 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770 return p;
1771}
1772
1773slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001774Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001775{
1776 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001779 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001780 return NULL;
1781 }
1782 p->kind = Slice_kind;
1783 p->v.Slice.lower = lower;
1784 p->v.Slice.upper = upper;
1785 p->v.Slice.step = step;
1786 return p;
1787}
1788
1789slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001790ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791{
1792 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001793 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001795 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001796 return NULL;
1797 }
1798 p->kind = ExtSlice_kind;
1799 p->v.ExtSlice.dims = dims;
1800 return p;
1801}
1802
1803slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001804Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805{
1806 slice_ty p;
1807 if (!value) {
1808 PyErr_SetString(PyExc_ValueError,
1809 "field value is required for Index");
1810 return NULL;
1811 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001812 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001814 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001815 return NULL;
1816 }
1817 p->kind = Index_kind;
1818 p->v.Index.value = value;
1819 return p;
1820}
1821
1822comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001823comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001824{
1825 comprehension_ty p;
1826 if (!target) {
1827 PyErr_SetString(PyExc_ValueError,
1828 "field target is required for comprehension");
1829 return NULL;
1830 }
1831 if (!iter) {
1832 PyErr_SetString(PyExc_ValueError,
1833 "field iter is required for comprehension");
1834 return NULL;
1835 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001836 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001837 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001838 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001839 return NULL;
1840 }
1841 p->target = target;
1842 p->iter = iter;
1843 p->ifs = ifs;
1844 return p;
1845}
1846
1847excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001848excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001849 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850{
1851 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001852 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001854 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855 return NULL;
1856 }
1857 p->type = type;
1858 p->name = name;
1859 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001860 p->lineno = lineno;
1861 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 return p;
1863}
1864
1865arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001866arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1867 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1868 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001869{
1870 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001871 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001872 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001873 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001874 return NULL;
1875 }
1876 p->args = args;
1877 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001878 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001879 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001880 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001881 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001883 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001884 return p;
1885}
1886
Neal Norwitzc1505362006-12-28 06:47:50 +00001887arg_ty
1888SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1889{
1890 arg_ty p;
1891 if (!arg) {
1892 PyErr_SetString(PyExc_ValueError,
1893 "field arg is required for SimpleArg");
1894 return NULL;
1895 }
1896 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1897 if (!p) {
1898 PyErr_NoMemory();
1899 return NULL;
1900 }
1901 p->kind = SimpleArg_kind;
1902 p->v.SimpleArg.arg = arg;
1903 p->v.SimpleArg.annotation = annotation;
1904 return p;
1905}
1906
1907arg_ty
1908NestedArgs(asdl_seq * args, PyArena *arena)
1909{
1910 arg_ty p;
1911 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1912 if (!p) {
1913 PyErr_NoMemory();
1914 return NULL;
1915 }
1916 p->kind = NestedArgs_kind;
1917 p->v.NestedArgs.args = args;
1918 return p;
1919}
1920
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001921keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001922keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923{
1924 keyword_ty p;
1925 if (!arg) {
1926 PyErr_SetString(PyExc_ValueError,
1927 "field arg is required for keyword");
1928 return NULL;
1929 }
1930 if (!value) {
1931 PyErr_SetString(PyExc_ValueError,
1932 "field value is required for keyword");
1933 return NULL;
1934 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001935 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001936 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001937 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001938 return NULL;
1939 }
1940 p->arg = arg;
1941 p->value = value;
1942 return p;
1943}
1944
1945alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001946alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947{
1948 alias_ty p;
1949 if (!name) {
1950 PyErr_SetString(PyExc_ValueError,
1951 "field name is required for alias");
1952 return NULL;
1953 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001954 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001955 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001956 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001957 return NULL;
1958 }
1959 p->name = name;
1960 p->asname = asname;
1961 return p;
1962}
1963
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001964
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001965PyObject*
1966ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001967{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 mod_ty o = (mod_ty)_o;
1969 PyObject *result = NULL, *value = NULL;
1970 if (!o) {
1971 Py_INCREF(Py_None);
1972 return Py_None;
1973 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001974
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 switch (o->kind) {
1976 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Module_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "body", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "body", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001993 break;
1994 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001995 result = PyType_GenericNew(Expression_type, NULL, NULL);
1996 if (!result) goto failed;
1997 value = ast2obj_expr(o->v.Expression.body);
1998 if (!value) goto failed;
1999 if (PyObject_SetAttrString(result, "body", value) == -1)
2000 goto failed;
2001 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002002 break;
2003 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002004 result = PyType_GenericNew(Suite_type, NULL, NULL);
2005 if (!result) goto failed;
2006 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2007 if (!value) goto failed;
2008 if (PyObject_SetAttrString(result, "body", value) == -1)
2009 goto failed;
2010 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002011 break;
2012 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002013 return result;
2014failed:
2015 Py_XDECREF(value);
2016 Py_XDECREF(result);
2017 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002018}
2019
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002020PyObject*
2021ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002022{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002023 stmt_ty o = (stmt_ty)_o;
2024 PyObject *result = NULL, *value = NULL;
2025 if (!o) {
2026 Py_INCREF(Py_None);
2027 return Py_None;
2028 }
2029
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002030 switch (o->kind) {
2031 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002032 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2033 if (!result) goto failed;
2034 value = ast2obj_identifier(o->v.FunctionDef.name);
2035 if (!value) goto failed;
2036 if (PyObject_SetAttrString(result, "name", value) == -1)
2037 goto failed;
2038 Py_DECREF(value);
2039 value = ast2obj_arguments(o->v.FunctionDef.args);
2040 if (!value) goto failed;
2041 if (PyObject_SetAttrString(result, "args", value) == -1)
2042 goto failed;
2043 Py_DECREF(value);
2044 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2045 if (!value) goto failed;
2046 if (PyObject_SetAttrString(result, "body", value) == -1)
2047 goto failed;
2048 Py_DECREF(value);
2049 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2050 if (!value) goto failed;
2051 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2052 goto failed;
2053 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002054 value = ast2obj_expr(o->v.FunctionDef.returns);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "returns", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002059 break;
2060 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002061 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2062 if (!result) goto failed;
2063 value = ast2obj_identifier(o->v.ClassDef.name);
2064 if (!value) goto failed;
2065 if (PyObject_SetAttrString(result, "name", value) == -1)
2066 goto failed;
2067 Py_DECREF(value);
2068 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "bases", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
2073 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "body", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002078 break;
2079 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002080 result = PyType_GenericNew(Return_type, NULL, NULL);
2081 if (!result) goto failed;
2082 value = ast2obj_expr(o->v.Return.value);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "value", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002087 break;
2088 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002089 result = PyType_GenericNew(Delete_type, NULL, NULL);
2090 if (!result) goto failed;
2091 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2092 if (!value) goto failed;
2093 if (PyObject_SetAttrString(result, "targets", value) == -1)
2094 goto failed;
2095 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096 break;
2097 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002098 result = PyType_GenericNew(Assign_type, NULL, NULL);
2099 if (!result) goto failed;
2100 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2101 if (!value) goto failed;
2102 if (PyObject_SetAttrString(result, "targets", value) == -1)
2103 goto failed;
2104 Py_DECREF(value);
2105 value = ast2obj_expr(o->v.Assign.value);
2106 if (!value) goto failed;
2107 if (PyObject_SetAttrString(result, "value", value) == -1)
2108 goto failed;
2109 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002110 break;
2111 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002112 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2113 if (!result) goto failed;
2114 value = ast2obj_expr(o->v.AugAssign.target);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "target", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
2119 value = ast2obj_operator(o->v.AugAssign.op);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "op", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 value = ast2obj_expr(o->v.AugAssign.value);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "value", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002129 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002130 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002131 result = PyType_GenericNew(For_type, NULL, NULL);
2132 if (!result) goto failed;
2133 value = ast2obj_expr(o->v.For.target);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "target", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
2138 value = ast2obj_expr(o->v.For.iter);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "iter", value) == -1)
2141 goto failed;
2142 Py_DECREF(value);
2143 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2144 if (!value) goto failed;
2145 if (PyObject_SetAttrString(result, "body", value) == -1)
2146 goto failed;
2147 Py_DECREF(value);
2148 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2149 if (!value) goto failed;
2150 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2151 goto failed;
2152 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002153 break;
2154 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002155 result = PyType_GenericNew(While_type, NULL, NULL);
2156 if (!result) goto failed;
2157 value = ast2obj_expr(o->v.While.test);
2158 if (!value) goto failed;
2159 if (PyObject_SetAttrString(result, "test", value) == -1)
2160 goto failed;
2161 Py_DECREF(value);
2162 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2163 if (!value) goto failed;
2164 if (PyObject_SetAttrString(result, "body", value) == -1)
2165 goto failed;
2166 Py_DECREF(value);
2167 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2168 if (!value) goto failed;
2169 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2170 goto failed;
2171 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002172 break;
2173 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002174 result = PyType_GenericNew(If_type, NULL, NULL);
2175 if (!result) goto failed;
2176 value = ast2obj_expr(o->v.If.test);
2177 if (!value) goto failed;
2178 if (PyObject_SetAttrString(result, "test", value) == -1)
2179 goto failed;
2180 Py_DECREF(value);
2181 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2182 if (!value) goto failed;
2183 if (PyObject_SetAttrString(result, "body", value) == -1)
2184 goto failed;
2185 Py_DECREF(value);
2186 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2187 if (!value) goto failed;
2188 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2189 goto failed;
2190 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002191 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002192 case With_kind:
2193 result = PyType_GenericNew(With_type, NULL, NULL);
2194 if (!result) goto failed;
2195 value = ast2obj_expr(o->v.With.context_expr);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
2200 value = ast2obj_expr(o->v.With.optional_vars);
2201 if (!value) goto failed;
2202 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2203 -1)
2204 goto failed;
2205 Py_DECREF(value);
2206 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2207 if (!value) goto failed;
2208 if (PyObject_SetAttrString(result, "body", value) == -1)
2209 goto failed;
2210 Py_DECREF(value);
2211 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002212 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002213 result = PyType_GenericNew(Raise_type, NULL, NULL);
2214 if (!result) goto failed;
2215 value = ast2obj_expr(o->v.Raise.type);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "type", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
2220 value = ast2obj_expr(o->v.Raise.inst);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "inst", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
2225 value = ast2obj_expr(o->v.Raise.tback);
2226 if (!value) goto failed;
2227 if (PyObject_SetAttrString(result, "tback", value) == -1)
2228 goto failed;
2229 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002230 break;
2231 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002232 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2233 if (!result) goto failed;
2234 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "body", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
2239 value = ast2obj_list(o->v.TryExcept.handlers,
2240 ast2obj_excepthandler);
2241 if (!value) goto failed;
2242 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2243 goto failed;
2244 Py_DECREF(value);
2245 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002250 break;
2251 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002252 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2253 if (!result) goto failed;
2254 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "body", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
2259 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002264 break;
2265 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002266 result = PyType_GenericNew(Assert_type, NULL, NULL);
2267 if (!result) goto failed;
2268 value = ast2obj_expr(o->v.Assert.test);
2269 if (!value) goto failed;
2270 if (PyObject_SetAttrString(result, "test", value) == -1)
2271 goto failed;
2272 Py_DECREF(value);
2273 value = ast2obj_expr(o->v.Assert.msg);
2274 if (!value) goto failed;
2275 if (PyObject_SetAttrString(result, "msg", value) == -1)
2276 goto failed;
2277 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002278 break;
2279 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002280 result = PyType_GenericNew(Import_type, NULL, NULL);
2281 if (!result) goto failed;
2282 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2283 if (!value) goto failed;
2284 if (PyObject_SetAttrString(result, "names", value) == -1)
2285 goto failed;
2286 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002287 break;
2288 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002289 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2290 if (!result) goto failed;
2291 value = ast2obj_identifier(o->v.ImportFrom.module);
2292 if (!value) goto failed;
2293 if (PyObject_SetAttrString(result, "module", value) == -1)
2294 goto failed;
2295 Py_DECREF(value);
2296 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2297 if (!value) goto failed;
2298 if (PyObject_SetAttrString(result, "names", value) == -1)
2299 goto failed;
2300 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002301 value = ast2obj_int(o->v.ImportFrom.level);
2302 if (!value) goto failed;
2303 if (PyObject_SetAttrString(result, "level", value) == -1)
2304 goto failed;
2305 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002306 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002307 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002308 result = PyType_GenericNew(Global_type, NULL, NULL);
2309 if (!result) goto failed;
2310 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2311 if (!value) goto failed;
2312 if (PyObject_SetAttrString(result, "names", value) == -1)
2313 goto failed;
2314 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002315 break;
2316 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002317 result = PyType_GenericNew(Expr_type, NULL, NULL);
2318 if (!result) goto failed;
2319 value = ast2obj_expr(o->v.Expr.value);
2320 if (!value) goto failed;
2321 if (PyObject_SetAttrString(result, "value", value) == -1)
2322 goto failed;
2323 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324 break;
2325 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002326 result = PyType_GenericNew(Pass_type, NULL, NULL);
2327 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002328 break;
2329 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002330 result = PyType_GenericNew(Break_type, NULL, NULL);
2331 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002332 break;
2333 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002334 result = PyType_GenericNew(Continue_type, NULL, NULL);
2335 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002336 break;
2337 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002338 value = ast2obj_int(o->lineno);
2339 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002340 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2341 goto failed;
2342 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002343 value = ast2obj_int(o->col_offset);
2344 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002345 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2346 goto failed;
2347 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002348 return result;
2349failed:
2350 Py_XDECREF(value);
2351 Py_XDECREF(result);
2352 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002353}
2354
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002355PyObject*
2356ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002357{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358 expr_ty o = (expr_ty)_o;
2359 PyObject *result = NULL, *value = NULL;
2360 if (!o) {
2361 Py_INCREF(Py_None);
2362 return Py_None;
2363 }
2364
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002365 switch (o->kind) {
2366 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002367 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2368 if (!result) goto failed;
2369 value = ast2obj_boolop(o->v.BoolOp.op);
2370 if (!value) goto failed;
2371 if (PyObject_SetAttrString(result, "op", value) == -1)
2372 goto failed;
2373 Py_DECREF(value);
2374 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "values", value) == -1)
2377 goto failed;
2378 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002379 break;
2380 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002381 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2382 if (!result) goto failed;
2383 value = ast2obj_expr(o->v.BinOp.left);
2384 if (!value) goto failed;
2385 if (PyObject_SetAttrString(result, "left", value) == -1)
2386 goto failed;
2387 Py_DECREF(value);
2388 value = ast2obj_operator(o->v.BinOp.op);
2389 if (!value) goto failed;
2390 if (PyObject_SetAttrString(result, "op", value) == -1)
2391 goto failed;
2392 Py_DECREF(value);
2393 value = ast2obj_expr(o->v.BinOp.right);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "right", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002398 break;
2399 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002400 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2401 if (!result) goto failed;
2402 value = ast2obj_unaryop(o->v.UnaryOp.op);
2403 if (!value) goto failed;
2404 if (PyObject_SetAttrString(result, "op", value) == -1)
2405 goto failed;
2406 Py_DECREF(value);
2407 value = ast2obj_expr(o->v.UnaryOp.operand);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "operand", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002412 break;
2413 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002414 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2415 if (!result) goto failed;
2416 value = ast2obj_arguments(o->v.Lambda.args);
2417 if (!value) goto failed;
2418 if (PyObject_SetAttrString(result, "args", value) == -1)
2419 goto failed;
2420 Py_DECREF(value);
2421 value = ast2obj_expr(o->v.Lambda.body);
2422 if (!value) goto failed;
2423 if (PyObject_SetAttrString(result, "body", value) == -1)
2424 goto failed;
2425 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002426 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002427 case IfExp_kind:
2428 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2429 if (!result) goto failed;
2430 value = ast2obj_expr(o->v.IfExp.test);
2431 if (!value) goto failed;
2432 if (PyObject_SetAttrString(result, "test", value) == -1)
2433 goto failed;
2434 Py_DECREF(value);
2435 value = ast2obj_expr(o->v.IfExp.body);
2436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "body", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 value = ast2obj_expr(o->v.IfExp.orelse);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
2445 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002446 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002447 result = PyType_GenericNew(Dict_type, NULL, NULL);
2448 if (!result) goto failed;
2449 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2450 if (!value) goto failed;
2451 if (PyObject_SetAttrString(result, "keys", value) == -1)
2452 goto failed;
2453 Py_DECREF(value);
2454 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2455 if (!value) goto failed;
2456 if (PyObject_SetAttrString(result, "values", value) == -1)
2457 goto failed;
2458 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002459 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002460 case Set_kind:
2461 result = PyType_GenericNew(Set_type, NULL, NULL);
2462 if (!result) goto failed;
2463 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2464 if (!value) goto failed;
2465 if (PyObject_SetAttrString(result, "elts", value) == -1)
2466 goto failed;
2467 Py_DECREF(value);
2468 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002469 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002470 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2471 if (!result) goto failed;
2472 value = ast2obj_expr(o->v.ListComp.elt);
2473 if (!value) goto failed;
2474 if (PyObject_SetAttrString(result, "elt", value) == -1)
2475 goto failed;
2476 Py_DECREF(value);
2477 value = ast2obj_list(o->v.ListComp.generators,
2478 ast2obj_comprehension);
2479 if (!value) goto failed;
2480 if (PyObject_SetAttrString(result, "generators", value) == -1)
2481 goto failed;
2482 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002483 break;
2484 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002485 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2486 if (!result) goto failed;
2487 value = ast2obj_expr(o->v.GeneratorExp.elt);
2488 if (!value) goto failed;
2489 if (PyObject_SetAttrString(result, "elt", value) == -1)
2490 goto failed;
2491 Py_DECREF(value);
2492 value = ast2obj_list(o->v.GeneratorExp.generators,
2493 ast2obj_comprehension);
2494 if (!value) goto failed;
2495 if (PyObject_SetAttrString(result, "generators", value) == -1)
2496 goto failed;
2497 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002498 break;
2499 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002500 result = PyType_GenericNew(Yield_type, NULL, NULL);
2501 if (!result) goto failed;
2502 value = ast2obj_expr(o->v.Yield.value);
2503 if (!value) goto failed;
2504 if (PyObject_SetAttrString(result, "value", value) == -1)
2505 goto failed;
2506 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002507 break;
2508 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002509 result = PyType_GenericNew(Compare_type, NULL, NULL);
2510 if (!result) goto failed;
2511 value = ast2obj_expr(o->v.Compare.left);
2512 if (!value) goto failed;
2513 if (PyObject_SetAttrString(result, "left", value) == -1)
2514 goto failed;
2515 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002516 {
2517 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2518 value = PyList_New(n);
2519 if (!value) goto failed;
2520 for(i = 0; i < n; i++)
2521 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2522 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002523 if (!value) goto failed;
2524 if (PyObject_SetAttrString(result, "ops", value) == -1)
2525 goto failed;
2526 Py_DECREF(value);
2527 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2528 if (!value) goto failed;
2529 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2530 goto failed;
2531 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002532 break;
2533 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002534 result = PyType_GenericNew(Call_type, NULL, NULL);
2535 if (!result) goto failed;
2536 value = ast2obj_expr(o->v.Call.func);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "func", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "args", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
2546 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
2551 value = ast2obj_expr(o->v.Call.starargs);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
2556 value = ast2obj_expr(o->v.Call.kwargs);
2557 if (!value) goto failed;
2558 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2559 goto failed;
2560 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002561 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002562 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002563 result = PyType_GenericNew(Num_type, NULL, NULL);
2564 if (!result) goto failed;
2565 value = ast2obj_object(o->v.Num.n);
2566 if (!value) goto failed;
2567 if (PyObject_SetAttrString(result, "n", value) == -1)
2568 goto failed;
2569 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002570 break;
2571 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002572 result = PyType_GenericNew(Str_type, NULL, NULL);
2573 if (!result) goto failed;
2574 value = ast2obj_string(o->v.Str.s);
2575 if (!value) goto failed;
2576 if (PyObject_SetAttrString(result, "s", value) == -1)
2577 goto failed;
2578 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002579 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002580 case Bytes_kind:
2581 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2582 if (!result) goto failed;
2583 value = ast2obj_string(o->v.Bytes.s);
2584 if (!value) goto failed;
2585 if (PyObject_SetAttrString(result, "s", value) == -1)
2586 goto failed;
2587 Py_DECREF(value);
2588 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002589 case Ellipsis_kind:
2590 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2591 if (!result) goto failed;
2592 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002593 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002594 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2595 if (!result) goto failed;
2596 value = ast2obj_expr(o->v.Attribute.value);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "value", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 value = ast2obj_identifier(o->v.Attribute.attr);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "attr", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
2606 value = ast2obj_expr_context(o->v.Attribute.ctx);
2607 if (!value) goto failed;
2608 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2609 goto failed;
2610 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002611 break;
2612 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002613 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2614 if (!result) goto failed;
2615 value = ast2obj_expr(o->v.Subscript.value);
2616 if (!value) goto failed;
2617 if (PyObject_SetAttrString(result, "value", value) == -1)
2618 goto failed;
2619 Py_DECREF(value);
2620 value = ast2obj_slice(o->v.Subscript.slice);
2621 if (!value) goto failed;
2622 if (PyObject_SetAttrString(result, "slice", value) == -1)
2623 goto failed;
2624 Py_DECREF(value);
2625 value = ast2obj_expr_context(o->v.Subscript.ctx);
2626 if (!value) goto failed;
2627 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2628 goto failed;
2629 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002630 break;
2631 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002632 result = PyType_GenericNew(Name_type, NULL, NULL);
2633 if (!result) goto failed;
2634 value = ast2obj_identifier(o->v.Name.id);
2635 if (!value) goto failed;
2636 if (PyObject_SetAttrString(result, "id", value) == -1)
2637 goto failed;
2638 Py_DECREF(value);
2639 value = ast2obj_expr_context(o->v.Name.ctx);
2640 if (!value) goto failed;
2641 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2642 goto failed;
2643 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002644 break;
2645 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002646 result = PyType_GenericNew(List_type, NULL, NULL);
2647 if (!result) goto failed;
2648 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2649 if (!value) goto failed;
2650 if (PyObject_SetAttrString(result, "elts", value) == -1)
2651 goto failed;
2652 Py_DECREF(value);
2653 value = ast2obj_expr_context(o->v.List.ctx);
2654 if (!value) goto failed;
2655 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2656 goto failed;
2657 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002658 break;
2659 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002660 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2661 if (!result) goto failed;
2662 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2663 if (!value) goto failed;
2664 if (PyObject_SetAttrString(result, "elts", value) == -1)
2665 goto failed;
2666 Py_DECREF(value);
2667 value = ast2obj_expr_context(o->v.Tuple.ctx);
2668 if (!value) goto failed;
2669 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2670 goto failed;
2671 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002672 break;
2673 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002674 value = ast2obj_int(o->lineno);
2675 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002676 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2677 goto failed;
2678 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002679 value = ast2obj_int(o->col_offset);
2680 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002681 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2682 goto failed;
2683 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002684 return result;
2685failed:
2686 Py_XDECREF(value);
2687 Py_XDECREF(result);
2688 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002689}
2690
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002692{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002693 switch(o) {
2694 case Load:
2695 Py_INCREF(Load_singleton);
2696 return Load_singleton;
2697 case Store:
2698 Py_INCREF(Store_singleton);
2699 return Store_singleton;
2700 case Del:
2701 Py_INCREF(Del_singleton);
2702 return Del_singleton;
2703 case AugLoad:
2704 Py_INCREF(AugLoad_singleton);
2705 return AugLoad_singleton;
2706 case AugStore:
2707 Py_INCREF(AugStore_singleton);
2708 return AugStore_singleton;
2709 case Param:
2710 Py_INCREF(Param_singleton);
2711 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002712 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002713 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002714}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002715PyObject*
2716ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002718 slice_ty o = (slice_ty)_o;
2719 PyObject *result = NULL, *value = NULL;
2720 if (!o) {
2721 Py_INCREF(Py_None);
2722 return Py_None;
2723 }
2724
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002725 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002726 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002727 result = PyType_GenericNew(Slice_type, NULL, NULL);
2728 if (!result) goto failed;
2729 value = ast2obj_expr(o->v.Slice.lower);
2730 if (!value) goto failed;
2731 if (PyObject_SetAttrString(result, "lower", value) == -1)
2732 goto failed;
2733 Py_DECREF(value);
2734 value = ast2obj_expr(o->v.Slice.upper);
2735 if (!value) goto failed;
2736 if (PyObject_SetAttrString(result, "upper", value) == -1)
2737 goto failed;
2738 Py_DECREF(value);
2739 value = ast2obj_expr(o->v.Slice.step);
2740 if (!value) goto failed;
2741 if (PyObject_SetAttrString(result, "step", value) == -1)
2742 goto failed;
2743 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002744 break;
2745 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002746 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2747 if (!result) goto failed;
2748 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2749 if (!value) goto failed;
2750 if (PyObject_SetAttrString(result, "dims", value) == -1)
2751 goto failed;
2752 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002753 break;
2754 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002755 result = PyType_GenericNew(Index_type, NULL, NULL);
2756 if (!result) goto failed;
2757 value = ast2obj_expr(o->v.Index.value);
2758 if (!value) goto failed;
2759 if (PyObject_SetAttrString(result, "value", value) == -1)
2760 goto failed;
2761 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002762 break;
2763 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002764 return result;
2765failed:
2766 Py_XDECREF(value);
2767 Py_XDECREF(result);
2768 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002769}
2770
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002771PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002772{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002773 switch(o) {
2774 case And:
2775 Py_INCREF(And_singleton);
2776 return And_singleton;
2777 case Or:
2778 Py_INCREF(Or_singleton);
2779 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002780 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002781 return NULL; /* cannot happen */
2782}
2783PyObject* ast2obj_operator(operator_ty o)
2784{
2785 switch(o) {
2786 case Add:
2787 Py_INCREF(Add_singleton);
2788 return Add_singleton;
2789 case Sub:
2790 Py_INCREF(Sub_singleton);
2791 return Sub_singleton;
2792 case Mult:
2793 Py_INCREF(Mult_singleton);
2794 return Mult_singleton;
2795 case Div:
2796 Py_INCREF(Div_singleton);
2797 return Div_singleton;
2798 case Mod:
2799 Py_INCREF(Mod_singleton);
2800 return Mod_singleton;
2801 case Pow:
2802 Py_INCREF(Pow_singleton);
2803 return Pow_singleton;
2804 case LShift:
2805 Py_INCREF(LShift_singleton);
2806 return LShift_singleton;
2807 case RShift:
2808 Py_INCREF(RShift_singleton);
2809 return RShift_singleton;
2810 case BitOr:
2811 Py_INCREF(BitOr_singleton);
2812 return BitOr_singleton;
2813 case BitXor:
2814 Py_INCREF(BitXor_singleton);
2815 return BitXor_singleton;
2816 case BitAnd:
2817 Py_INCREF(BitAnd_singleton);
2818 return BitAnd_singleton;
2819 case FloorDiv:
2820 Py_INCREF(FloorDiv_singleton);
2821 return FloorDiv_singleton;
2822 }
2823 return NULL; /* cannot happen */
2824}
2825PyObject* ast2obj_unaryop(unaryop_ty o)
2826{
2827 switch(o) {
2828 case Invert:
2829 Py_INCREF(Invert_singleton);
2830 return Invert_singleton;
2831 case Not:
2832 Py_INCREF(Not_singleton);
2833 return Not_singleton;
2834 case UAdd:
2835 Py_INCREF(UAdd_singleton);
2836 return UAdd_singleton;
2837 case USub:
2838 Py_INCREF(USub_singleton);
2839 return USub_singleton;
2840 }
2841 return NULL; /* cannot happen */
2842}
2843PyObject* ast2obj_cmpop(cmpop_ty o)
2844{
2845 switch(o) {
2846 case Eq:
2847 Py_INCREF(Eq_singleton);
2848 return Eq_singleton;
2849 case NotEq:
2850 Py_INCREF(NotEq_singleton);
2851 return NotEq_singleton;
2852 case Lt:
2853 Py_INCREF(Lt_singleton);
2854 return Lt_singleton;
2855 case LtE:
2856 Py_INCREF(LtE_singleton);
2857 return LtE_singleton;
2858 case Gt:
2859 Py_INCREF(Gt_singleton);
2860 return Gt_singleton;
2861 case GtE:
2862 Py_INCREF(GtE_singleton);
2863 return GtE_singleton;
2864 case Is:
2865 Py_INCREF(Is_singleton);
2866 return Is_singleton;
2867 case IsNot:
2868 Py_INCREF(IsNot_singleton);
2869 return IsNot_singleton;
2870 case In:
2871 Py_INCREF(In_singleton);
2872 return In_singleton;
2873 case NotIn:
2874 Py_INCREF(NotIn_singleton);
2875 return NotIn_singleton;
2876 }
2877 return NULL; /* cannot happen */
2878}
2879PyObject*
2880ast2obj_comprehension(void* _o)
2881{
2882 comprehension_ty o = (comprehension_ty)_o;
2883 PyObject *result = NULL, *value = NULL;
2884 if (!o) {
2885 Py_INCREF(Py_None);
2886 return Py_None;
2887 }
2888
2889 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2890 if (!result) return NULL;
2891 value = ast2obj_expr(o->target);
2892 if (!value) goto failed;
2893 if (PyObject_SetAttrString(result, "target", value) == -1)
2894 goto failed;
2895 Py_DECREF(value);
2896 value = ast2obj_expr(o->iter);
2897 if (!value) goto failed;
2898 if (PyObject_SetAttrString(result, "iter", value) == -1)
2899 goto failed;
2900 Py_DECREF(value);
2901 value = ast2obj_list(o->ifs, ast2obj_expr);
2902 if (!value) goto failed;
2903 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2904 goto failed;
2905 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002906 return result;
2907failed:
2908 Py_XDECREF(value);
2909 Py_XDECREF(result);
2910 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002911}
2912
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002913PyObject*
2914ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002915{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002916 excepthandler_ty o = (excepthandler_ty)_o;
2917 PyObject *result = NULL, *value = NULL;
2918 if (!o) {
2919 Py_INCREF(Py_None);
2920 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002921 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002922
2923 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2924 if (!result) return NULL;
2925 value = ast2obj_expr(o->type);
2926 if (!value) goto failed;
2927 if (PyObject_SetAttrString(result, "type", value) == -1)
2928 goto failed;
2929 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002930 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002931 if (!value) goto failed;
2932 if (PyObject_SetAttrString(result, "name", value) == -1)
2933 goto failed;
2934 Py_DECREF(value);
2935 value = ast2obj_list(o->body, ast2obj_stmt);
2936 if (!value) goto failed;
2937 if (PyObject_SetAttrString(result, "body", value) == -1)
2938 goto failed;
2939 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002940 value = ast2obj_int(o->lineno);
2941 if (!value) goto failed;
2942 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2943 goto failed;
2944 Py_DECREF(value);
2945 value = ast2obj_int(o->col_offset);
2946 if (!value) goto failed;
2947 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2948 goto failed;
2949 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002950 return result;
2951failed:
2952 Py_XDECREF(value);
2953 Py_XDECREF(result);
2954 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002955}
2956
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002957PyObject*
2958ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002959{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002960 arguments_ty o = (arguments_ty)_o;
2961 PyObject *result = NULL, *value = NULL;
2962 if (!o) {
2963 Py_INCREF(Py_None);
2964 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002965 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002966
2967 result = PyType_GenericNew(arguments_type, NULL, NULL);
2968 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002969 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002970 if (!value) goto failed;
2971 if (PyObject_SetAttrString(result, "args", value) == -1)
2972 goto failed;
2973 Py_DECREF(value);
2974 value = ast2obj_identifier(o->vararg);
2975 if (!value) goto failed;
2976 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2977 goto failed;
2978 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002979 value = ast2obj_expr(o->varargannotation);
2980 if (!value) goto failed;
2981 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2982 goto failed;
2983 Py_DECREF(value);
2984 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002985 if (!value) goto failed;
2986 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2987 goto failed;
2988 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002989 value = ast2obj_identifier(o->kwarg);
2990 if (!value) goto failed;
2991 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2992 goto failed;
2993 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002994 value = ast2obj_expr(o->kwargannotation);
2995 if (!value) goto failed;
2996 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2997 goto failed;
2998 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002999 value = ast2obj_list(o->defaults, ast2obj_expr);
3000 if (!value) goto failed;
3001 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00003004 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3005 if (!value) goto failed;
3006 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
3007 goto failed;
3008 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003009 return result;
3010failed:
3011 Py_XDECREF(value);
3012 Py_XDECREF(result);
3013 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003014}
3015
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003016PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003017ast2obj_arg(void* _o)
3018{
3019 arg_ty o = (arg_ty)_o;
3020 PyObject *result = NULL, *value = NULL;
3021 if (!o) {
3022 Py_INCREF(Py_None);
3023 return Py_None;
3024 }
3025
3026 switch (o->kind) {
3027 case SimpleArg_kind:
3028 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
3029 if (!result) goto failed;
3030 value = ast2obj_identifier(o->v.SimpleArg.arg);
3031 if (!value) goto failed;
3032 if (PyObject_SetAttrString(result, "arg", value) == -1)
3033 goto failed;
3034 Py_DECREF(value);
3035 value = ast2obj_expr(o->v.SimpleArg.annotation);
3036 if (!value) goto failed;
3037 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3038 goto failed;
3039 Py_DECREF(value);
3040 break;
3041 case NestedArgs_kind:
3042 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
3043 if (!result) goto failed;
3044 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3045 if (!value) goto failed;
3046 if (PyObject_SetAttrString(result, "args", value) == -1)
3047 goto failed;
3048 Py_DECREF(value);
3049 break;
3050 }
3051 return result;
3052failed:
3053 Py_XDECREF(value);
3054 Py_XDECREF(result);
3055 return NULL;
3056}
3057
3058PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003059ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003060{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003061 keyword_ty o = (keyword_ty)_o;
3062 PyObject *result = NULL, *value = NULL;
3063 if (!o) {
3064 Py_INCREF(Py_None);
3065 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003066 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003067
3068 result = PyType_GenericNew(keyword_type, NULL, NULL);
3069 if (!result) return NULL;
3070 value = ast2obj_identifier(o->arg);
3071 if (!value) goto failed;
3072 if (PyObject_SetAttrString(result, "arg", value) == -1)
3073 goto failed;
3074 Py_DECREF(value);
3075 value = ast2obj_expr(o->value);
3076 if (!value) goto failed;
3077 if (PyObject_SetAttrString(result, "value", value) == -1)
3078 goto failed;
3079 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003080 return result;
3081failed:
3082 Py_XDECREF(value);
3083 Py_XDECREF(result);
3084 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003085}
3086
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003087PyObject*
3088ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003089{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003090 alias_ty o = (alias_ty)_o;
3091 PyObject *result = NULL, *value = NULL;
3092 if (!o) {
3093 Py_INCREF(Py_None);
3094 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003095 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003096
3097 result = PyType_GenericNew(alias_type, NULL, NULL);
3098 if (!result) return NULL;
3099 value = ast2obj_identifier(o->name);
3100 if (!value) goto failed;
3101 if (PyObject_SetAttrString(result, "name", value) == -1)
3102 goto failed;
3103 Py_DECREF(value);
3104 value = ast2obj_identifier(o->asname);
3105 if (!value) goto failed;
3106 if (PyObject_SetAttrString(result, "asname", value) == -1)
3107 goto failed;
3108 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003109 return result;
3110failed:
3111 Py_XDECREF(value);
3112 Py_XDECREF(result);
3113 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003114}
3115
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003116
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003117PyMODINIT_FUNC
3118init_ast(void)
3119{
3120 PyObject *m, *d;
3121 if (!init_types()) return;
3122 m = Py_InitModule3("_ast", NULL, NULL);
3123 if (!m) return;
3124 d = PyModule_GetDict(m);
3125 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3126 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3127 return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003128 if (PyModule_AddStringConstant(m, "__version__", "53866") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003129 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003130 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3131 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3132 return;
3133 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3134 < 0) return;
3135 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3136 0) return;
3137 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3138 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3139 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3140 < 0) return;
3141 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3142 return;
3143 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3144 return;
3145 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3146 return;
3147 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3148 return;
3149 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3150 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003151 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3152 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3153 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3154 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3155 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3156 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3157 0) return;
3158 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3159 0) return;
3160 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3161 return;
3162 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3163 return;
3164 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3165 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003166 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3167 return;
3168 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3169 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3170 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3172 return;
3173 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3174 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3175 return;
3176 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3177 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3178 return;
3179 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3180 return;
3181 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3182 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003183 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003184 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3185 return;
3186 if (PyDict_SetItemString(d, "GeneratorExp",
3187 (PyObject*)GeneratorExp_type) < 0) return;
3188 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3189 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3190 return;
3191 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003192 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3193 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003194 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003195 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3196 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003197 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3198 0) return;
3199 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3200 0) return;
3201 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3202 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3203 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3204 if (PyDict_SetItemString(d, "expr_context",
3205 (PyObject*)expr_context_type) < 0) return;
3206 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3207 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3208 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3209 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3210 return;
3211 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3212 return;
3213 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3214 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003215 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3216 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3217 return;
3218 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3219 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3220 return;
3221 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3222 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3223 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3224 return;
3225 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3226 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3227 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3228 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3229 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3230 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3231 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3232 return;
3233 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3234 return;
3235 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3236 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3237 return;
3238 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3239 return;
3240 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3241 return;
3242 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3243 return;
3244 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3245 return;
3246 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3247 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3248 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3249 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3250 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3251 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3252 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3253 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3254 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3255 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3256 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3257 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3258 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3259 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3260 if (PyDict_SetItemString(d, "comprehension",
3261 (PyObject*)comprehension_type) < 0) return;
3262 if (PyDict_SetItemString(d, "excepthandler",
3263 (PyObject*)excepthandler_type) < 0) return;
3264 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3265 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003266 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3267 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3268 0) return;
3269 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3270 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003271 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3272 return;
3273 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003274}
3275
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003276
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003277PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003278{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003279 init_types();
3280 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003281}
3282
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003283