blob: c024a6277615d9a357b1ef4323fb7a10cd1575aa [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Brett Cannon5b198e82007-02-27 20:16:01 +00005 __version__ 53986.
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};
Jeremy Hylton81e95022007-02-27 06:50:52 +0000134static PyTypeObject *Nonlocal_type;
135static char *Nonlocal_fields[]={
136 "names",
137};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000138static PyTypeObject *Expr_type;
139static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000140 "value",
141};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000142static PyTypeObject *Pass_type;
143static PyTypeObject *Break_type;
144static PyTypeObject *Continue_type;
145static PyTypeObject *expr_type;
146static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000147 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000148 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000149};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000150static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000151static PyTypeObject *BoolOp_type;
152static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000153 "op",
154 "values",
155};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000156static PyTypeObject *BinOp_type;
157static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000158 "left",
159 "op",
160 "right",
161};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000162static PyTypeObject *UnaryOp_type;
163static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000164 "op",
165 "operand",
166};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000167static PyTypeObject *Lambda_type;
168static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000169 "args",
170 "body",
171};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000172static PyTypeObject *IfExp_type;
173static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000174 "test",
175 "body",
176 "orelse",
177};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000178static PyTypeObject *Dict_type;
179static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000180 "keys",
181 "values",
182};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000183static PyTypeObject *Set_type;
184static char *Set_fields[]={
185 "elts",
186};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000187static PyTypeObject *ListComp_type;
188static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000189 "elt",
190 "generators",
191};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000192static PyTypeObject *GeneratorExp_type;
193static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000194 "elt",
195 "generators",
196};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000197static PyTypeObject *Yield_type;
198static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000199 "value",
200};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000201static PyTypeObject *Compare_type;
202static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000203 "left",
204 "ops",
205 "comparators",
206};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000207static PyTypeObject *Call_type;
208static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000209 "func",
210 "args",
211 "keywords",
212 "starargs",
213 "kwargs",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Num_type;
216static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "n",
218};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000219static PyTypeObject *Str_type;
220static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000221 "s",
222};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000223static PyTypeObject *Bytes_type;
224static char *Bytes_fields[]={
225 "s",
226};
Georg Brandl52318d62006-09-06 07:06:08 +0000227static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000228static PyTypeObject *Attribute_type;
229static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000230 "value",
231 "attr",
232 "ctx",
233};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000234static PyTypeObject *Subscript_type;
235static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000236 "value",
237 "slice",
238 "ctx",
239};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000240static PyTypeObject *Name_type;
241static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000242 "id",
243 "ctx",
244};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000245static PyTypeObject *List_type;
246static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000247 "elts",
248 "ctx",
249};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000250static PyTypeObject *Tuple_type;
251static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000252 "elts",
253 "ctx",
254};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000255static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000256static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
257*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
258static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000259static PyTypeObject *Load_type;
260static PyTypeObject *Store_type;
261static PyTypeObject *Del_type;
262static PyTypeObject *AugLoad_type;
263static PyTypeObject *AugStore_type;
264static PyTypeObject *Param_type;
265static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000266static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *Slice_type;
268static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269 "lower",
270 "upper",
271 "step",
272};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000273static PyTypeObject *ExtSlice_type;
274static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000275 "dims",
276};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000277static PyTypeObject *Index_type;
278static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000279 "value",
280};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000281static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000282static PyObject *And_singleton, *Or_singleton;
283static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000284static PyTypeObject *And_type;
285static PyTypeObject *Or_type;
286static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000287static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
288*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
289*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
290*FloorDiv_singleton;
291static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000292static PyTypeObject *Add_type;
293static PyTypeObject *Sub_type;
294static PyTypeObject *Mult_type;
295static PyTypeObject *Div_type;
296static PyTypeObject *Mod_type;
297static PyTypeObject *Pow_type;
298static PyTypeObject *LShift_type;
299static PyTypeObject *RShift_type;
300static PyTypeObject *BitOr_type;
301static PyTypeObject *BitXor_type;
302static PyTypeObject *BitAnd_type;
303static PyTypeObject *FloorDiv_type;
304static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000305static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
306*USub_singleton;
307static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000308static PyTypeObject *Invert_type;
309static PyTypeObject *Not_type;
310static PyTypeObject *UAdd_type;
311static PyTypeObject *USub_type;
312static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000313static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
314*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
315*NotIn_singleton;
316static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000317static PyTypeObject *Eq_type;
318static PyTypeObject *NotEq_type;
319static PyTypeObject *Lt_type;
320static PyTypeObject *LtE_type;
321static PyTypeObject *Gt_type;
322static PyTypeObject *GtE_type;
323static PyTypeObject *Is_type;
324static PyTypeObject *IsNot_type;
325static PyTypeObject *In_type;
326static PyTypeObject *NotIn_type;
327static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000328static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000329static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000330 "target",
331 "iter",
332 "ifs",
333};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000334static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000335static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000336static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000337 "type",
338 "name",
339 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000340 "lineno",
341 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000343static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000345static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346 "args",
347 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000348 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000349 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000351 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000353 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000354};
Neal Norwitzc1505362006-12-28 06:47:50 +0000355static PyTypeObject *arg_type;
356static PyObject* ast2obj_arg(void*);
357static PyTypeObject *SimpleArg_type;
358static char *SimpleArg_fields[]={
359 "arg",
360 "annotation",
361};
362static PyTypeObject *NestedArgs_type;
363static char *NestedArgs_fields[]={
364 "args",
365};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000366static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000367static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000368static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000369 "arg",
370 "value",
371};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000372static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000373static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000374static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000375 "name",
376 "asname",
377};
378
379
380static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
381{
382 PyObject *fnames, *result;
383 int i;
384 if (num_fields) {
385 fnames = PyTuple_New(num_fields);
386 if (!fnames) return NULL;
387 } else {
388 fnames = Py_None;
389 Py_INCREF(Py_None);
390 }
391 for(i=0; i < num_fields; i++) {
392 PyObject *field = PyString_FromString(fields[i]);
393 if (!field) {
394 Py_DECREF(fnames);
395 return NULL;
396 }
397 PyTuple_SET_ITEM(fnames, i, field);
398 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000399 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000400 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000401 Py_DECREF(fnames);
402 return (PyTypeObject*)result;
403}
404
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000405static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
406{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000407 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000408 PyObject *s, *l = PyList_New(num_fields);
409 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000410 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000411 s = PyString_FromString(attrs[i]);
412 if (!s) {
413 Py_DECREF(l);
414 return 0;
415 }
416 PyList_SET_ITEM(l, i, s);
417 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000418 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
419 Py_DECREF(l);
420 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000421}
422
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000423static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
424{
425 int i, n = asdl_seq_LEN(seq);
426 PyObject *result = PyList_New(n);
427 PyObject *value;
428 if (!result)
429 return NULL;
430 for (i = 0; i < n; i++) {
431 value = func(asdl_seq_GET(seq, i));
432 if (!value) {
433 Py_DECREF(result);
434 return NULL;
435 }
436 PyList_SET_ITEM(result, i, value);
437 }
438 return result;
439}
440
441static PyObject* ast2obj_object(void *o)
442{
443 if (!o)
444 o = Py_None;
445 Py_INCREF((PyObject*)o);
446 return (PyObject*)o;
447}
448#define ast2obj_identifier ast2obj_object
449#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000450
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000451static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452{
453 return PyInt_FromLong(b);
454}
455
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456static int init_types(void)
457{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000458 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
461 mod_type = make_type("mod", AST_type, NULL, 0);
462 if (!mod_type) return 0;
463 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000465 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000466 Interactive_type = make_type("Interactive", mod_type,
467 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Expression_type = make_type("Expression", mod_type, Expression_fields,
470 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000471 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 if (!Suite_type) return 0;
474 stmt_type = make_type("stmt", AST_type, NULL, 0);
475 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000476 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000478 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000496 With_type = make_type("With", stmt_type, With_fields, 3);
497 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
503 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000510 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000514 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
515 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000518 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000520 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000522 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!Continue_type) return 0;
524 expr_type = make_type("expr", AST_type, NULL, 0);
525 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000526 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000535 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000539 Set_type = make_type("Set", expr_type, Set_fields, 1);
540 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 GeneratorExp_type = make_type("GeneratorExp", expr_type,
544 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000556 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
557 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000558 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
559 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Tuple_type) return 0;
570 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
571 if (!expr_context_type) return 0;
572 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000573 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000575 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000577 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000581 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000585 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000589 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000591 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000592 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000593 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000595 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!Param_singleton) return 0;
597 slice_type = make_type("slice", AST_type, NULL, 0);
598 if (!slice_type) return 0;
599 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000600 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000602 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000604 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!Index_type) return 0;
606 boolop_type = make_type("boolop", AST_type, NULL, 0);
607 if (!boolop_type) return 0;
608 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000609 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000611 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000613 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Or_singleton) return 0;
617 operator_type = make_type("operator", AST_type, NULL, 0);
618 if (!operator_type) return 0;
619 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000620 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000622 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000624 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000626 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000628 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000630 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000632 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000634 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000636 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000638 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000640 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000642 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000644 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000646 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000664 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000666 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!FloorDiv_singleton) return 0;
668 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
669 if (!unaryop_type) return 0;
670 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000671 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000673 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000675 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000677 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000679 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000681 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000683 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!USub_singleton) return 0;
687 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
688 if (!cmpop_type) return 0;
689 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000690 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000692 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000694 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000696 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000698 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000700 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000702 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000704 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000706 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000708 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000710 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000714 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000716 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000718 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000720 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000722 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000724 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000725 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000726 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000728 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!NotIn_singleton) return 0;
730 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000731 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000732 if (!comprehension_type) return 0;
733 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000734 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000736 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000737 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000738 arg_type = make_type("arg", AST_type, NULL, 0);
739 if (!arg_type) return 0;
740 if (!add_attributes(arg_type, NULL, 0)) return 0;
741 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
742 if (!SimpleArg_type) return 0;
743 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
744 1);
745 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000746 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
747 if (!keyword_type) return 0;
748 alias_type = make_type("alias", AST_type, alias_fields, 2);
749 if (!alias_type) return 0;
750 initialized = 1;
751 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000752}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000753
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000754mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000755Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000756{
757 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000758 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000759 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000760 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761 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));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000771 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000772 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000773 p->kind = Interactive_kind;
774 p->v.Interactive.body = body;
775 return p;
776}
777
778mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000779Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000780{
781 mod_ty p;
782 if (!body) {
783 PyErr_SetString(PyExc_ValueError,
784 "field body is required for Expression");
785 return NULL;
786 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000787 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000788 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000789 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000790 p->kind = Expression_kind;
791 p->v.Expression.body = body;
792 return p;
793}
794
795mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000796Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000797{
798 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000799 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000800 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000801 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802 p->kind = Suite_kind;
803 p->v.Suite.body = body;
804 return p;
805}
806
807stmt_ty
808FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000809 decorators, expr_ty returns, int lineno, int col_offset, PyArena
810 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811{
812 stmt_ty p;
813 if (!name) {
814 PyErr_SetString(PyExc_ValueError,
815 "field name is required for FunctionDef");
816 return NULL;
817 }
818 if (!args) {
819 PyErr_SetString(PyExc_ValueError,
820 "field args is required for FunctionDef");
821 return NULL;
822 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000823 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000824 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826 p->kind = FunctionDef_kind;
827 p->v.FunctionDef.name = name;
828 p->v.FunctionDef.args = args;
829 p->v.FunctionDef.body = body;
830 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000831 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000833 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000834 return p;
835}
836
837stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000838ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
839 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840{
841 stmt_ty p;
842 if (!name) {
843 PyErr_SetString(PyExc_ValueError,
844 "field name is required for ClassDef");
845 return NULL;
846 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000847 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000848 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000850 p->kind = ClassDef_kind;
851 p->v.ClassDef.name = name;
852 p->v.ClassDef.bases = bases;
853 p->v.ClassDef.body = body;
854 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000855 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856 return p;
857}
858
859stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000860Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861{
862 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000863 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000864 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 p->kind = Return_kind;
867 p->v.Return.value = value;
868 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000869 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000870 return p;
871}
872
873stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000874Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875{
876 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000877 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000878 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000879 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000880 p->kind = Delete_kind;
881 p->v.Delete.targets = targets;
882 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000883 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000884 return p;
885}
886
887stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000888Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
889 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890{
891 stmt_ty p;
892 if (!value) {
893 PyErr_SetString(PyExc_ValueError,
894 "field value is required for Assign");
895 return NULL;
896 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000897 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000898 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000900 p->kind = Assign_kind;
901 p->v.Assign.targets = targets;
902 p->v.Assign.value = value;
903 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000904 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000905 return p;
906}
907
908stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000909AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
910 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000911{
912 stmt_ty p;
913 if (!target) {
914 PyErr_SetString(PyExc_ValueError,
915 "field target is required for AugAssign");
916 return NULL;
917 }
918 if (!op) {
919 PyErr_SetString(PyExc_ValueError,
920 "field op is required for AugAssign");
921 return NULL;
922 }
923 if (!value) {
924 PyErr_SetString(PyExc_ValueError,
925 "field value is required for AugAssign");
926 return NULL;
927 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000928 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000929 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931 p->kind = AugAssign_kind;
932 p->v.AugAssign.target = target;
933 p->v.AugAssign.op = op;
934 p->v.AugAssign.value = value;
935 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000936 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000937 return p;
938}
939
940stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000942 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000943{
944 stmt_ty p;
945 if (!target) {
946 PyErr_SetString(PyExc_ValueError,
947 "field target is required for For");
948 return NULL;
949 }
950 if (!iter) {
951 PyErr_SetString(PyExc_ValueError,
952 "field iter is required for For");
953 return NULL;
954 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000955 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000956 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000957 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000958 p->kind = For_kind;
959 p->v.For.target = target;
960 p->v.For.iter = iter;
961 p->v.For.body = body;
962 p->v.For.orelse = orelse;
963 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000964 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000965 return p;
966}
967
968stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000969While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
970 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000971{
972 stmt_ty p;
973 if (!test) {
974 PyErr_SetString(PyExc_ValueError,
975 "field test is required for While");
976 return NULL;
977 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000978 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000979 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000980 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000981 p->kind = While_kind;
982 p->v.While.test = test;
983 p->v.While.body = body;
984 p->v.While.orelse = orelse;
985 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000986 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987 return p;
988}
989
990stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000991If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
992 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000993{
994 stmt_ty p;
995 if (!test) {
996 PyErr_SetString(PyExc_ValueError,
997 "field test is required for If");
998 return NULL;
999 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001000 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001001 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001002 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003 p->kind = If_kind;
1004 p->v.If.test = test;
1005 p->v.If.body = body;
1006 p->v.If.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
Guido van Rossumc2e20742006-02-27 22:32:47 +00001013With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001014 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001015{
1016 stmt_ty p;
1017 if (!context_expr) {
1018 PyErr_SetString(PyExc_ValueError,
1019 "field context_expr is required for With");
1020 return NULL;
1021 }
1022 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001023 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001024 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025 p->kind = With_kind;
1026 p->v.With.context_expr = context_expr;
1027 p->v.With.optional_vars = optional_vars;
1028 p->v.With.body = body;
1029 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001030 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001031 return p;
1032}
1033
1034stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001035Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1036 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001037{
1038 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001039 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001040 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001041 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001042 p->kind = Raise_kind;
1043 p->v.Raise.type = type;
1044 p->v.Raise.inst = inst;
1045 p->v.Raise.tback = tback;
1046 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001047 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001048 return p;
1049}
1050
1051stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001052TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001053 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054{
1055 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001056 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001057 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001058 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001059 p->kind = TryExcept_kind;
1060 p->v.TryExcept.body = body;
1061 p->v.TryExcept.handlers = handlers;
1062 p->v.TryExcept.orelse = orelse;
1063 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001064 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001065 return p;
1066}
1067
1068stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001069TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1070 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071{
1072 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001073 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001074 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076 p->kind = TryFinally_kind;
1077 p->v.TryFinally.body = body;
1078 p->v.TryFinally.finalbody = finalbody;
1079 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001080 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081 return p;
1082}
1083
1084stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001085Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001086{
1087 stmt_ty p;
1088 if (!test) {
1089 PyErr_SetString(PyExc_ValueError,
1090 "field test is required for Assert");
1091 return NULL;
1092 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001093 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001094 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096 p->kind = Assert_kind;
1097 p->v.Assert.test = test;
1098 p->v.Assert.msg = msg;
1099 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001100 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101 return p;
1102}
1103
1104stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001105Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106{
1107 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001108 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001109 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001110 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001111 p->kind = Import_kind;
1112 p->v.Import.names = names;
1113 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001114 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001115 return p;
1116}
1117
1118stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001119ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1120 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001121{
1122 stmt_ty p;
1123 if (!module) {
1124 PyErr_SetString(PyExc_ValueError,
1125 "field module is required for ImportFrom");
1126 return NULL;
1127 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001128 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001129 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001130 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 p->kind = ImportFrom_kind;
1132 p->v.ImportFrom.module = module;
1133 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001134 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001136 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 return p;
1138}
1139
1140stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001141Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001142{
1143 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001144 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001145 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001146 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147 p->kind = Global_kind;
1148 p->v.Global.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
Jeremy Hylton81e95022007-02-27 06:50:52 +00001155Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1156{
1157 stmt_ty p;
1158 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1159 if (!p)
1160 return NULL;
1161 p->kind = Nonlocal_kind;
1162 p->v.Nonlocal.names = names;
1163 p->lineno = lineno;
1164 p->col_offset = col_offset;
1165 return p;
1166}
1167
1168stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001169Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001170{
1171 stmt_ty p;
1172 if (!value) {
1173 PyErr_SetString(PyExc_ValueError,
1174 "field value is required for Expr");
1175 return NULL;
1176 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001177 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001178 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001180 p->kind = Expr_kind;
1181 p->v.Expr.value = value;
1182 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001183 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001184 return p;
1185}
1186
1187stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001188Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001189{
1190 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001191 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001192 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001193 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194 p->kind = Pass_kind;
1195 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001196 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 return p;
1198}
1199
1200stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001201Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001202{
1203 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001204 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001205 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 p->kind = Break_kind;
1208 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001209 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210 return p;
1211}
1212
1213stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001214Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001215{
1216 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001217 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001218 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001219 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 p->kind = Continue_kind;
1221 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001222 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 return p;
1224}
1225
1226expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001227BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1228 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229{
1230 expr_ty p;
1231 if (!op) {
1232 PyErr_SetString(PyExc_ValueError,
1233 "field op is required for BoolOp");
1234 return NULL;
1235 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001236 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001237 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001238 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239 p->kind = BoolOp_kind;
1240 p->v.BoolOp.op = op;
1241 p->v.BoolOp.values = values;
1242 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001243 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244 return p;
1245}
1246
1247expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001248BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1249 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250{
1251 expr_ty p;
1252 if (!left) {
1253 PyErr_SetString(PyExc_ValueError,
1254 "field left is required for BinOp");
1255 return NULL;
1256 }
1257 if (!op) {
1258 PyErr_SetString(PyExc_ValueError,
1259 "field op is required for BinOp");
1260 return NULL;
1261 }
1262 if (!right) {
1263 PyErr_SetString(PyExc_ValueError,
1264 "field right is required for BinOp");
1265 return NULL;
1266 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001267 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001268 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001269 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001270 p->kind = BinOp_kind;
1271 p->v.BinOp.left = left;
1272 p->v.BinOp.op = op;
1273 p->v.BinOp.right = right;
1274 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001275 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001276 return p;
1277}
1278
1279expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001280UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1281 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001282{
1283 expr_ty p;
1284 if (!op) {
1285 PyErr_SetString(PyExc_ValueError,
1286 "field op is required for UnaryOp");
1287 return NULL;
1288 }
1289 if (!operand) {
1290 PyErr_SetString(PyExc_ValueError,
1291 "field operand is required for UnaryOp");
1292 return NULL;
1293 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001294 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001295 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001296 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001297 p->kind = UnaryOp_kind;
1298 p->v.UnaryOp.op = op;
1299 p->v.UnaryOp.operand = operand;
1300 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001301 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302 return p;
1303}
1304
1305expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001306Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1307 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001308{
1309 expr_ty p;
1310 if (!args) {
1311 PyErr_SetString(PyExc_ValueError,
1312 "field args is required for Lambda");
1313 return NULL;
1314 }
1315 if (!body) {
1316 PyErr_SetString(PyExc_ValueError,
1317 "field body is required for Lambda");
1318 return NULL;
1319 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001320 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001321 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001322 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001323 p->kind = Lambda_kind;
1324 p->v.Lambda.args = args;
1325 p->v.Lambda.body = body;
1326 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001327 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001328 return p;
1329}
1330
1331expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001332IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1333 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001334{
1335 expr_ty p;
1336 if (!test) {
1337 PyErr_SetString(PyExc_ValueError,
1338 "field test is required for IfExp");
1339 return NULL;
1340 }
1341 if (!body) {
1342 PyErr_SetString(PyExc_ValueError,
1343 "field body is required for IfExp");
1344 return NULL;
1345 }
1346 if (!orelse) {
1347 PyErr_SetString(PyExc_ValueError,
1348 "field orelse is required for IfExp");
1349 return NULL;
1350 }
1351 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001352 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001353 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001354 p->kind = IfExp_kind;
1355 p->v.IfExp.test = test;
1356 p->v.IfExp.body = body;
1357 p->v.IfExp.orelse = orelse;
1358 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001359 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001360 return p;
1361}
1362
1363expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001364Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1365 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001366{
1367 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001368 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001369 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001370 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001371 p->kind = Dict_kind;
1372 p->v.Dict.keys = keys;
1373 p->v.Dict.values = values;
1374 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001375 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001376 return p;
1377}
1378
1379expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001380Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1381{
1382 expr_ty p;
1383 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001384 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001385 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001386 p->kind = Set_kind;
1387 p->v.Set.elts = elts;
1388 p->lineno = lineno;
1389 p->col_offset = col_offset;
1390 return p;
1391}
1392
1393expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001394ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1395 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001396{
1397 expr_ty p;
1398 if (!elt) {
1399 PyErr_SetString(PyExc_ValueError,
1400 "field elt is required for ListComp");
1401 return NULL;
1402 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001403 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001404 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001405 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001406 p->kind = ListComp_kind;
1407 p->v.ListComp.elt = elt;
1408 p->v.ListComp.generators = generators;
1409 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001410 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001411 return p;
1412}
1413
1414expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1416 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001417{
1418 expr_ty p;
1419 if (!elt) {
1420 PyErr_SetString(PyExc_ValueError,
1421 "field elt is required for GeneratorExp");
1422 return NULL;
1423 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001424 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001425 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 p->kind = GeneratorExp_kind;
1428 p->v.GeneratorExp.elt = elt;
1429 p->v.GeneratorExp.generators = generators;
1430 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001431 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001432 return p;
1433}
1434
1435expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001436Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001437{
1438 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001439 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001440 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001441 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001442 p->kind = Yield_kind;
1443 p->v.Yield.value = value;
1444 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001445 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001446 return p;
1447}
1448
1449expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001450Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1451 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452{
1453 expr_ty p;
1454 if (!left) {
1455 PyErr_SetString(PyExc_ValueError,
1456 "field left is required for Compare");
1457 return NULL;
1458 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001459 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001460 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001461 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001462 p->kind = Compare_kind;
1463 p->v.Compare.left = left;
1464 p->v.Compare.ops = ops;
1465 p->v.Compare.comparators = comparators;
1466 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001467 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001468 return p;
1469}
1470
1471expr_ty
1472Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001473 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001474{
1475 expr_ty p;
1476 if (!func) {
1477 PyErr_SetString(PyExc_ValueError,
1478 "field func is required for Call");
1479 return NULL;
1480 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001481 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001482 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001483 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001484 p->kind = Call_kind;
1485 p->v.Call.func = func;
1486 p->v.Call.args = args;
1487 p->v.Call.keywords = keywords;
1488 p->v.Call.starargs = starargs;
1489 p->v.Call.kwargs = kwargs;
1490 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001491 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 return p;
1493}
1494
1495expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001496Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001497{
1498 expr_ty p;
1499 if (!n) {
1500 PyErr_SetString(PyExc_ValueError,
1501 "field n is required for Num");
1502 return NULL;
1503 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001504 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001505 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001507 p->kind = Num_kind;
1508 p->v.Num.n = n;
1509 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001510 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001511 return p;
1512}
1513
1514expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001515Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516{
1517 expr_ty p;
1518 if (!s) {
1519 PyErr_SetString(PyExc_ValueError,
1520 "field s is required for Str");
1521 return NULL;
1522 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001523 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001524 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001525 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526 p->kind = Str_kind;
1527 p->v.Str.s = s;
1528 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001529 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530 return p;
1531}
1532
1533expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001534Bytes(string s, int lineno, int col_offset, PyArena *arena)
1535{
1536 expr_ty p;
1537 if (!s) {
1538 PyErr_SetString(PyExc_ValueError,
1539 "field s is required for Bytes");
1540 return NULL;
1541 }
1542 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001543 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001544 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001545 p->kind = Bytes_kind;
1546 p->v.Bytes.s = s;
1547 p->lineno = lineno;
1548 p->col_offset = col_offset;
1549 return p;
1550}
1551
1552expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001553Ellipsis(int lineno, int col_offset, PyArena *arena)
1554{
1555 expr_ty p;
1556 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001557 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001558 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001559 p->kind = Ellipsis_kind;
1560 p->lineno = lineno;
1561 p->col_offset = col_offset;
1562 return p;
1563}
1564
1565expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001566Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1567 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001568{
1569 expr_ty p;
1570 if (!value) {
1571 PyErr_SetString(PyExc_ValueError,
1572 "field value is required for Attribute");
1573 return NULL;
1574 }
1575 if (!attr) {
1576 PyErr_SetString(PyExc_ValueError,
1577 "field attr is required for Attribute");
1578 return NULL;
1579 }
1580 if (!ctx) {
1581 PyErr_SetString(PyExc_ValueError,
1582 "field ctx is required for Attribute");
1583 return NULL;
1584 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001585 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001586 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001587 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001588 p->kind = Attribute_kind;
1589 p->v.Attribute.value = value;
1590 p->v.Attribute.attr = attr;
1591 p->v.Attribute.ctx = ctx;
1592 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001593 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594 return p;
1595}
1596
1597expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001598Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1599 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001600{
1601 expr_ty p;
1602 if (!value) {
1603 PyErr_SetString(PyExc_ValueError,
1604 "field value is required for Subscript");
1605 return NULL;
1606 }
1607 if (!slice) {
1608 PyErr_SetString(PyExc_ValueError,
1609 "field slice is required for Subscript");
1610 return NULL;
1611 }
1612 if (!ctx) {
1613 PyErr_SetString(PyExc_ValueError,
1614 "field ctx is required for Subscript");
1615 return NULL;
1616 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001617 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001618 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001619 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001620 p->kind = Subscript_kind;
1621 p->v.Subscript.value = value;
1622 p->v.Subscript.slice = slice;
1623 p->v.Subscript.ctx = ctx;
1624 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001625 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001626 return p;
1627}
1628
1629expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001630Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1631 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001632{
1633 expr_ty p;
1634 if (!id) {
1635 PyErr_SetString(PyExc_ValueError,
1636 "field id is required for Name");
1637 return NULL;
1638 }
1639 if (!ctx) {
1640 PyErr_SetString(PyExc_ValueError,
1641 "field ctx is required for Name");
1642 return NULL;
1643 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001644 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001645 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001646 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001647 p->kind = Name_kind;
1648 p->v.Name.id = id;
1649 p->v.Name.ctx = ctx;
1650 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001651 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 return p;
1653}
1654
1655expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001656List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1657 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001658{
1659 expr_ty p;
1660 if (!ctx) {
1661 PyErr_SetString(PyExc_ValueError,
1662 "field ctx is required for List");
1663 return NULL;
1664 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001665 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001666 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001667 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668 p->kind = List_kind;
1669 p->v.List.elts = elts;
1670 p->v.List.ctx = ctx;
1671 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001672 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001673 return p;
1674}
1675
1676expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001677Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1678 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679{
1680 expr_ty p;
1681 if (!ctx) {
1682 PyErr_SetString(PyExc_ValueError,
1683 "field ctx is required for Tuple");
1684 return NULL;
1685 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001686 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001687 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001689 p->kind = Tuple_kind;
1690 p->v.Tuple.elts = elts;
1691 p->v.Tuple.ctx = ctx;
1692 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001693 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001694 return p;
1695}
1696
1697slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001698Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001699{
1700 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001701 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001702 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001704 p->kind = Slice_kind;
1705 p->v.Slice.lower = lower;
1706 p->v.Slice.upper = upper;
1707 p->v.Slice.step = step;
1708 return p;
1709}
1710
1711slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001712ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713{
1714 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001715 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001716 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001717 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001718 p->kind = ExtSlice_kind;
1719 p->v.ExtSlice.dims = dims;
1720 return p;
1721}
1722
1723slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001724Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725{
1726 slice_ty p;
1727 if (!value) {
1728 PyErr_SetString(PyExc_ValueError,
1729 "field value is required for Index");
1730 return NULL;
1731 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001732 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001733 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001734 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001735 p->kind = Index_kind;
1736 p->v.Index.value = value;
1737 return p;
1738}
1739
1740comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001741comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742{
1743 comprehension_ty p;
1744 if (!target) {
1745 PyErr_SetString(PyExc_ValueError,
1746 "field target is required for comprehension");
1747 return NULL;
1748 }
1749 if (!iter) {
1750 PyErr_SetString(PyExc_ValueError,
1751 "field iter is required for comprehension");
1752 return NULL;
1753 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001754 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001755 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757 p->target = target;
1758 p->iter = iter;
1759 p->ifs = ifs;
1760 return p;
1761}
1762
1763excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001764excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001765 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001766{
1767 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001768 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001769 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771 p->type = type;
1772 p->name = name;
1773 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001774 p->lineno = lineno;
1775 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 return p;
1777}
1778
1779arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001780arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1781 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1782 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001783{
1784 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001785 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001786 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001788 p->args = args;
1789 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001790 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001791 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001792 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001793 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001795 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001796 return p;
1797}
1798
Neal Norwitzc1505362006-12-28 06:47:50 +00001799arg_ty
1800SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1801{
1802 arg_ty p;
1803 if (!arg) {
1804 PyErr_SetString(PyExc_ValueError,
1805 "field arg is required for SimpleArg");
1806 return NULL;
1807 }
1808 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001809 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001810 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001811 p->kind = SimpleArg_kind;
1812 p->v.SimpleArg.arg = arg;
1813 p->v.SimpleArg.annotation = annotation;
1814 return p;
1815}
1816
1817arg_ty
1818NestedArgs(asdl_seq * args, PyArena *arena)
1819{
1820 arg_ty p;
1821 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001822 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001823 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001824 p->kind = NestedArgs_kind;
1825 p->v.NestedArgs.args = args;
1826 return p;
1827}
1828
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001830keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001831{
1832 keyword_ty p;
1833 if (!arg) {
1834 PyErr_SetString(PyExc_ValueError,
1835 "field arg is required for keyword");
1836 return NULL;
1837 }
1838 if (!value) {
1839 PyErr_SetString(PyExc_ValueError,
1840 "field value is required for keyword");
1841 return NULL;
1842 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001843 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001844 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 p->arg = arg;
1847 p->value = value;
1848 return p;
1849}
1850
1851alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001852alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853{
1854 alias_ty p;
1855 if (!name) {
1856 PyErr_SetString(PyExc_ValueError,
1857 "field name is required for alias");
1858 return NULL;
1859 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001860 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001861 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863 p->name = name;
1864 p->asname = asname;
1865 return p;
1866}
1867
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001868
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001869PyObject*
1870ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001871{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001872 mod_ty o = (mod_ty)_o;
1873 PyObject *result = NULL, *value = NULL;
1874 if (!o) {
1875 Py_INCREF(Py_None);
1876 return Py_None;
1877 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001878
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879 switch (o->kind) {
1880 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001881 result = PyType_GenericNew(Module_type, NULL, NULL);
1882 if (!result) goto failed;
1883 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1884 if (!value) goto failed;
1885 if (PyObject_SetAttrString(result, "body", value) == -1)
1886 goto failed;
1887 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001888 break;
1889 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001890 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1891 if (!result) goto failed;
1892 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1893 if (!value) goto failed;
1894 if (PyObject_SetAttrString(result, "body", value) == -1)
1895 goto failed;
1896 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897 break;
1898 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001899 result = PyType_GenericNew(Expression_type, NULL, NULL);
1900 if (!result) goto failed;
1901 value = ast2obj_expr(o->v.Expression.body);
1902 if (!value) goto failed;
1903 if (PyObject_SetAttrString(result, "body", value) == -1)
1904 goto failed;
1905 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906 break;
1907 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001908 result = PyType_GenericNew(Suite_type, NULL, NULL);
1909 if (!result) goto failed;
1910 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1911 if (!value) goto failed;
1912 if (PyObject_SetAttrString(result, "body", value) == -1)
1913 goto failed;
1914 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001915 break;
1916 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001917 return result;
1918failed:
1919 Py_XDECREF(value);
1920 Py_XDECREF(result);
1921 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001922}
1923
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001924PyObject*
1925ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001926{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001927 stmt_ty o = (stmt_ty)_o;
1928 PyObject *result = NULL, *value = NULL;
1929 if (!o) {
1930 Py_INCREF(Py_None);
1931 return Py_None;
1932 }
1933
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001934 switch (o->kind) {
1935 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001936 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1937 if (!result) goto failed;
1938 value = ast2obj_identifier(o->v.FunctionDef.name);
1939 if (!value) goto failed;
1940 if (PyObject_SetAttrString(result, "name", value) == -1)
1941 goto failed;
1942 Py_DECREF(value);
1943 value = ast2obj_arguments(o->v.FunctionDef.args);
1944 if (!value) goto failed;
1945 if (PyObject_SetAttrString(result, "args", value) == -1)
1946 goto failed;
1947 Py_DECREF(value);
1948 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1949 if (!value) goto failed;
1950 if (PyObject_SetAttrString(result, "body", value) == -1)
1951 goto failed;
1952 Py_DECREF(value);
1953 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1954 if (!value) goto failed;
1955 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1956 goto failed;
1957 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00001958 value = ast2obj_expr(o->v.FunctionDef.returns);
1959 if (!value) goto failed;
1960 if (PyObject_SetAttrString(result, "returns", value) == -1)
1961 goto failed;
1962 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001963 break;
1964 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001965 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1966 if (!result) goto failed;
1967 value = ast2obj_identifier(o->v.ClassDef.name);
1968 if (!value) goto failed;
1969 if (PyObject_SetAttrString(result, "name", value) == -1)
1970 goto failed;
1971 Py_DECREF(value);
1972 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1973 if (!value) goto failed;
1974 if (PyObject_SetAttrString(result, "bases", value) == -1)
1975 goto failed;
1976 Py_DECREF(value);
1977 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1978 if (!value) goto failed;
1979 if (PyObject_SetAttrString(result, "body", value) == -1)
1980 goto failed;
1981 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001982 break;
1983 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001984 result = PyType_GenericNew(Return_type, NULL, NULL);
1985 if (!result) goto failed;
1986 value = ast2obj_expr(o->v.Return.value);
1987 if (!value) goto failed;
1988 if (PyObject_SetAttrString(result, "value", value) == -1)
1989 goto failed;
1990 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001991 break;
1992 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001993 result = PyType_GenericNew(Delete_type, NULL, NULL);
1994 if (!result) goto failed;
1995 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1996 if (!value) goto failed;
1997 if (PyObject_SetAttrString(result, "targets", value) == -1)
1998 goto failed;
1999 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002000 break;
2001 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002002 result = PyType_GenericNew(Assign_type, NULL, NULL);
2003 if (!result) goto failed;
2004 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2005 if (!value) goto failed;
2006 if (PyObject_SetAttrString(result, "targets", value) == -1)
2007 goto failed;
2008 Py_DECREF(value);
2009 value = ast2obj_expr(o->v.Assign.value);
2010 if (!value) goto failed;
2011 if (PyObject_SetAttrString(result, "value", value) == -1)
2012 goto failed;
2013 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002014 break;
2015 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002016 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2017 if (!result) goto failed;
2018 value = ast2obj_expr(o->v.AugAssign.target);
2019 if (!value) goto failed;
2020 if (PyObject_SetAttrString(result, "target", value) == -1)
2021 goto failed;
2022 Py_DECREF(value);
2023 value = ast2obj_operator(o->v.AugAssign.op);
2024 if (!value) goto failed;
2025 if (PyObject_SetAttrString(result, "op", value) == -1)
2026 goto failed;
2027 Py_DECREF(value);
2028 value = ast2obj_expr(o->v.AugAssign.value);
2029 if (!value) goto failed;
2030 if (PyObject_SetAttrString(result, "value", value) == -1)
2031 goto failed;
2032 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002033 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002034 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002035 result = PyType_GenericNew(For_type, NULL, NULL);
2036 if (!result) goto failed;
2037 value = ast2obj_expr(o->v.For.target);
2038 if (!value) goto failed;
2039 if (PyObject_SetAttrString(result, "target", value) == -1)
2040 goto failed;
2041 Py_DECREF(value);
2042 value = ast2obj_expr(o->v.For.iter);
2043 if (!value) goto failed;
2044 if (PyObject_SetAttrString(result, "iter", value) == -1)
2045 goto failed;
2046 Py_DECREF(value);
2047 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2048 if (!value) goto failed;
2049 if (PyObject_SetAttrString(result, "body", value) == -1)
2050 goto failed;
2051 Py_DECREF(value);
2052 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2053 if (!value) goto failed;
2054 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2055 goto failed;
2056 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002057 break;
2058 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002059 result = PyType_GenericNew(While_type, NULL, NULL);
2060 if (!result) goto failed;
2061 value = ast2obj_expr(o->v.While.test);
2062 if (!value) goto failed;
2063 if (PyObject_SetAttrString(result, "test", value) == -1)
2064 goto failed;
2065 Py_DECREF(value);
2066 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2067 if (!value) goto failed;
2068 if (PyObject_SetAttrString(result, "body", value) == -1)
2069 goto failed;
2070 Py_DECREF(value);
2071 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2072 if (!value) goto failed;
2073 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2074 goto failed;
2075 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002076 break;
2077 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002078 result = PyType_GenericNew(If_type, NULL, NULL);
2079 if (!result) goto failed;
2080 value = ast2obj_expr(o->v.If.test);
2081 if (!value) goto failed;
2082 if (PyObject_SetAttrString(result, "test", value) == -1)
2083 goto failed;
2084 Py_DECREF(value);
2085 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2086 if (!value) goto failed;
2087 if (PyObject_SetAttrString(result, "body", value) == -1)
2088 goto failed;
2089 Py_DECREF(value);
2090 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2091 if (!value) goto failed;
2092 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2093 goto failed;
2094 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002095 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002096 case With_kind:
2097 result = PyType_GenericNew(With_type, NULL, NULL);
2098 if (!result) goto failed;
2099 value = ast2obj_expr(o->v.With.context_expr);
2100 if (!value) goto failed;
2101 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2102 goto failed;
2103 Py_DECREF(value);
2104 value = ast2obj_expr(o->v.With.optional_vars);
2105 if (!value) goto failed;
2106 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2107 -1)
2108 goto failed;
2109 Py_DECREF(value);
2110 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2111 if (!value) goto failed;
2112 if (PyObject_SetAttrString(result, "body", value) == -1)
2113 goto failed;
2114 Py_DECREF(value);
2115 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002116 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002117 result = PyType_GenericNew(Raise_type, NULL, NULL);
2118 if (!result) goto failed;
2119 value = ast2obj_expr(o->v.Raise.type);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "type", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 value = ast2obj_expr(o->v.Raise.inst);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "inst", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_expr(o->v.Raise.tback);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "tback", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002134 break;
2135 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002136 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2137 if (!result) goto failed;
2138 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "body", value) == -1)
2141 goto failed;
2142 Py_DECREF(value);
2143 value = ast2obj_list(o->v.TryExcept.handlers,
2144 ast2obj_excepthandler);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002154 break;
2155 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002156 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2157 if (!result) goto failed;
2158 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "body", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
2163 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002168 break;
2169 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002170 result = PyType_GenericNew(Assert_type, NULL, NULL);
2171 if (!result) goto failed;
2172 value = ast2obj_expr(o->v.Assert.test);
2173 if (!value) goto failed;
2174 if (PyObject_SetAttrString(result, "test", value) == -1)
2175 goto failed;
2176 Py_DECREF(value);
2177 value = ast2obj_expr(o->v.Assert.msg);
2178 if (!value) goto failed;
2179 if (PyObject_SetAttrString(result, "msg", value) == -1)
2180 goto failed;
2181 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182 break;
2183 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002184 result = PyType_GenericNew(Import_type, NULL, NULL);
2185 if (!result) goto failed;
2186 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2187 if (!value) goto failed;
2188 if (PyObject_SetAttrString(result, "names", value) == -1)
2189 goto failed;
2190 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002191 break;
2192 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002193 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2194 if (!result) goto failed;
2195 value = ast2obj_identifier(o->v.ImportFrom.module);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "module", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
2200 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2201 if (!value) goto failed;
2202 if (PyObject_SetAttrString(result, "names", value) == -1)
2203 goto failed;
2204 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002205 value = ast2obj_int(o->v.ImportFrom.level);
2206 if (!value) goto failed;
2207 if (PyObject_SetAttrString(result, "level", value) == -1)
2208 goto failed;
2209 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002210 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002211 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002212 result = PyType_GenericNew(Global_type, NULL, NULL);
2213 if (!result) goto failed;
2214 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2215 if (!value) goto failed;
2216 if (PyObject_SetAttrString(result, "names", value) == -1)
2217 goto failed;
2218 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002219 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002220 case Nonlocal_kind:
2221 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2222 if (!result) goto failed;
2223 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2224 if (!value) goto failed;
2225 if (PyObject_SetAttrString(result, "names", value) == -1)
2226 goto failed;
2227 Py_DECREF(value);
2228 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002229 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002230 result = PyType_GenericNew(Expr_type, NULL, NULL);
2231 if (!result) goto failed;
2232 value = ast2obj_expr(o->v.Expr.value);
2233 if (!value) goto failed;
2234 if (PyObject_SetAttrString(result, "value", value) == -1)
2235 goto failed;
2236 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002237 break;
2238 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002239 result = PyType_GenericNew(Pass_type, NULL, NULL);
2240 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241 break;
2242 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002243 result = PyType_GenericNew(Break_type, NULL, NULL);
2244 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002245 break;
2246 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002247 result = PyType_GenericNew(Continue_type, NULL, NULL);
2248 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002249 break;
2250 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002251 value = ast2obj_int(o->lineno);
2252 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002253 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2254 goto failed;
2255 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002256 value = ast2obj_int(o->col_offset);
2257 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002258 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2259 goto failed;
2260 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002261 return result;
2262failed:
2263 Py_XDECREF(value);
2264 Py_XDECREF(result);
2265 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002266}
2267
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002268PyObject*
2269ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002270{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002271 expr_ty o = (expr_ty)_o;
2272 PyObject *result = NULL, *value = NULL;
2273 if (!o) {
2274 Py_INCREF(Py_None);
2275 return Py_None;
2276 }
2277
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002278 switch (o->kind) {
2279 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002280 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2281 if (!result) goto failed;
2282 value = ast2obj_boolop(o->v.BoolOp.op);
2283 if (!value) goto failed;
2284 if (PyObject_SetAttrString(result, "op", value) == -1)
2285 goto failed;
2286 Py_DECREF(value);
2287 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2288 if (!value) goto failed;
2289 if (PyObject_SetAttrString(result, "values", value) == -1)
2290 goto failed;
2291 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002292 break;
2293 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002294 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2295 if (!result) goto failed;
2296 value = ast2obj_expr(o->v.BinOp.left);
2297 if (!value) goto failed;
2298 if (PyObject_SetAttrString(result, "left", value) == -1)
2299 goto failed;
2300 Py_DECREF(value);
2301 value = ast2obj_operator(o->v.BinOp.op);
2302 if (!value) goto failed;
2303 if (PyObject_SetAttrString(result, "op", value) == -1)
2304 goto failed;
2305 Py_DECREF(value);
2306 value = ast2obj_expr(o->v.BinOp.right);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "right", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002311 break;
2312 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002313 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2314 if (!result) goto failed;
2315 value = ast2obj_unaryop(o->v.UnaryOp.op);
2316 if (!value) goto failed;
2317 if (PyObject_SetAttrString(result, "op", value) == -1)
2318 goto failed;
2319 Py_DECREF(value);
2320 value = ast2obj_expr(o->v.UnaryOp.operand);
2321 if (!value) goto failed;
2322 if (PyObject_SetAttrString(result, "operand", value) == -1)
2323 goto failed;
2324 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325 break;
2326 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002327 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2328 if (!result) goto failed;
2329 value = ast2obj_arguments(o->v.Lambda.args);
2330 if (!value) goto failed;
2331 if (PyObject_SetAttrString(result, "args", value) == -1)
2332 goto failed;
2333 Py_DECREF(value);
2334 value = ast2obj_expr(o->v.Lambda.body);
2335 if (!value) goto failed;
2336 if (PyObject_SetAttrString(result, "body", value) == -1)
2337 goto failed;
2338 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002339 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002340 case IfExp_kind:
2341 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2342 if (!result) goto failed;
2343 value = ast2obj_expr(o->v.IfExp.test);
2344 if (!value) goto failed;
2345 if (PyObject_SetAttrString(result, "test", value) == -1)
2346 goto failed;
2347 Py_DECREF(value);
2348 value = ast2obj_expr(o->v.IfExp.body);
2349 if (!value) goto failed;
2350 if (PyObject_SetAttrString(result, "body", value) == -1)
2351 goto failed;
2352 Py_DECREF(value);
2353 value = ast2obj_expr(o->v.IfExp.orelse);
2354 if (!value) goto failed;
2355 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2356 goto failed;
2357 Py_DECREF(value);
2358 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002359 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002360 result = PyType_GenericNew(Dict_type, NULL, NULL);
2361 if (!result) goto failed;
2362 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2363 if (!value) goto failed;
2364 if (PyObject_SetAttrString(result, "keys", value) == -1)
2365 goto failed;
2366 Py_DECREF(value);
2367 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2368 if (!value) goto failed;
2369 if (PyObject_SetAttrString(result, "values", value) == -1)
2370 goto failed;
2371 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002372 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002373 case Set_kind:
2374 result = PyType_GenericNew(Set_type, NULL, NULL);
2375 if (!result) goto failed;
2376 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2377 if (!value) goto failed;
2378 if (PyObject_SetAttrString(result, "elts", value) == -1)
2379 goto failed;
2380 Py_DECREF(value);
2381 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002382 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002383 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2384 if (!result) goto failed;
2385 value = ast2obj_expr(o->v.ListComp.elt);
2386 if (!value) goto failed;
2387 if (PyObject_SetAttrString(result, "elt", value) == -1)
2388 goto failed;
2389 Py_DECREF(value);
2390 value = ast2obj_list(o->v.ListComp.generators,
2391 ast2obj_comprehension);
2392 if (!value) goto failed;
2393 if (PyObject_SetAttrString(result, "generators", value) == -1)
2394 goto failed;
2395 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002396 break;
2397 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002398 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2399 if (!result) goto failed;
2400 value = ast2obj_expr(o->v.GeneratorExp.elt);
2401 if (!value) goto failed;
2402 if (PyObject_SetAttrString(result, "elt", value) == -1)
2403 goto failed;
2404 Py_DECREF(value);
2405 value = ast2obj_list(o->v.GeneratorExp.generators,
2406 ast2obj_comprehension);
2407 if (!value) goto failed;
2408 if (PyObject_SetAttrString(result, "generators", value) == -1)
2409 goto failed;
2410 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002411 break;
2412 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002413 result = PyType_GenericNew(Yield_type, NULL, NULL);
2414 if (!result) goto failed;
2415 value = ast2obj_expr(o->v.Yield.value);
2416 if (!value) goto failed;
2417 if (PyObject_SetAttrString(result, "value", value) == -1)
2418 goto failed;
2419 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002420 break;
2421 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002422 result = PyType_GenericNew(Compare_type, NULL, NULL);
2423 if (!result) goto failed;
2424 value = ast2obj_expr(o->v.Compare.left);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "left", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002429 {
2430 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2431 value = PyList_New(n);
2432 if (!value) goto failed;
2433 for(i = 0; i < n; i++)
2434 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2435 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "ops", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002445 break;
2446 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002447 result = PyType_GenericNew(Call_type, NULL, NULL);
2448 if (!result) goto failed;
2449 value = ast2obj_expr(o->v.Call.func);
2450 if (!value) goto failed;
2451 if (PyObject_SetAttrString(result, "func", value) == -1)
2452 goto failed;
2453 Py_DECREF(value);
2454 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2455 if (!value) goto failed;
2456 if (PyObject_SetAttrString(result, "args", value) == -1)
2457 goto failed;
2458 Py_DECREF(value);
2459 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2460 if (!value) goto failed;
2461 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2462 goto failed;
2463 Py_DECREF(value);
2464 value = ast2obj_expr(o->v.Call.starargs);
2465 if (!value) goto failed;
2466 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2467 goto failed;
2468 Py_DECREF(value);
2469 value = ast2obj_expr(o->v.Call.kwargs);
2470 if (!value) goto failed;
2471 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2472 goto failed;
2473 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002474 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002475 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002476 result = PyType_GenericNew(Num_type, NULL, NULL);
2477 if (!result) goto failed;
2478 value = ast2obj_object(o->v.Num.n);
2479 if (!value) goto failed;
2480 if (PyObject_SetAttrString(result, "n", value) == -1)
2481 goto failed;
2482 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002483 break;
2484 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002485 result = PyType_GenericNew(Str_type, NULL, NULL);
2486 if (!result) goto failed;
2487 value = ast2obj_string(o->v.Str.s);
2488 if (!value) goto failed;
2489 if (PyObject_SetAttrString(result, "s", value) == -1)
2490 goto failed;
2491 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002492 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002493 case Bytes_kind:
2494 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2495 if (!result) goto failed;
2496 value = ast2obj_string(o->v.Bytes.s);
2497 if (!value) goto failed;
2498 if (PyObject_SetAttrString(result, "s", value) == -1)
2499 goto failed;
2500 Py_DECREF(value);
2501 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002502 case Ellipsis_kind:
2503 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2504 if (!result) goto failed;
2505 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002506 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_expr(o->v.Attribute.value);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "value", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
2514 value = ast2obj_identifier(o->v.Attribute.attr);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "attr", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_expr_context(o->v.Attribute.ctx);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002524 break;
2525 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002526 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2527 if (!result) goto failed;
2528 value = ast2obj_expr(o->v.Subscript.value);
2529 if (!value) goto failed;
2530 if (PyObject_SetAttrString(result, "value", value) == -1)
2531 goto failed;
2532 Py_DECREF(value);
2533 value = ast2obj_slice(o->v.Subscript.slice);
2534 if (!value) goto failed;
2535 if (PyObject_SetAttrString(result, "slice", value) == -1)
2536 goto failed;
2537 Py_DECREF(value);
2538 value = ast2obj_expr_context(o->v.Subscript.ctx);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002543 break;
2544 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002545 result = PyType_GenericNew(Name_type, NULL, NULL);
2546 if (!result) goto failed;
2547 value = ast2obj_identifier(o->v.Name.id);
2548 if (!value) goto failed;
2549 if (PyObject_SetAttrString(result, "id", value) == -1)
2550 goto failed;
2551 Py_DECREF(value);
2552 value = ast2obj_expr_context(o->v.Name.ctx);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557 break;
2558 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002559 result = PyType_GenericNew(List_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "elts", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
2566 value = ast2obj_expr_context(o->v.List.ctx);
2567 if (!value) goto failed;
2568 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2569 goto failed;
2570 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002571 break;
2572 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002573 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2574 if (!result) goto failed;
2575 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "elts", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_expr_context(o->v.Tuple.ctx);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002585 break;
2586 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002587 value = ast2obj_int(o->lineno);
2588 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002589 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2590 goto failed;
2591 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002592 value = ast2obj_int(o->col_offset);
2593 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002594 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2595 goto failed;
2596 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002597 return result;
2598failed:
2599 Py_XDECREF(value);
2600 Py_XDECREF(result);
2601 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002602}
2603
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002604PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002605{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002606 switch(o) {
2607 case Load:
2608 Py_INCREF(Load_singleton);
2609 return Load_singleton;
2610 case Store:
2611 Py_INCREF(Store_singleton);
2612 return Store_singleton;
2613 case Del:
2614 Py_INCREF(Del_singleton);
2615 return Del_singleton;
2616 case AugLoad:
2617 Py_INCREF(AugLoad_singleton);
2618 return AugLoad_singleton;
2619 case AugStore:
2620 Py_INCREF(AugStore_singleton);
2621 return AugStore_singleton;
2622 case Param:
2623 Py_INCREF(Param_singleton);
2624 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002625 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002626 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002627}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002628PyObject*
2629ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002630{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002631 slice_ty o = (slice_ty)_o;
2632 PyObject *result = NULL, *value = NULL;
2633 if (!o) {
2634 Py_INCREF(Py_None);
2635 return Py_None;
2636 }
2637
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002638 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002639 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002640 result = PyType_GenericNew(Slice_type, NULL, NULL);
2641 if (!result) goto failed;
2642 value = ast2obj_expr(o->v.Slice.lower);
2643 if (!value) goto failed;
2644 if (PyObject_SetAttrString(result, "lower", value) == -1)
2645 goto failed;
2646 Py_DECREF(value);
2647 value = ast2obj_expr(o->v.Slice.upper);
2648 if (!value) goto failed;
2649 if (PyObject_SetAttrString(result, "upper", value) == -1)
2650 goto failed;
2651 Py_DECREF(value);
2652 value = ast2obj_expr(o->v.Slice.step);
2653 if (!value) goto failed;
2654 if (PyObject_SetAttrString(result, "step", value) == -1)
2655 goto failed;
2656 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002657 break;
2658 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002659 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2660 if (!result) goto failed;
2661 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2662 if (!value) goto failed;
2663 if (PyObject_SetAttrString(result, "dims", value) == -1)
2664 goto failed;
2665 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002666 break;
2667 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002668 result = PyType_GenericNew(Index_type, NULL, NULL);
2669 if (!result) goto failed;
2670 value = ast2obj_expr(o->v.Index.value);
2671 if (!value) goto failed;
2672 if (PyObject_SetAttrString(result, "value", value) == -1)
2673 goto failed;
2674 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002675 break;
2676 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002677 return result;
2678failed:
2679 Py_XDECREF(value);
2680 Py_XDECREF(result);
2681 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682}
2683
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002684PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002685{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002686 switch(o) {
2687 case And:
2688 Py_INCREF(And_singleton);
2689 return And_singleton;
2690 case Or:
2691 Py_INCREF(Or_singleton);
2692 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 return NULL; /* cannot happen */
2695}
2696PyObject* ast2obj_operator(operator_ty o)
2697{
2698 switch(o) {
2699 case Add:
2700 Py_INCREF(Add_singleton);
2701 return Add_singleton;
2702 case Sub:
2703 Py_INCREF(Sub_singleton);
2704 return Sub_singleton;
2705 case Mult:
2706 Py_INCREF(Mult_singleton);
2707 return Mult_singleton;
2708 case Div:
2709 Py_INCREF(Div_singleton);
2710 return Div_singleton;
2711 case Mod:
2712 Py_INCREF(Mod_singleton);
2713 return Mod_singleton;
2714 case Pow:
2715 Py_INCREF(Pow_singleton);
2716 return Pow_singleton;
2717 case LShift:
2718 Py_INCREF(LShift_singleton);
2719 return LShift_singleton;
2720 case RShift:
2721 Py_INCREF(RShift_singleton);
2722 return RShift_singleton;
2723 case BitOr:
2724 Py_INCREF(BitOr_singleton);
2725 return BitOr_singleton;
2726 case BitXor:
2727 Py_INCREF(BitXor_singleton);
2728 return BitXor_singleton;
2729 case BitAnd:
2730 Py_INCREF(BitAnd_singleton);
2731 return BitAnd_singleton;
2732 case FloorDiv:
2733 Py_INCREF(FloorDiv_singleton);
2734 return FloorDiv_singleton;
2735 }
2736 return NULL; /* cannot happen */
2737}
2738PyObject* ast2obj_unaryop(unaryop_ty o)
2739{
2740 switch(o) {
2741 case Invert:
2742 Py_INCREF(Invert_singleton);
2743 return Invert_singleton;
2744 case Not:
2745 Py_INCREF(Not_singleton);
2746 return Not_singleton;
2747 case UAdd:
2748 Py_INCREF(UAdd_singleton);
2749 return UAdd_singleton;
2750 case USub:
2751 Py_INCREF(USub_singleton);
2752 return USub_singleton;
2753 }
2754 return NULL; /* cannot happen */
2755}
2756PyObject* ast2obj_cmpop(cmpop_ty o)
2757{
2758 switch(o) {
2759 case Eq:
2760 Py_INCREF(Eq_singleton);
2761 return Eq_singleton;
2762 case NotEq:
2763 Py_INCREF(NotEq_singleton);
2764 return NotEq_singleton;
2765 case Lt:
2766 Py_INCREF(Lt_singleton);
2767 return Lt_singleton;
2768 case LtE:
2769 Py_INCREF(LtE_singleton);
2770 return LtE_singleton;
2771 case Gt:
2772 Py_INCREF(Gt_singleton);
2773 return Gt_singleton;
2774 case GtE:
2775 Py_INCREF(GtE_singleton);
2776 return GtE_singleton;
2777 case Is:
2778 Py_INCREF(Is_singleton);
2779 return Is_singleton;
2780 case IsNot:
2781 Py_INCREF(IsNot_singleton);
2782 return IsNot_singleton;
2783 case In:
2784 Py_INCREF(In_singleton);
2785 return In_singleton;
2786 case NotIn:
2787 Py_INCREF(NotIn_singleton);
2788 return NotIn_singleton;
2789 }
2790 return NULL; /* cannot happen */
2791}
2792PyObject*
2793ast2obj_comprehension(void* _o)
2794{
2795 comprehension_ty o = (comprehension_ty)_o;
2796 PyObject *result = NULL, *value = NULL;
2797 if (!o) {
2798 Py_INCREF(Py_None);
2799 return Py_None;
2800 }
2801
2802 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2803 if (!result) return NULL;
2804 value = ast2obj_expr(o->target);
2805 if (!value) goto failed;
2806 if (PyObject_SetAttrString(result, "target", value) == -1)
2807 goto failed;
2808 Py_DECREF(value);
2809 value = ast2obj_expr(o->iter);
2810 if (!value) goto failed;
2811 if (PyObject_SetAttrString(result, "iter", value) == -1)
2812 goto failed;
2813 Py_DECREF(value);
2814 value = ast2obj_list(o->ifs, ast2obj_expr);
2815 if (!value) goto failed;
2816 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2817 goto failed;
2818 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002819 return result;
2820failed:
2821 Py_XDECREF(value);
2822 Py_XDECREF(result);
2823 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002824}
2825
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002826PyObject*
2827ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002828{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002829 excepthandler_ty o = (excepthandler_ty)_o;
2830 PyObject *result = NULL, *value = NULL;
2831 if (!o) {
2832 Py_INCREF(Py_None);
2833 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002834 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002835
2836 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2837 if (!result) return NULL;
2838 value = ast2obj_expr(o->type);
2839 if (!value) goto failed;
2840 if (PyObject_SetAttrString(result, "type", value) == -1)
2841 goto failed;
2842 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002843 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002844 if (!value) goto failed;
2845 if (PyObject_SetAttrString(result, "name", value) == -1)
2846 goto failed;
2847 Py_DECREF(value);
2848 value = ast2obj_list(o->body, ast2obj_stmt);
2849 if (!value) goto failed;
2850 if (PyObject_SetAttrString(result, "body", value) == -1)
2851 goto failed;
2852 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002853 value = ast2obj_int(o->lineno);
2854 if (!value) goto failed;
2855 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2856 goto failed;
2857 Py_DECREF(value);
2858 value = ast2obj_int(o->col_offset);
2859 if (!value) goto failed;
2860 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2861 goto failed;
2862 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002863 return result;
2864failed:
2865 Py_XDECREF(value);
2866 Py_XDECREF(result);
2867 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002868}
2869
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002870PyObject*
2871ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002872{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002873 arguments_ty o = (arguments_ty)_o;
2874 PyObject *result = NULL, *value = NULL;
2875 if (!o) {
2876 Py_INCREF(Py_None);
2877 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002878 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002879
2880 result = PyType_GenericNew(arguments_type, NULL, NULL);
2881 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002882 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002883 if (!value) goto failed;
2884 if (PyObject_SetAttrString(result, "args", value) == -1)
2885 goto failed;
2886 Py_DECREF(value);
2887 value = ast2obj_identifier(o->vararg);
2888 if (!value) goto failed;
2889 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2890 goto failed;
2891 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002892 value = ast2obj_expr(o->varargannotation);
2893 if (!value) goto failed;
2894 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2895 goto failed;
2896 Py_DECREF(value);
2897 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002898 if (!value) goto failed;
2899 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2900 goto failed;
2901 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002902 value = ast2obj_identifier(o->kwarg);
2903 if (!value) goto failed;
2904 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2905 goto failed;
2906 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002907 value = ast2obj_expr(o->kwargannotation);
2908 if (!value) goto failed;
2909 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2910 goto failed;
2911 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002912 value = ast2obj_list(o->defaults, ast2obj_expr);
2913 if (!value) goto failed;
2914 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2915 goto failed;
2916 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002917 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2918 if (!value) goto failed;
2919 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2920 goto failed;
2921 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002922 return result;
2923failed:
2924 Py_XDECREF(value);
2925 Py_XDECREF(result);
2926 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002927}
2928
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002929PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002930ast2obj_arg(void* _o)
2931{
2932 arg_ty o = (arg_ty)_o;
2933 PyObject *result = NULL, *value = NULL;
2934 if (!o) {
2935 Py_INCREF(Py_None);
2936 return Py_None;
2937 }
2938
2939 switch (o->kind) {
2940 case SimpleArg_kind:
2941 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2942 if (!result) goto failed;
2943 value = ast2obj_identifier(o->v.SimpleArg.arg);
2944 if (!value) goto failed;
2945 if (PyObject_SetAttrString(result, "arg", value) == -1)
2946 goto failed;
2947 Py_DECREF(value);
2948 value = ast2obj_expr(o->v.SimpleArg.annotation);
2949 if (!value) goto failed;
2950 if (PyObject_SetAttrString(result, "annotation", value) == -1)
2951 goto failed;
2952 Py_DECREF(value);
2953 break;
2954 case NestedArgs_kind:
2955 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
2956 if (!result) goto failed;
2957 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
2958 if (!value) goto failed;
2959 if (PyObject_SetAttrString(result, "args", value) == -1)
2960 goto failed;
2961 Py_DECREF(value);
2962 break;
2963 }
2964 return result;
2965failed:
2966 Py_XDECREF(value);
2967 Py_XDECREF(result);
2968 return NULL;
2969}
2970
2971PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002972ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002973{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002974 keyword_ty o = (keyword_ty)_o;
2975 PyObject *result = NULL, *value = NULL;
2976 if (!o) {
2977 Py_INCREF(Py_None);
2978 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002979 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002980
2981 result = PyType_GenericNew(keyword_type, NULL, NULL);
2982 if (!result) return NULL;
2983 value = ast2obj_identifier(o->arg);
2984 if (!value) goto failed;
2985 if (PyObject_SetAttrString(result, "arg", value) == -1)
2986 goto failed;
2987 Py_DECREF(value);
2988 value = ast2obj_expr(o->value);
2989 if (!value) goto failed;
2990 if (PyObject_SetAttrString(result, "value", value) == -1)
2991 goto failed;
2992 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002993 return result;
2994failed:
2995 Py_XDECREF(value);
2996 Py_XDECREF(result);
2997 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002998}
2999
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003000PyObject*
3001ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003002{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003003 alias_ty o = (alias_ty)_o;
3004 PyObject *result = NULL, *value = NULL;
3005 if (!o) {
3006 Py_INCREF(Py_None);
3007 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003008 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003009
3010 result = PyType_GenericNew(alias_type, NULL, NULL);
3011 if (!result) return NULL;
3012 value = ast2obj_identifier(o->name);
3013 if (!value) goto failed;
3014 if (PyObject_SetAttrString(result, "name", value) == -1)
3015 goto failed;
3016 Py_DECREF(value);
3017 value = ast2obj_identifier(o->asname);
3018 if (!value) goto failed;
3019 if (PyObject_SetAttrString(result, "asname", value) == -1)
3020 goto failed;
3021 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003022 return result;
3023failed:
3024 Py_XDECREF(value);
3025 Py_XDECREF(result);
3026 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003027}
3028
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003029
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003030PyMODINIT_FUNC
3031init_ast(void)
3032{
3033 PyObject *m, *d;
3034 if (!init_types()) return;
3035 m = Py_InitModule3("_ast", NULL, NULL);
3036 if (!m) return;
3037 d = PyModule_GetDict(m);
3038 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3039 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3040 return;
Brett Cannon5b198e82007-02-27 20:16:01 +00003041 if (PyModule_AddStringConstant(m, "__version__", "53986") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003042 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003043 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3044 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3045 return;
3046 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3047 < 0) return;
3048 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3049 0) return;
3050 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3051 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3052 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3053 < 0) return;
3054 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3055 return;
3056 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3057 return;
3058 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3059 return;
3060 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3061 return;
3062 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3063 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003064 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3065 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3066 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3067 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3068 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3069 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3070 0) return;
3071 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3072 0) return;
3073 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3074 return;
3075 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3076 return;
3077 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3078 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003079 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3080 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003081 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3082 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003083 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3084 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3085 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3086 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3087 return;
3088 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3089 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3090 return;
3091 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3092 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3093 return;
3094 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3095 return;
3096 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3097 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003098 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003099 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3100 return;
3101 if (PyDict_SetItemString(d, "GeneratorExp",
3102 (PyObject*)GeneratorExp_type) < 0) return;
3103 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3104 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3105 return;
3106 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003107 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3108 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003109 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003110 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3111 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003112 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3113 0) return;
3114 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3115 0) return;
3116 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3117 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3118 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3119 if (PyDict_SetItemString(d, "expr_context",
3120 (PyObject*)expr_context_type) < 0) return;
3121 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3122 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3123 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3124 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3125 return;
3126 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3129 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003130 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3131 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3132 return;
3133 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3134 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3135 return;
3136 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3138 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3139 return;
3140 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3141 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3142 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3143 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3144 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3145 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3146 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3147 return;
3148 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3149 return;
3150 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3151 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3152 return;
3153 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3154 return;
3155 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3156 return;
3157 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3158 return;
3159 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3160 return;
3161 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3162 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3163 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3164 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3165 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3166 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3167 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3168 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3169 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3170 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3172 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3173 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3174 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3175 if (PyDict_SetItemString(d, "comprehension",
3176 (PyObject*)comprehension_type) < 0) return;
3177 if (PyDict_SetItemString(d, "excepthandler",
3178 (PyObject*)excepthandler_type) < 0) return;
3179 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3180 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003181 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3182 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3183 0) return;
3184 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3185 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003186 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3187 return;
3188 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003189}
3190
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003191
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003192PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003193{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003194 init_types();
3195 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003196}
3197
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003198