blob: e57b6a9ac81b686401283e963fdf892a4be0e14d [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum8981ad02007-04-16 17:02:00 +00005 __version__ 54835.
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",
Guido van Rossum52cc1d82007-03-18 15:41:51 +000052 "keywords",
53 "starargs",
54 "kwargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000055 "body",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *Return_type;
58static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "value",
60};
Neal Norwitz53d960c2006-02-28 22:47:29 +000061static PyTypeObject *Delete_type;
62static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000063 "targets",
64};
Neal Norwitz53d960c2006-02-28 22:47:29 +000065static PyTypeObject *Assign_type;
66static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000067 "targets",
68 "value",
69};
Neal Norwitz53d960c2006-02-28 22:47:29 +000070static PyTypeObject *AugAssign_type;
71static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000072 "target",
73 "op",
74 "value",
75};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *For_type;
77static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000078 "target",
79 "iter",
80 "body",
81 "orelse",
82};
Neal Norwitz53d960c2006-02-28 22:47:29 +000083static PyTypeObject *While_type;
84static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000085 "test",
86 "body",
87 "orelse",
88};
Neal Norwitz53d960c2006-02-28 22:47:29 +000089static PyTypeObject *If_type;
90static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000091 "test",
92 "body",
93 "orelse",
94};
Neal Norwitz53d960c2006-02-28 22:47:29 +000095static PyTypeObject *With_type;
96static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000097 "context_expr",
98 "optional_vars",
99 "body",
100};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000101static PyTypeObject *Raise_type;
102static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000103 "type",
104 "inst",
105 "tback",
106};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000107static PyTypeObject *TryExcept_type;
108static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000109 "body",
110 "handlers",
111 "orelse",
112};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000113static PyTypeObject *TryFinally_type;
114static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000115 "body",
116 "finalbody",
117};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000118static PyTypeObject *Assert_type;
119static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000120 "test",
121 "msg",
122};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000123static PyTypeObject *Import_type;
124static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000125 "names",
126};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000127static PyTypeObject *ImportFrom_type;
128static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000129 "module",
130 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000131 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000132};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000133static PyTypeObject *Global_type;
134static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000135 "names",
136};
Jeremy Hylton81e95022007-02-27 06:50:52 +0000137static PyTypeObject *Nonlocal_type;
138static char *Nonlocal_fields[]={
139 "names",
140};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000141static PyTypeObject *Expr_type;
142static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000143 "value",
144};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000145static PyTypeObject *Pass_type;
146static PyTypeObject *Break_type;
147static PyTypeObject *Continue_type;
148static PyTypeObject *expr_type;
149static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000150 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000151 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000152};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000153static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *BoolOp_type;
155static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "op",
157 "values",
158};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000159static PyTypeObject *BinOp_type;
160static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000161 "left",
162 "op",
163 "right",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *UnaryOp_type;
166static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "op",
168 "operand",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *Lambda_type;
171static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000172 "args",
173 "body",
174};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000175static PyTypeObject *IfExp_type;
176static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000177 "test",
178 "body",
179 "orelse",
180};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000181static PyTypeObject *Dict_type;
182static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000183 "keys",
184 "values",
185};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000186static PyTypeObject *Set_type;
187static char *Set_fields[]={
188 "elts",
189};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000190static PyTypeObject *ListComp_type;
191static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000192 "elt",
193 "generators",
194};
Nick Coghlan650f0d02007-04-15 12:05:43 +0000195static PyTypeObject *SetComp_type;
196static char *SetComp_fields[]={
197 "elt",
198 "generators",
199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *GeneratorExp_type;
201static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000202 "elt",
203 "generators",
204};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000205static PyTypeObject *Yield_type;
206static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000207 "value",
208};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000209static PyTypeObject *Compare_type;
210static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000211 "left",
212 "ops",
213 "comparators",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Call_type;
216static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "func",
218 "args",
219 "keywords",
220 "starargs",
221 "kwargs",
222};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000223static PyTypeObject *Num_type;
224static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000225 "n",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Str_type;
228static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "s",
230};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000231static PyTypeObject *Bytes_type;
232static char *Bytes_fields[]={
233 "s",
234};
Georg Brandl52318d62006-09-06 07:06:08 +0000235static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000236static PyTypeObject *Attribute_type;
237static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000238 "value",
239 "attr",
240 "ctx",
241};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Subscript_type;
243static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244 "value",
245 "slice",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *Name_type;
249static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000250 "id",
251 "ctx",
252};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000253static PyTypeObject *List_type;
254static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255 "elts",
256 "ctx",
257};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000258static PyTypeObject *Tuple_type;
259static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000260 "elts",
261 "ctx",
262};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000263static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000264static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
265*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
266static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *Load_type;
268static PyTypeObject *Store_type;
269static PyTypeObject *Del_type;
270static PyTypeObject *AugLoad_type;
271static PyTypeObject *AugStore_type;
272static PyTypeObject *Param_type;
273static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000274static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *Slice_type;
276static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000277 "lower",
278 "upper",
279 "step",
280};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000281static PyTypeObject *ExtSlice_type;
282static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000283 "dims",
284};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000285static PyTypeObject *Index_type;
286static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000287 "value",
288};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000289static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000290static PyObject *And_singleton, *Or_singleton;
291static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000292static PyTypeObject *And_type;
293static PyTypeObject *Or_type;
294static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
296*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
297*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
298*FloorDiv_singleton;
299static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000300static PyTypeObject *Add_type;
301static PyTypeObject *Sub_type;
302static PyTypeObject *Mult_type;
303static PyTypeObject *Div_type;
304static PyTypeObject *Mod_type;
305static PyTypeObject *Pow_type;
306static PyTypeObject *LShift_type;
307static PyTypeObject *RShift_type;
308static PyTypeObject *BitOr_type;
309static PyTypeObject *BitXor_type;
310static PyTypeObject *BitAnd_type;
311static PyTypeObject *FloorDiv_type;
312static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000313static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
314*USub_singleton;
315static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000316static PyTypeObject *Invert_type;
317static PyTypeObject *Not_type;
318static PyTypeObject *UAdd_type;
319static PyTypeObject *USub_type;
320static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000321static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
322*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
323*NotIn_singleton;
324static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000325static PyTypeObject *Eq_type;
326static PyTypeObject *NotEq_type;
327static PyTypeObject *Lt_type;
328static PyTypeObject *LtE_type;
329static PyTypeObject *Gt_type;
330static PyTypeObject *GtE_type;
331static PyTypeObject *Is_type;
332static PyTypeObject *IsNot_type;
333static PyTypeObject *In_type;
334static PyTypeObject *NotIn_type;
335static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338 "target",
339 "iter",
340 "ifs",
341};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000342static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000343static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000344static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000345 "type",
346 "name",
347 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000348 "lineno",
349 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000351static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000353static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000354 "args",
355 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000356 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000357 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000358 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000359 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000360 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000361 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000362};
Neal Norwitzc1505362006-12-28 06:47:50 +0000363static PyTypeObject *arg_type;
364static PyObject* ast2obj_arg(void*);
365static PyTypeObject *SimpleArg_type;
366static char *SimpleArg_fields[]={
367 "arg",
368 "annotation",
369};
370static PyTypeObject *NestedArgs_type;
371static char *NestedArgs_fields[]={
372 "args",
373};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000374static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000375static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000376static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000377 "arg",
378 "value",
379};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000380static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000381static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000382static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000383 "name",
384 "asname",
385};
386
387
388static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
389{
390 PyObject *fnames, *result;
391 int i;
392 if (num_fields) {
393 fnames = PyTuple_New(num_fields);
394 if (!fnames) return NULL;
395 } else {
396 fnames = Py_None;
397 Py_INCREF(Py_None);
398 }
399 for(i=0; i < num_fields; i++) {
400 PyObject *field = PyString_FromString(fields[i]);
401 if (!field) {
402 Py_DECREF(fnames);
403 return NULL;
404 }
405 PyTuple_SET_ITEM(fnames, i, field);
406 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000407 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000408 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000409 Py_DECREF(fnames);
410 return (PyTypeObject*)result;
411}
412
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000413static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
414{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000415 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000416 PyObject *s, *l = PyList_New(num_fields);
417 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000418 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000419 s = PyString_FromString(attrs[i]);
420 if (!s) {
421 Py_DECREF(l);
422 return 0;
423 }
424 PyList_SET_ITEM(l, i, s);
425 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000426 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
427 Py_DECREF(l);
428 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000429}
430
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000431static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
432{
433 int i, n = asdl_seq_LEN(seq);
434 PyObject *result = PyList_New(n);
435 PyObject *value;
436 if (!result)
437 return NULL;
438 for (i = 0; i < n; i++) {
439 value = func(asdl_seq_GET(seq, i));
440 if (!value) {
441 Py_DECREF(result);
442 return NULL;
443 }
444 PyList_SET_ITEM(result, i, value);
445 }
446 return result;
447}
448
449static PyObject* ast2obj_object(void *o)
450{
451 if (!o)
452 o = Py_None;
453 Py_INCREF((PyObject*)o);
454 return (PyObject*)o;
455}
456#define ast2obj_identifier ast2obj_object
457#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000458
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000459static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460{
461 return PyInt_FromLong(b);
462}
463
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464static int init_types(void)
465{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000466 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
469 mod_type = make_type("mod", AST_type, NULL, 0);
470 if (!mod_type) return 0;
471 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000474 Interactive_type = make_type("Interactive", mod_type,
475 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Expression_type = make_type("Expression", mod_type, Expression_fields,
478 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!Suite_type) return 0;
482 stmt_type = make_type("stmt", AST_type, NULL, 0);
483 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000484 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000486 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!FunctionDef_type) return 0;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000488 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000497 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000499 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000501 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000502 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000503 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000504 With_type = make_type("With", stmt_type, With_fields, 3);
505 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
511 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000512 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000513 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000515 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000516 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000517 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000518 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000522 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
523 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000526 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000528 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000529 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000530 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!Continue_type) return 0;
532 expr_type = make_type("expr", AST_type, NULL, 0);
533 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000534 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000543 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000547 Set_type = make_type("Set", expr_type, Set_fields, 1);
548 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!ListComp_type) return 0;
Nick Coghlan650f0d02007-04-15 12:05:43 +0000551 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
552 if (!SetComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553 GeneratorExp_type = make_type("GeneratorExp", expr_type,
554 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000566 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
567 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000568 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
569 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000574 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000575 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000576 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!Tuple_type) return 0;
580 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
581 if (!expr_context_type) return 0;
582 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000583 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000587 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000589 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000590 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000591 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000592 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000593 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000594 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000595 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000596 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000597 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000599 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000601 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Param_singleton) return 0;
607 slice_type = make_type("slice", AST_type, NULL, 0);
608 if (!slice_type) return 0;
609 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000610 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000611 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000612 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000614 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!Index_type) return 0;
616 boolop_type = make_type("boolop", AST_type, NULL, 0);
617 if (!boolop_type) return 0;
618 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Or_singleton) return 0;
627 operator_type = make_type("operator", AST_type, NULL, 0);
628 if (!operator_type) return 0;
629 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000630 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000632 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000634 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000636 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000638 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000640 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000642 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000644 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000646 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000648 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000650 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000666 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000670 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000671 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000672 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000673 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000674 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000676 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!FloorDiv_singleton) return 0;
678 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
679 if (!unaryop_type) return 0;
680 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!USub_singleton) return 0;
697 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
698 if (!cmpop_type) return 0;
699 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000700 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000704 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000706 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000708 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000710 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000712 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000714 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000716 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000718 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000720 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000722 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000723 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000724 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000725 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000726 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000728 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000730 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000731 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000732 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000733 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000734 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000736 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000737 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000738 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000739 if (!NotIn_singleton) return 0;
740 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000741 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000742 if (!comprehension_type) return 0;
743 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000744 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000745 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000746 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000747 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000748 arg_type = make_type("arg", AST_type, NULL, 0);
749 if (!arg_type) return 0;
750 if (!add_attributes(arg_type, NULL, 0)) return 0;
751 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
752 if (!SimpleArg_type) return 0;
753 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
754 1);
755 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000756 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
757 if (!keyword_type) return 0;
758 alias_type = make_type("alias", AST_type, alias_fields, 2);
759 if (!alias_type) return 0;
760 initialized = 1;
761 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000762}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000763
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000764mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000765Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766{
767 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000768 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000769 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000770 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771 p->kind = Module_kind;
772 p->v.Module.body = body;
773 return p;
774}
775
776mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000777Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778{
779 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000780 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000781 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000782 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783 p->kind = Interactive_kind;
784 p->v.Interactive.body = body;
785 return p;
786}
787
788mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000789Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000790{
791 mod_ty p;
792 if (!body) {
793 PyErr_SetString(PyExc_ValueError,
794 "field body is required for Expression");
795 return NULL;
796 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000797 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000798 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000799 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 p->kind = Expression_kind;
801 p->v.Expression.body = body;
802 return p;
803}
804
805mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000806Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000807{
808 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000809 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000810 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000812 p->kind = Suite_kind;
813 p->v.Suite.body = body;
814 return p;
815}
816
817stmt_ty
818FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000819 decorators, expr_ty returns, int lineno, int col_offset, PyArena
820 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000821{
822 stmt_ty p;
823 if (!name) {
824 PyErr_SetString(PyExc_ValueError,
825 "field name is required for FunctionDef");
826 return NULL;
827 }
828 if (!args) {
829 PyErr_SetString(PyExc_ValueError,
830 "field args is required for FunctionDef");
831 return NULL;
832 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000833 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000834 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000836 p->kind = FunctionDef_kind;
837 p->v.FunctionDef.name = name;
838 p->v.FunctionDef.args = args;
839 p->v.FunctionDef.body = body;
840 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000841 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000843 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000844 return p;
845}
846
847stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000848ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
849 starargs, expr_ty kwargs, asdl_seq * body, int lineno, int col_offset,
850 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851{
852 stmt_ty p;
853 if (!name) {
854 PyErr_SetString(PyExc_ValueError,
855 "field name is required for ClassDef");
856 return NULL;
857 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000858 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000859 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861 p->kind = ClassDef_kind;
862 p->v.ClassDef.name = name;
863 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000864 p->v.ClassDef.keywords = keywords;
865 p->v.ClassDef.starargs = starargs;
866 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 p->v.ClassDef.body = body;
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 +0000874Return(expr_ty value, 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 = Return_kind;
881 p->v.Return.value = value;
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 +0000888Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000889{
890 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000891 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000892 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000893 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894 p->kind = Delete_kind;
895 p->v.Delete.targets = targets;
896 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000897 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898 return p;
899}
900
901stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000902Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
903 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000904{
905 stmt_ty p;
906 if (!value) {
907 PyErr_SetString(PyExc_ValueError,
908 "field value is required for Assign");
909 return NULL;
910 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000911 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000912 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000913 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 p->kind = Assign_kind;
915 p->v.Assign.targets = targets;
916 p->v.Assign.value = value;
917 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000918 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000919 return p;
920}
921
922stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000923AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
924 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000925{
926 stmt_ty p;
927 if (!target) {
928 PyErr_SetString(PyExc_ValueError,
929 "field target is required for AugAssign");
930 return NULL;
931 }
932 if (!op) {
933 PyErr_SetString(PyExc_ValueError,
934 "field op is required for AugAssign");
935 return NULL;
936 }
937 if (!value) {
938 PyErr_SetString(PyExc_ValueError,
939 "field value is required for AugAssign");
940 return NULL;
941 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000942 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000943 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000944 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000945 p->kind = AugAssign_kind;
946 p->v.AugAssign.target = target;
947 p->v.AugAssign.op = op;
948 p->v.AugAssign.value = value;
949 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000950 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951 return p;
952}
953
954stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000956 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000957{
958 stmt_ty p;
959 if (!target) {
960 PyErr_SetString(PyExc_ValueError,
961 "field target is required for For");
962 return NULL;
963 }
964 if (!iter) {
965 PyErr_SetString(PyExc_ValueError,
966 "field iter is required for For");
967 return NULL;
968 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000969 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000970 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000971 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000972 p->kind = For_kind;
973 p->v.For.target = target;
974 p->v.For.iter = iter;
975 p->v.For.body = body;
976 p->v.For.orelse = orelse;
977 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000978 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 return p;
980}
981
982stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000983While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
984 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985{
986 stmt_ty p;
987 if (!test) {
988 PyErr_SetString(PyExc_ValueError,
989 "field test is required for While");
990 return NULL;
991 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000992 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000993 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000994 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000995 p->kind = While_kind;
996 p->v.While.test = test;
997 p->v.While.body = body;
998 p->v.While.orelse = orelse;
999 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001000 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 return p;
1002}
1003
1004stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001005If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1006 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001007{
1008 stmt_ty p;
1009 if (!test) {
1010 PyErr_SetString(PyExc_ValueError,
1011 "field test is required for If");
1012 return NULL;
1013 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001014 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001015 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001016 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001017 p->kind = If_kind;
1018 p->v.If.test = test;
1019 p->v.If.body = body;
1020 p->v.If.orelse = orelse;
1021 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001022 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001023 return p;
1024}
1025
1026stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001027With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001028 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001029{
1030 stmt_ty p;
1031 if (!context_expr) {
1032 PyErr_SetString(PyExc_ValueError,
1033 "field context_expr is required for With");
1034 return NULL;
1035 }
1036 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001037 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001038 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001039 p->kind = With_kind;
1040 p->v.With.context_expr = context_expr;
1041 p->v.With.optional_vars = optional_vars;
1042 p->v.With.body = body;
1043 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001044 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001045 return p;
1046}
1047
1048stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001049Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1050 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001051{
1052 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001053 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001054 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001055 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001056 p->kind = Raise_kind;
1057 p->v.Raise.type = type;
1058 p->v.Raise.inst = inst;
1059 p->v.Raise.tback = tback;
1060 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001061 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 return p;
1063}
1064
1065stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001066TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001067 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068{
1069 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001070 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001071 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001072 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073 p->kind = TryExcept_kind;
1074 p->v.TryExcept.body = body;
1075 p->v.TryExcept.handlers = handlers;
1076 p->v.TryExcept.orelse = orelse;
1077 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001078 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 return p;
1080}
1081
1082stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001083TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1084 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085{
1086 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001087 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001088 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001090 p->kind = TryFinally_kind;
1091 p->v.TryFinally.body = body;
1092 p->v.TryFinally.finalbody = finalbody;
1093 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001094 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 return p;
1096}
1097
1098stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001099Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001100{
1101 stmt_ty p;
1102 if (!test) {
1103 PyErr_SetString(PyExc_ValueError,
1104 "field test is required for Assert");
1105 return NULL;
1106 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001107 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001108 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001109 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001110 p->kind = Assert_kind;
1111 p->v.Assert.test = test;
1112 p->v.Assert.msg = msg;
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 +00001119Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120{
1121 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001122 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001123 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001124 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 p->kind = Import_kind;
1126 p->v.Import.names = names;
1127 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001128 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 return p;
1130}
1131
1132stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001133ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1134 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135{
1136 stmt_ty p;
1137 if (!module) {
1138 PyErr_SetString(PyExc_ValueError,
1139 "field module is required for ImportFrom");
1140 return NULL;
1141 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001142 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001143 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001144 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 p->kind = ImportFrom_kind;
1146 p->v.ImportFrom.module = module;
1147 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001148 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001150 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151 return p;
1152}
1153
1154stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001155Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001156{
1157 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001158 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001159 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001160 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 p->kind = Global_kind;
1162 p->v.Global.names = names;
1163 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001164 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001165 return p;
1166}
1167
1168stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001169Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1170{
1171 stmt_ty p;
1172 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1173 if (!p)
1174 return NULL;
1175 p->kind = Nonlocal_kind;
1176 p->v.Nonlocal.names = names;
1177 p->lineno = lineno;
1178 p->col_offset = col_offset;
1179 return p;
1180}
1181
1182stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001183Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001184{
1185 stmt_ty p;
1186 if (!value) {
1187 PyErr_SetString(PyExc_ValueError,
1188 "field value is required for Expr");
1189 return NULL;
1190 }
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 = Expr_kind;
1195 p->v.Expr.value = value;
1196 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001197 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001198 return p;
1199}
1200
1201stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001202Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203{
1204 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001205 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001206 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208 p->kind = Pass_kind;
1209 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001210 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001211 return p;
1212}
1213
1214stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001215Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001216{
1217 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001218 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001219 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001221 p->kind = Break_kind;
1222 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001223 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001224 return p;
1225}
1226
1227stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001228Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229{
1230 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001231 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001232 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001233 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234 p->kind = Continue_kind;
1235 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001236 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001237 return p;
1238}
1239
1240expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001241BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1242 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001243{
1244 expr_ty p;
1245 if (!op) {
1246 PyErr_SetString(PyExc_ValueError,
1247 "field op is required for BoolOp");
1248 return NULL;
1249 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001250 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001251 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001252 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001253 p->kind = BoolOp_kind;
1254 p->v.BoolOp.op = op;
1255 p->v.BoolOp.values = values;
1256 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001257 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001258 return p;
1259}
1260
1261expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001262BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1263 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264{
1265 expr_ty p;
1266 if (!left) {
1267 PyErr_SetString(PyExc_ValueError,
1268 "field left is required for BinOp");
1269 return NULL;
1270 }
1271 if (!op) {
1272 PyErr_SetString(PyExc_ValueError,
1273 "field op is required for BinOp");
1274 return NULL;
1275 }
1276 if (!right) {
1277 PyErr_SetString(PyExc_ValueError,
1278 "field right is required for BinOp");
1279 return NULL;
1280 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001281 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001282 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001283 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001284 p->kind = BinOp_kind;
1285 p->v.BinOp.left = left;
1286 p->v.BinOp.op = op;
1287 p->v.BinOp.right = right;
1288 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001289 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290 return p;
1291}
1292
1293expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001294UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1295 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001296{
1297 expr_ty p;
1298 if (!op) {
1299 PyErr_SetString(PyExc_ValueError,
1300 "field op is required for UnaryOp");
1301 return NULL;
1302 }
1303 if (!operand) {
1304 PyErr_SetString(PyExc_ValueError,
1305 "field operand is required for UnaryOp");
1306 return NULL;
1307 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001308 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001309 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001310 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001311 p->kind = UnaryOp_kind;
1312 p->v.UnaryOp.op = op;
1313 p->v.UnaryOp.operand = operand;
1314 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001315 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001316 return p;
1317}
1318
1319expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001320Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1321 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001322{
1323 expr_ty p;
1324 if (!args) {
1325 PyErr_SetString(PyExc_ValueError,
1326 "field args is required for Lambda");
1327 return NULL;
1328 }
1329 if (!body) {
1330 PyErr_SetString(PyExc_ValueError,
1331 "field body is required for Lambda");
1332 return NULL;
1333 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001334 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001335 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001336 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001337 p->kind = Lambda_kind;
1338 p->v.Lambda.args = args;
1339 p->v.Lambda.body = body;
1340 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001341 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001342 return p;
1343}
1344
1345expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001346IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1347 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001348{
1349 expr_ty p;
1350 if (!test) {
1351 PyErr_SetString(PyExc_ValueError,
1352 "field test is required for IfExp");
1353 return NULL;
1354 }
1355 if (!body) {
1356 PyErr_SetString(PyExc_ValueError,
1357 "field body is required for IfExp");
1358 return NULL;
1359 }
1360 if (!orelse) {
1361 PyErr_SetString(PyExc_ValueError,
1362 "field orelse is required for IfExp");
1363 return NULL;
1364 }
1365 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001366 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001367 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001368 p->kind = IfExp_kind;
1369 p->v.IfExp.test = test;
1370 p->v.IfExp.body = body;
1371 p->v.IfExp.orelse = orelse;
1372 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001373 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001374 return p;
1375}
1376
1377expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001378Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1379 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001380{
1381 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001382 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001383 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001384 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001385 p->kind = Dict_kind;
1386 p->v.Dict.keys = keys;
1387 p->v.Dict.values = values;
1388 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001389 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001390 return p;
1391}
1392
1393expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001394Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1395{
1396 expr_ty p;
1397 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001398 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001399 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001400 p->kind = Set_kind;
1401 p->v.Set.elts = elts;
1402 p->lineno = lineno;
1403 p->col_offset = col_offset;
1404 return p;
1405}
1406
1407expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001408ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1409 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001410{
1411 expr_ty p;
1412 if (!elt) {
1413 PyErr_SetString(PyExc_ValueError,
1414 "field elt is required for ListComp");
1415 return NULL;
1416 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001417 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001418 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001419 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001420 p->kind = ListComp_kind;
1421 p->v.ListComp.elt = elt;
1422 p->v.ListComp.generators = generators;
1423 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001424 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001425 return p;
1426}
1427
1428expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001429SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1430 *arena)
1431{
1432 expr_ty p;
1433 if (!elt) {
1434 PyErr_SetString(PyExc_ValueError,
1435 "field elt is required for SetComp");
1436 return NULL;
1437 }
1438 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1439 if (!p)
1440 return NULL;
1441 p->kind = SetComp_kind;
1442 p->v.SetComp.elt = elt;
1443 p->v.SetComp.generators = generators;
1444 p->lineno = lineno;
1445 p->col_offset = col_offset;
1446 return p;
1447}
1448
1449expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001450GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1451 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452{
1453 expr_ty p;
1454 if (!elt) {
1455 PyErr_SetString(PyExc_ValueError,
1456 "field elt is required for GeneratorExp");
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 = GeneratorExp_kind;
1463 p->v.GeneratorExp.elt = elt;
1464 p->v.GeneratorExp.generators = generators;
1465 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001466 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001467 return p;
1468}
1469
1470expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001471Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472{
1473 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001474 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001475 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001476 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 p->kind = Yield_kind;
1478 p->v.Yield.value = value;
1479 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001480 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001481 return p;
1482}
1483
1484expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001485Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1486 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001487{
1488 expr_ty p;
1489 if (!left) {
1490 PyErr_SetString(PyExc_ValueError,
1491 "field left is required for Compare");
1492 return NULL;
1493 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001494 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001495 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001496 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001497 p->kind = Compare_kind;
1498 p->v.Compare.left = left;
1499 p->v.Compare.ops = ops;
1500 p->v.Compare.comparators = comparators;
1501 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001502 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001503 return p;
1504}
1505
1506expr_ty
1507Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001508 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001509{
1510 expr_ty p;
1511 if (!func) {
1512 PyErr_SetString(PyExc_ValueError,
1513 "field func is required for Call");
1514 return NULL;
1515 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001516 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001517 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001519 p->kind = Call_kind;
1520 p->v.Call.func = func;
1521 p->v.Call.args = args;
1522 p->v.Call.keywords = keywords;
1523 p->v.Call.starargs = starargs;
1524 p->v.Call.kwargs = kwargs;
1525 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001526 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001527 return p;
1528}
1529
1530expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001531Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532{
1533 expr_ty p;
1534 if (!n) {
1535 PyErr_SetString(PyExc_ValueError,
1536 "field n is required for Num");
1537 return NULL;
1538 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001539 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001540 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001541 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001542 p->kind = Num_kind;
1543 p->v.Num.n = n;
1544 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001545 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001546 return p;
1547}
1548
1549expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001550Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551{
1552 expr_ty p;
1553 if (!s) {
1554 PyErr_SetString(PyExc_ValueError,
1555 "field s is required for Str");
1556 return NULL;
1557 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001558 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001559 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001560 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561 p->kind = Str_kind;
1562 p->v.Str.s = s;
1563 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001564 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565 return p;
1566}
1567
1568expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001569Bytes(string s, int lineno, int col_offset, PyArena *arena)
1570{
1571 expr_ty p;
1572 if (!s) {
1573 PyErr_SetString(PyExc_ValueError,
1574 "field s is required for Bytes");
1575 return NULL;
1576 }
1577 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001578 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001579 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001580 p->kind = Bytes_kind;
1581 p->v.Bytes.s = s;
1582 p->lineno = lineno;
1583 p->col_offset = col_offset;
1584 return p;
1585}
1586
1587expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001588Ellipsis(int lineno, int col_offset, PyArena *arena)
1589{
1590 expr_ty p;
1591 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001592 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001593 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001594 p->kind = Ellipsis_kind;
1595 p->lineno = lineno;
1596 p->col_offset = col_offset;
1597 return p;
1598}
1599
1600expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001601Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1602 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001603{
1604 expr_ty p;
1605 if (!value) {
1606 PyErr_SetString(PyExc_ValueError,
1607 "field value is required for Attribute");
1608 return NULL;
1609 }
1610 if (!attr) {
1611 PyErr_SetString(PyExc_ValueError,
1612 "field attr is required for Attribute");
1613 return NULL;
1614 }
1615 if (!ctx) {
1616 PyErr_SetString(PyExc_ValueError,
1617 "field ctx is required for Attribute");
1618 return NULL;
1619 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001620 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001621 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001622 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001623 p->kind = Attribute_kind;
1624 p->v.Attribute.value = value;
1625 p->v.Attribute.attr = attr;
1626 p->v.Attribute.ctx = ctx;
1627 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001628 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001629 return p;
1630}
1631
1632expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001633Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1634 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001635{
1636 expr_ty p;
1637 if (!value) {
1638 PyErr_SetString(PyExc_ValueError,
1639 "field value is required for Subscript");
1640 return NULL;
1641 }
1642 if (!slice) {
1643 PyErr_SetString(PyExc_ValueError,
1644 "field slice is required for Subscript");
1645 return NULL;
1646 }
1647 if (!ctx) {
1648 PyErr_SetString(PyExc_ValueError,
1649 "field ctx is required for Subscript");
1650 return NULL;
1651 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001652 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001653 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001654 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001655 p->kind = Subscript_kind;
1656 p->v.Subscript.value = value;
1657 p->v.Subscript.slice = slice;
1658 p->v.Subscript.ctx = ctx;
1659 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001660 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001661 return p;
1662}
1663
1664expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001665Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1666 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001667{
1668 expr_ty p;
1669 if (!id) {
1670 PyErr_SetString(PyExc_ValueError,
1671 "field id is required for Name");
1672 return NULL;
1673 }
1674 if (!ctx) {
1675 PyErr_SetString(PyExc_ValueError,
1676 "field ctx is required for Name");
1677 return NULL;
1678 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001679 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001680 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001681 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001682 p->kind = Name_kind;
1683 p->v.Name.id = id;
1684 p->v.Name.ctx = ctx;
1685 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001686 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001687 return p;
1688}
1689
1690expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001691List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1692 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001693{
1694 expr_ty p;
1695 if (!ctx) {
1696 PyErr_SetString(PyExc_ValueError,
1697 "field ctx is required for List");
1698 return NULL;
1699 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001700 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001701 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703 p->kind = List_kind;
1704 p->v.List.elts = elts;
1705 p->v.List.ctx = ctx;
1706 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001707 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001708 return p;
1709}
1710
1711expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001712Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1713 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001714{
1715 expr_ty p;
1716 if (!ctx) {
1717 PyErr_SetString(PyExc_ValueError,
1718 "field ctx is required for Tuple");
1719 return NULL;
1720 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001721 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001722 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001723 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001724 p->kind = Tuple_kind;
1725 p->v.Tuple.elts = elts;
1726 p->v.Tuple.ctx = ctx;
1727 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001728 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001729 return p;
1730}
1731
1732slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001733Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001734{
1735 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001736 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001737 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001739 p->kind = Slice_kind;
1740 p->v.Slice.lower = lower;
1741 p->v.Slice.upper = upper;
1742 p->v.Slice.step = step;
1743 return p;
1744}
1745
1746slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001747ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748{
1749 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001750 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001751 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001752 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 p->kind = ExtSlice_kind;
1754 p->v.ExtSlice.dims = dims;
1755 return p;
1756}
1757
1758slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001759Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760{
1761 slice_ty p;
1762 if (!value) {
1763 PyErr_SetString(PyExc_ValueError,
1764 "field value is required for Index");
1765 return NULL;
1766 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001767 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001768 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001770 p->kind = Index_kind;
1771 p->v.Index.value = value;
1772 return p;
1773}
1774
1775comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001776comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001777{
1778 comprehension_ty p;
1779 if (!target) {
1780 PyErr_SetString(PyExc_ValueError,
1781 "field target is required for comprehension");
1782 return NULL;
1783 }
1784 if (!iter) {
1785 PyErr_SetString(PyExc_ValueError,
1786 "field iter is required for comprehension");
1787 return NULL;
1788 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001789 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001790 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001791 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001792 p->target = target;
1793 p->iter = iter;
1794 p->ifs = ifs;
1795 return p;
1796}
1797
1798excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001799excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001800 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001801{
1802 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001803 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001804 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001806 p->type = type;
1807 p->name = name;
1808 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001809 p->lineno = lineno;
1810 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001811 return p;
1812}
1813
1814arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001815arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1816 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1817 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001818{
1819 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001820 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001821 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001822 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001823 p->args = args;
1824 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001825 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001826 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001827 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001828 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001830 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001831 return p;
1832}
1833
Neal Norwitzc1505362006-12-28 06:47:50 +00001834arg_ty
1835SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1836{
1837 arg_ty p;
1838 if (!arg) {
1839 PyErr_SetString(PyExc_ValueError,
1840 "field arg is required for SimpleArg");
1841 return NULL;
1842 }
1843 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001844 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001845 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001846 p->kind = SimpleArg_kind;
1847 p->v.SimpleArg.arg = arg;
1848 p->v.SimpleArg.annotation = annotation;
1849 return p;
1850}
1851
1852arg_ty
1853NestedArgs(asdl_seq * args, PyArena *arena)
1854{
1855 arg_ty p;
1856 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001857 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001858 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001859 p->kind = NestedArgs_kind;
1860 p->v.NestedArgs.args = args;
1861 return p;
1862}
1863
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001865keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866{
1867 keyword_ty p;
1868 if (!arg) {
1869 PyErr_SetString(PyExc_ValueError,
1870 "field arg is required for keyword");
1871 return NULL;
1872 }
1873 if (!value) {
1874 PyErr_SetString(PyExc_ValueError,
1875 "field value is required for keyword");
1876 return NULL;
1877 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001878 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001879 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001880 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881 p->arg = arg;
1882 p->value = value;
1883 return p;
1884}
1885
1886alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001887alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001888{
1889 alias_ty p;
1890 if (!name) {
1891 PyErr_SetString(PyExc_ValueError,
1892 "field name is required for alias");
1893 return NULL;
1894 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001895 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001896 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001898 p->name = name;
1899 p->asname = asname;
1900 return p;
1901}
1902
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001903
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001904PyObject*
1905ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001906{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001907 mod_ty o = (mod_ty)_o;
1908 PyObject *result = NULL, *value = NULL;
1909 if (!o) {
1910 Py_INCREF(Py_None);
1911 return Py_None;
1912 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001913
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001914 switch (o->kind) {
1915 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001916 result = PyType_GenericNew(Module_type, NULL, NULL);
1917 if (!result) goto failed;
1918 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1919 if (!value) goto failed;
1920 if (PyObject_SetAttrString(result, "body", value) == -1)
1921 goto failed;
1922 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923 break;
1924 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001925 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1926 if (!result) goto failed;
1927 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "body", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001932 break;
1933 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001934 result = PyType_GenericNew(Expression_type, NULL, NULL);
1935 if (!result) goto failed;
1936 value = ast2obj_expr(o->v.Expression.body);
1937 if (!value) goto failed;
1938 if (PyObject_SetAttrString(result, "body", value) == -1)
1939 goto failed;
1940 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 break;
1942 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001943 result = PyType_GenericNew(Suite_type, NULL, NULL);
1944 if (!result) goto failed;
1945 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1946 if (!value) goto failed;
1947 if (PyObject_SetAttrString(result, "body", value) == -1)
1948 goto failed;
1949 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001950 break;
1951 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001952 return result;
1953failed:
1954 Py_XDECREF(value);
1955 Py_XDECREF(result);
1956 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001957}
1958
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001959PyObject*
1960ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001961{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001962 stmt_ty o = (stmt_ty)_o;
1963 PyObject *result = NULL, *value = NULL;
1964 if (!o) {
1965 Py_INCREF(Py_None);
1966 return Py_None;
1967 }
1968
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001969 switch (o->kind) {
1970 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001971 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1972 if (!result) goto failed;
1973 value = ast2obj_identifier(o->v.FunctionDef.name);
1974 if (!value) goto failed;
1975 if (PyObject_SetAttrString(result, "name", value) == -1)
1976 goto failed;
1977 Py_DECREF(value);
1978 value = ast2obj_arguments(o->v.FunctionDef.args);
1979 if (!value) goto failed;
1980 if (PyObject_SetAttrString(result, "args", value) == -1)
1981 goto failed;
1982 Py_DECREF(value);
1983 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1984 if (!value) goto failed;
1985 if (PyObject_SetAttrString(result, "body", value) == -1)
1986 goto failed;
1987 Py_DECREF(value);
1988 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00001993 value = ast2obj_expr(o->v.FunctionDef.returns);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "returns", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001998 break;
1999 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002000 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2001 if (!result) goto failed;
2002 value = ast2obj_identifier(o->v.ClassDef.name);
2003 if (!value) goto failed;
2004 if (PyObject_SetAttrString(result, "name", value) == -1)
2005 goto failed;
2006 Py_DECREF(value);
2007 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "bases", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00002012 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
2017 value = ast2obj_expr(o->v.ClassDef.starargs);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_expr(o->v.ClassDef.kwargs);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002027 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2028 if (!value) goto failed;
2029 if (PyObject_SetAttrString(result, "body", value) == -1)
2030 goto failed;
2031 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002032 break;
2033 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002034 result = PyType_GenericNew(Return_type, NULL, NULL);
2035 if (!result) goto failed;
2036 value = ast2obj_expr(o->v.Return.value);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "value", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041 break;
2042 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002043 result = PyType_GenericNew(Delete_type, NULL, NULL);
2044 if (!result) goto failed;
2045 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "targets", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002050 break;
2051 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002052 result = PyType_GenericNew(Assign_type, NULL, NULL);
2053 if (!result) goto failed;
2054 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "targets", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
2059 value = ast2obj_expr(o->v.Assign.value);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "value", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002064 break;
2065 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002066 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2067 if (!result) goto failed;
2068 value = ast2obj_expr(o->v.AugAssign.target);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "target", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
2073 value = ast2obj_operator(o->v.AugAssign.op);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "op", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
2078 value = ast2obj_expr(o->v.AugAssign.value);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "value", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002083 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002084 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002085 result = PyType_GenericNew(For_type, NULL, NULL);
2086 if (!result) goto failed;
2087 value = ast2obj_expr(o->v.For.target);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "target", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_expr(o->v.For.iter);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "iter", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
2097 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2098 if (!value) goto failed;
2099 if (PyObject_SetAttrString(result, "body", value) == -1)
2100 goto failed;
2101 Py_DECREF(value);
2102 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2103 if (!value) goto failed;
2104 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2105 goto failed;
2106 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002107 break;
2108 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002109 result = PyType_GenericNew(While_type, NULL, NULL);
2110 if (!result) goto failed;
2111 value = ast2obj_expr(o->v.While.test);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "test", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
2116 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2117 if (!value) goto failed;
2118 if (PyObject_SetAttrString(result, "body", value) == -1)
2119 goto failed;
2120 Py_DECREF(value);
2121 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002126 break;
2127 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002128 result = PyType_GenericNew(If_type, NULL, NULL);
2129 if (!result) goto failed;
2130 value = ast2obj_expr(o->v.If.test);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "test", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "body", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
2140 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2141 if (!value) goto failed;
2142 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2143 goto failed;
2144 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002145 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002146 case With_kind:
2147 result = PyType_GenericNew(With_type, NULL, NULL);
2148 if (!result) goto failed;
2149 value = ast2obj_expr(o->v.With.context_expr);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_expr(o->v.With.optional_vars);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2157 -1)
2158 goto failed;
2159 Py_DECREF(value);
2160 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2161 if (!value) goto failed;
2162 if (PyObject_SetAttrString(result, "body", value) == -1)
2163 goto failed;
2164 Py_DECREF(value);
2165 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002166 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002167 result = PyType_GenericNew(Raise_type, NULL, NULL);
2168 if (!result) goto failed;
2169 value = ast2obj_expr(o->v.Raise.type);
2170 if (!value) goto failed;
2171 if (PyObject_SetAttrString(result, "type", value) == -1)
2172 goto failed;
2173 Py_DECREF(value);
2174 value = ast2obj_expr(o->v.Raise.inst);
2175 if (!value) goto failed;
2176 if (PyObject_SetAttrString(result, "inst", value) == -1)
2177 goto failed;
2178 Py_DECREF(value);
2179 value = ast2obj_expr(o->v.Raise.tback);
2180 if (!value) goto failed;
2181 if (PyObject_SetAttrString(result, "tback", value) == -1)
2182 goto failed;
2183 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002184 break;
2185 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002186 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2187 if (!result) goto failed;
2188 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "body", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_list(o->v.TryExcept.handlers,
2194 ast2obj_excepthandler);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2200 if (!value) goto failed;
2201 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2202 goto failed;
2203 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002204 break;
2205 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002206 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2207 if (!result) goto failed;
2208 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "body", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
2213 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2214 if (!value) goto failed;
2215 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2216 goto failed;
2217 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218 break;
2219 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002220 result = PyType_GenericNew(Assert_type, NULL, NULL);
2221 if (!result) goto failed;
2222 value = ast2obj_expr(o->v.Assert.test);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "test", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
2227 value = ast2obj_expr(o->v.Assert.msg);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "msg", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002232 break;
2233 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002234 result = PyType_GenericNew(Import_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "names", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241 break;
2242 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002243 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2244 if (!result) goto failed;
2245 value = ast2obj_identifier(o->v.ImportFrom.module);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "module", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
2250 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2251 if (!value) goto failed;
2252 if (PyObject_SetAttrString(result, "names", value) == -1)
2253 goto failed;
2254 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002255 value = ast2obj_int(o->v.ImportFrom.level);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "level", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002260 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002261 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002262 result = PyType_GenericNew(Global_type, NULL, NULL);
2263 if (!result) goto failed;
2264 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "names", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002269 break;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002270 case Nonlocal_kind:
2271 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2272 if (!result) goto failed;
2273 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2274 if (!value) goto failed;
2275 if (PyObject_SetAttrString(result, "names", value) == -1)
2276 goto failed;
2277 Py_DECREF(value);
2278 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002279 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002280 result = PyType_GenericNew(Expr_type, NULL, NULL);
2281 if (!result) goto failed;
2282 value = ast2obj_expr(o->v.Expr.value);
2283 if (!value) goto failed;
2284 if (PyObject_SetAttrString(result, "value", value) == -1)
2285 goto failed;
2286 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002287 break;
2288 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002289 result = PyType_GenericNew(Pass_type, NULL, NULL);
2290 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002291 break;
2292 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002293 result = PyType_GenericNew(Break_type, NULL, NULL);
2294 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002295 break;
2296 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002297 result = PyType_GenericNew(Continue_type, NULL, NULL);
2298 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002299 break;
2300 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002301 value = ast2obj_int(o->lineno);
2302 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002303 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2304 goto failed;
2305 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002306 value = ast2obj_int(o->col_offset);
2307 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002308 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2309 goto failed;
2310 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002311 return result;
2312failed:
2313 Py_XDECREF(value);
2314 Py_XDECREF(result);
2315 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002316}
2317
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002318PyObject*
2319ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002320{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002321 expr_ty o = (expr_ty)_o;
2322 PyObject *result = NULL, *value = NULL;
2323 if (!o) {
2324 Py_INCREF(Py_None);
2325 return Py_None;
2326 }
2327
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002328 switch (o->kind) {
2329 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002330 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2331 if (!result) goto failed;
2332 value = ast2obj_boolop(o->v.BoolOp.op);
2333 if (!value) goto failed;
2334 if (PyObject_SetAttrString(result, "op", value) == -1)
2335 goto failed;
2336 Py_DECREF(value);
2337 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2338 if (!value) goto failed;
2339 if (PyObject_SetAttrString(result, "values", value) == -1)
2340 goto failed;
2341 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342 break;
2343 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2345 if (!result) goto failed;
2346 value = ast2obj_expr(o->v.BinOp.left);
2347 if (!value) goto failed;
2348 if (PyObject_SetAttrString(result, "left", value) == -1)
2349 goto failed;
2350 Py_DECREF(value);
2351 value = ast2obj_operator(o->v.BinOp.op);
2352 if (!value) goto failed;
2353 if (PyObject_SetAttrString(result, "op", value) == -1)
2354 goto failed;
2355 Py_DECREF(value);
2356 value = ast2obj_expr(o->v.BinOp.right);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "right", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002361 break;
2362 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002363 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2364 if (!result) goto failed;
2365 value = ast2obj_unaryop(o->v.UnaryOp.op);
2366 if (!value) goto failed;
2367 if (PyObject_SetAttrString(result, "op", value) == -1)
2368 goto failed;
2369 Py_DECREF(value);
2370 value = ast2obj_expr(o->v.UnaryOp.operand);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "operand", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375 break;
2376 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002377 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2378 if (!result) goto failed;
2379 value = ast2obj_arguments(o->v.Lambda.args);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "args", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 value = ast2obj_expr(o->v.Lambda.body);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "body", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002389 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002390 case IfExp_kind:
2391 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2392 if (!result) goto failed;
2393 value = ast2obj_expr(o->v.IfExp.test);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "test", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
2398 value = ast2obj_expr(o->v.IfExp.body);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "body", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 value = ast2obj_expr(o->v.IfExp.orelse);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
2408 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002409 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(Dict_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "keys", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
2417 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "values", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002422 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002423 case Set_kind:
2424 result = PyType_GenericNew(Set_type, NULL, NULL);
2425 if (!result) goto failed;
2426 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2427 if (!value) goto failed;
2428 if (PyObject_SetAttrString(result, "elts", value) == -1)
2429 goto failed;
2430 Py_DECREF(value);
2431 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002432 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002433 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2434 if (!result) goto failed;
2435 value = ast2obj_expr(o->v.ListComp.elt);
2436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "elt", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 value = ast2obj_list(o->v.ListComp.generators,
2441 ast2obj_comprehension);
2442 if (!value) goto failed;
2443 if (PyObject_SetAttrString(result, "generators", value) == -1)
2444 goto failed;
2445 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002446 break;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002447 case SetComp_kind:
2448 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2449 if (!result) goto failed;
2450 value = ast2obj_expr(o->v.SetComp.elt);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "elt", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
2455 value = ast2obj_list(o->v.SetComp.generators,
2456 ast2obj_comprehension);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "generators", value) == -1)
2459 goto failed;
2460 Py_DECREF(value);
2461 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002462 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002463 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_expr(o->v.GeneratorExp.elt);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "elt", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 value = ast2obj_list(o->v.GeneratorExp.generators,
2471 ast2obj_comprehension);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "generators", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002476 break;
2477 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002478 result = PyType_GenericNew(Yield_type, NULL, NULL);
2479 if (!result) goto failed;
2480 value = ast2obj_expr(o->v.Yield.value);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "value", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002485 break;
2486 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002487 result = PyType_GenericNew(Compare_type, NULL, NULL);
2488 if (!result) goto failed;
2489 value = ast2obj_expr(o->v.Compare.left);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "left", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002494 {
2495 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2496 value = PyList_New(n);
2497 if (!value) goto failed;
2498 for(i = 0; i < n; i++)
2499 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2500 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "ops", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
2505 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002510 break;
2511 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002512 result = PyType_GenericNew(Call_type, NULL, NULL);
2513 if (!result) goto failed;
2514 value = ast2obj_expr(o->v.Call.func);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "func", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "args", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
2524 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2525 if (!value) goto failed;
2526 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2527 goto failed;
2528 Py_DECREF(value);
2529 value = ast2obj_expr(o->v.Call.starargs);
2530 if (!value) goto failed;
2531 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2532 goto failed;
2533 Py_DECREF(value);
2534 value = ast2obj_expr(o->v.Call.kwargs);
2535 if (!value) goto failed;
2536 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2537 goto failed;
2538 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002539 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002540 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002541 result = PyType_GenericNew(Num_type, NULL, NULL);
2542 if (!result) goto failed;
2543 value = ast2obj_object(o->v.Num.n);
2544 if (!value) goto failed;
2545 if (PyObject_SetAttrString(result, "n", value) == -1)
2546 goto failed;
2547 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002548 break;
2549 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002550 result = PyType_GenericNew(Str_type, NULL, NULL);
2551 if (!result) goto failed;
2552 value = ast2obj_string(o->v.Str.s);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "s", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002558 case Bytes_kind:
2559 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_string(o->v.Bytes.s);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "s", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
2566 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002567 case Ellipsis_kind:
2568 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2569 if (!result) goto failed;
2570 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002571 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002572 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2573 if (!result) goto failed;
2574 value = ast2obj_expr(o->v.Attribute.value);
2575 if (!value) goto failed;
2576 if (PyObject_SetAttrString(result, "value", value) == -1)
2577 goto failed;
2578 Py_DECREF(value);
2579 value = ast2obj_identifier(o->v.Attribute.attr);
2580 if (!value) goto failed;
2581 if (PyObject_SetAttrString(result, "attr", value) == -1)
2582 goto failed;
2583 Py_DECREF(value);
2584 value = ast2obj_expr_context(o->v.Attribute.ctx);
2585 if (!value) goto failed;
2586 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2587 goto failed;
2588 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589 break;
2590 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002591 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2592 if (!result) goto failed;
2593 value = ast2obj_expr(o->v.Subscript.value);
2594 if (!value) goto failed;
2595 if (PyObject_SetAttrString(result, "value", value) == -1)
2596 goto failed;
2597 Py_DECREF(value);
2598 value = ast2obj_slice(o->v.Subscript.slice);
2599 if (!value) goto failed;
2600 if (PyObject_SetAttrString(result, "slice", value) == -1)
2601 goto failed;
2602 Py_DECREF(value);
2603 value = ast2obj_expr_context(o->v.Subscript.ctx);
2604 if (!value) goto failed;
2605 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2606 goto failed;
2607 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002608 break;
2609 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002610 result = PyType_GenericNew(Name_type, NULL, NULL);
2611 if (!result) goto failed;
2612 value = ast2obj_identifier(o->v.Name.id);
2613 if (!value) goto failed;
2614 if (PyObject_SetAttrString(result, "id", value) == -1)
2615 goto failed;
2616 Py_DECREF(value);
2617 value = ast2obj_expr_context(o->v.Name.ctx);
2618 if (!value) goto failed;
2619 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2620 goto failed;
2621 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002622 break;
2623 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002624 result = PyType_GenericNew(List_type, NULL, NULL);
2625 if (!result) goto failed;
2626 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "elts", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
2631 value = ast2obj_expr_context(o->v.List.ctx);
2632 if (!value) goto failed;
2633 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2634 goto failed;
2635 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002636 break;
2637 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002638 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2639 if (!result) goto failed;
2640 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2641 if (!value) goto failed;
2642 if (PyObject_SetAttrString(result, "elts", value) == -1)
2643 goto failed;
2644 Py_DECREF(value);
2645 value = ast2obj_expr_context(o->v.Tuple.ctx);
2646 if (!value) goto failed;
2647 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2648 goto failed;
2649 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002650 break;
2651 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002652 value = ast2obj_int(o->lineno);
2653 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002654 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2655 goto failed;
2656 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002657 value = ast2obj_int(o->col_offset);
2658 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002659 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2660 goto failed;
2661 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002662 return result;
2663failed:
2664 Py_XDECREF(value);
2665 Py_XDECREF(result);
2666 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002667}
2668
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002669PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002670{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002671 switch(o) {
2672 case Load:
2673 Py_INCREF(Load_singleton);
2674 return Load_singleton;
2675 case Store:
2676 Py_INCREF(Store_singleton);
2677 return Store_singleton;
2678 case Del:
2679 Py_INCREF(Del_singleton);
2680 return Del_singleton;
2681 case AugLoad:
2682 Py_INCREF(AugLoad_singleton);
2683 return AugLoad_singleton;
2684 case AugStore:
2685 Py_INCREF(AugStore_singleton);
2686 return AugStore_singleton;
2687 case Param:
2688 Py_INCREF(Param_singleton);
2689 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002692}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002693PyObject*
2694ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002695{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002696 slice_ty o = (slice_ty)_o;
2697 PyObject *result = NULL, *value = NULL;
2698 if (!o) {
2699 Py_INCREF(Py_None);
2700 return Py_None;
2701 }
2702
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002703 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002704 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002705 result = PyType_GenericNew(Slice_type, NULL, NULL);
2706 if (!result) goto failed;
2707 value = ast2obj_expr(o->v.Slice.lower);
2708 if (!value) goto failed;
2709 if (PyObject_SetAttrString(result, "lower", value) == -1)
2710 goto failed;
2711 Py_DECREF(value);
2712 value = ast2obj_expr(o->v.Slice.upper);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "upper", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
2717 value = ast2obj_expr(o->v.Slice.step);
2718 if (!value) goto failed;
2719 if (PyObject_SetAttrString(result, "step", value) == -1)
2720 goto failed;
2721 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002722 break;
2723 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002724 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2725 if (!result) goto failed;
2726 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2727 if (!value) goto failed;
2728 if (PyObject_SetAttrString(result, "dims", value) == -1)
2729 goto failed;
2730 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002731 break;
2732 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002733 result = PyType_GenericNew(Index_type, NULL, NULL);
2734 if (!result) goto failed;
2735 value = ast2obj_expr(o->v.Index.value);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "value", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002740 break;
2741 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002742 return result;
2743failed:
2744 Py_XDECREF(value);
2745 Py_XDECREF(result);
2746 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002747}
2748
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002749PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002750{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002751 switch(o) {
2752 case And:
2753 Py_INCREF(And_singleton);
2754 return And_singleton;
2755 case Or:
2756 Py_INCREF(Or_singleton);
2757 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002758 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002759 return NULL; /* cannot happen */
2760}
2761PyObject* ast2obj_operator(operator_ty o)
2762{
2763 switch(o) {
2764 case Add:
2765 Py_INCREF(Add_singleton);
2766 return Add_singleton;
2767 case Sub:
2768 Py_INCREF(Sub_singleton);
2769 return Sub_singleton;
2770 case Mult:
2771 Py_INCREF(Mult_singleton);
2772 return Mult_singleton;
2773 case Div:
2774 Py_INCREF(Div_singleton);
2775 return Div_singleton;
2776 case Mod:
2777 Py_INCREF(Mod_singleton);
2778 return Mod_singleton;
2779 case Pow:
2780 Py_INCREF(Pow_singleton);
2781 return Pow_singleton;
2782 case LShift:
2783 Py_INCREF(LShift_singleton);
2784 return LShift_singleton;
2785 case RShift:
2786 Py_INCREF(RShift_singleton);
2787 return RShift_singleton;
2788 case BitOr:
2789 Py_INCREF(BitOr_singleton);
2790 return BitOr_singleton;
2791 case BitXor:
2792 Py_INCREF(BitXor_singleton);
2793 return BitXor_singleton;
2794 case BitAnd:
2795 Py_INCREF(BitAnd_singleton);
2796 return BitAnd_singleton;
2797 case FloorDiv:
2798 Py_INCREF(FloorDiv_singleton);
2799 return FloorDiv_singleton;
2800 }
2801 return NULL; /* cannot happen */
2802}
2803PyObject* ast2obj_unaryop(unaryop_ty o)
2804{
2805 switch(o) {
2806 case Invert:
2807 Py_INCREF(Invert_singleton);
2808 return Invert_singleton;
2809 case Not:
2810 Py_INCREF(Not_singleton);
2811 return Not_singleton;
2812 case UAdd:
2813 Py_INCREF(UAdd_singleton);
2814 return UAdd_singleton;
2815 case USub:
2816 Py_INCREF(USub_singleton);
2817 return USub_singleton;
2818 }
2819 return NULL; /* cannot happen */
2820}
2821PyObject* ast2obj_cmpop(cmpop_ty o)
2822{
2823 switch(o) {
2824 case Eq:
2825 Py_INCREF(Eq_singleton);
2826 return Eq_singleton;
2827 case NotEq:
2828 Py_INCREF(NotEq_singleton);
2829 return NotEq_singleton;
2830 case Lt:
2831 Py_INCREF(Lt_singleton);
2832 return Lt_singleton;
2833 case LtE:
2834 Py_INCREF(LtE_singleton);
2835 return LtE_singleton;
2836 case Gt:
2837 Py_INCREF(Gt_singleton);
2838 return Gt_singleton;
2839 case GtE:
2840 Py_INCREF(GtE_singleton);
2841 return GtE_singleton;
2842 case Is:
2843 Py_INCREF(Is_singleton);
2844 return Is_singleton;
2845 case IsNot:
2846 Py_INCREF(IsNot_singleton);
2847 return IsNot_singleton;
2848 case In:
2849 Py_INCREF(In_singleton);
2850 return In_singleton;
2851 case NotIn:
2852 Py_INCREF(NotIn_singleton);
2853 return NotIn_singleton;
2854 }
2855 return NULL; /* cannot happen */
2856}
2857PyObject*
2858ast2obj_comprehension(void* _o)
2859{
2860 comprehension_ty o = (comprehension_ty)_o;
2861 PyObject *result = NULL, *value = NULL;
2862 if (!o) {
2863 Py_INCREF(Py_None);
2864 return Py_None;
2865 }
2866
2867 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2868 if (!result) return NULL;
2869 value = ast2obj_expr(o->target);
2870 if (!value) goto failed;
2871 if (PyObject_SetAttrString(result, "target", value) == -1)
2872 goto failed;
2873 Py_DECREF(value);
2874 value = ast2obj_expr(o->iter);
2875 if (!value) goto failed;
2876 if (PyObject_SetAttrString(result, "iter", value) == -1)
2877 goto failed;
2878 Py_DECREF(value);
2879 value = ast2obj_list(o->ifs, ast2obj_expr);
2880 if (!value) goto failed;
2881 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2882 goto failed;
2883 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002884 return result;
2885failed:
2886 Py_XDECREF(value);
2887 Py_XDECREF(result);
2888 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002889}
2890
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002891PyObject*
2892ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002893{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002894 excepthandler_ty o = (excepthandler_ty)_o;
2895 PyObject *result = NULL, *value = NULL;
2896 if (!o) {
2897 Py_INCREF(Py_None);
2898 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002899 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002900
2901 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2902 if (!result) return NULL;
2903 value = ast2obj_expr(o->type);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "type", value) == -1)
2906 goto failed;
2907 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002908 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002909 if (!value) goto failed;
2910 if (PyObject_SetAttrString(result, "name", value) == -1)
2911 goto failed;
2912 Py_DECREF(value);
2913 value = ast2obj_list(o->body, ast2obj_stmt);
2914 if (!value) goto failed;
2915 if (PyObject_SetAttrString(result, "body", value) == -1)
2916 goto failed;
2917 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002918 value = ast2obj_int(o->lineno);
2919 if (!value) goto failed;
2920 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2921 goto failed;
2922 Py_DECREF(value);
2923 value = ast2obj_int(o->col_offset);
2924 if (!value) goto failed;
2925 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2926 goto failed;
2927 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002928 return result;
2929failed:
2930 Py_XDECREF(value);
2931 Py_XDECREF(result);
2932 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002933}
2934
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002935PyObject*
2936ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002937{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002938 arguments_ty o = (arguments_ty)_o;
2939 PyObject *result = NULL, *value = NULL;
2940 if (!o) {
2941 Py_INCREF(Py_None);
2942 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002943 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002944
2945 result = PyType_GenericNew(arguments_type, NULL, NULL);
2946 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002947 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002948 if (!value) goto failed;
2949 if (PyObject_SetAttrString(result, "args", value) == -1)
2950 goto failed;
2951 Py_DECREF(value);
2952 value = ast2obj_identifier(o->vararg);
2953 if (!value) goto failed;
2954 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2955 goto failed;
2956 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002957 value = ast2obj_expr(o->varargannotation);
2958 if (!value) goto failed;
2959 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2960 goto failed;
2961 Py_DECREF(value);
2962 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002963 if (!value) goto failed;
2964 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2965 goto failed;
2966 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002967 value = ast2obj_identifier(o->kwarg);
2968 if (!value) goto failed;
2969 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2970 goto failed;
2971 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002972 value = ast2obj_expr(o->kwargannotation);
2973 if (!value) goto failed;
2974 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2975 goto failed;
2976 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002977 value = ast2obj_list(o->defaults, ast2obj_expr);
2978 if (!value) goto failed;
2979 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2980 goto failed;
2981 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002982 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2983 if (!value) goto failed;
2984 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2985 goto failed;
2986 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002987 return result;
2988failed:
2989 Py_XDECREF(value);
2990 Py_XDECREF(result);
2991 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002992}
2993
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002994PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002995ast2obj_arg(void* _o)
2996{
2997 arg_ty o = (arg_ty)_o;
2998 PyObject *result = NULL, *value = NULL;
2999 if (!o) {
3000 Py_INCREF(Py_None);
3001 return Py_None;
3002 }
3003
3004 switch (o->kind) {
3005 case SimpleArg_kind:
3006 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
3007 if (!result) goto failed;
3008 value = ast2obj_identifier(o->v.SimpleArg.arg);
3009 if (!value) goto failed;
3010 if (PyObject_SetAttrString(result, "arg", value) == -1)
3011 goto failed;
3012 Py_DECREF(value);
3013 value = ast2obj_expr(o->v.SimpleArg.annotation);
3014 if (!value) goto failed;
3015 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3016 goto failed;
3017 Py_DECREF(value);
3018 break;
3019 case NestedArgs_kind:
3020 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
3021 if (!result) goto failed;
3022 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3023 if (!value) goto failed;
3024 if (PyObject_SetAttrString(result, "args", value) == -1)
3025 goto failed;
3026 Py_DECREF(value);
3027 break;
3028 }
3029 return result;
3030failed:
3031 Py_XDECREF(value);
3032 Py_XDECREF(result);
3033 return NULL;
3034}
3035
3036PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003037ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003038{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003039 keyword_ty o = (keyword_ty)_o;
3040 PyObject *result = NULL, *value = NULL;
3041 if (!o) {
3042 Py_INCREF(Py_None);
3043 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003044 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003045
3046 result = PyType_GenericNew(keyword_type, NULL, NULL);
3047 if (!result) return NULL;
3048 value = ast2obj_identifier(o->arg);
3049 if (!value) goto failed;
3050 if (PyObject_SetAttrString(result, "arg", value) == -1)
3051 goto failed;
3052 Py_DECREF(value);
3053 value = ast2obj_expr(o->value);
3054 if (!value) goto failed;
3055 if (PyObject_SetAttrString(result, "value", value) == -1)
3056 goto failed;
3057 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003058 return result;
3059failed:
3060 Py_XDECREF(value);
3061 Py_XDECREF(result);
3062 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003063}
3064
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003065PyObject*
3066ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003067{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003068 alias_ty o = (alias_ty)_o;
3069 PyObject *result = NULL, *value = NULL;
3070 if (!o) {
3071 Py_INCREF(Py_None);
3072 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003073 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003074
3075 result = PyType_GenericNew(alias_type, NULL, NULL);
3076 if (!result) return NULL;
3077 value = ast2obj_identifier(o->name);
3078 if (!value) goto failed;
3079 if (PyObject_SetAttrString(result, "name", value) == -1)
3080 goto failed;
3081 Py_DECREF(value);
3082 value = ast2obj_identifier(o->asname);
3083 if (!value) goto failed;
3084 if (PyObject_SetAttrString(result, "asname", value) == -1)
3085 goto failed;
3086 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003087 return result;
3088failed:
3089 Py_XDECREF(value);
3090 Py_XDECREF(result);
3091 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003092}
3093
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003094
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003095PyMODINIT_FUNC
3096init_ast(void)
3097{
3098 PyObject *m, *d;
3099 if (!init_types()) return;
3100 m = Py_InitModule3("_ast", NULL, NULL);
3101 if (!m) return;
3102 d = PyModule_GetDict(m);
3103 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3104 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3105 return;
Guido van Rossum8981ad02007-04-16 17:02:00 +00003106 if (PyModule_AddStringConstant(m, "__version__", "54835") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003107 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003108 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3109 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3110 return;
3111 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3112 < 0) return;
3113 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3114 0) return;
3115 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3116 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3117 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3118 < 0) return;
3119 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3120 return;
3121 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3122 return;
3123 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3124 return;
3125 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3126 return;
3127 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3128 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003129 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3130 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3131 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3132 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3133 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3134 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3135 0) return;
3136 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3137 0) return;
3138 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3139 return;
3140 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3141 return;
3142 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3143 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003144 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3145 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003146 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3147 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003148 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3149 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3150 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3151 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3152 return;
3153 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3154 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3155 return;
3156 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3157 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3158 return;
3159 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3160 return;
3161 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3162 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003163 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003164 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3165 return;
Nick Coghlan650f0d02007-04-15 12:05:43 +00003166 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
3167 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003168 if (PyDict_SetItemString(d, "GeneratorExp",
3169 (PyObject*)GeneratorExp_type) < 0) return;
3170 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3172 return;
3173 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003174 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3175 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003176 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003177 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3178 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003179 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3180 0) return;
3181 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3182 0) return;
3183 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3184 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3185 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3186 if (PyDict_SetItemString(d, "expr_context",
3187 (PyObject*)expr_context_type) < 0) return;
3188 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3189 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3190 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3191 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3192 return;
3193 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3194 return;
3195 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3196 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003197 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3198 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3199 return;
3200 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3201 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3202 return;
3203 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3204 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3205 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3206 return;
3207 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3208 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3209 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3210 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3211 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3212 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3213 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3214 return;
3215 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3216 return;
3217 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3218 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3219 return;
3220 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3221 return;
3222 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3223 return;
3224 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3225 return;
3226 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3227 return;
3228 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3229 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3230 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3231 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3232 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3233 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3234 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3235 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3236 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3237 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3238 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3239 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3240 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3241 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3242 if (PyDict_SetItemString(d, "comprehension",
3243 (PyObject*)comprehension_type) < 0) return;
3244 if (PyDict_SetItemString(d, "excepthandler",
3245 (PyObject*)excepthandler_type) < 0) return;
3246 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3247 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003248 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3249 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3250 0) return;
3251 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3252 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003253 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3254 return;
3255 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003256}
3257
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003258
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003259PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003260{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003261 init_types();
3262 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003263}
3264
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003265