blob: bcdd56dc897124d22f6d7377cdf2ae520ca33072 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
Guido van Rossum9091e3a2007-03-18 16:10:35 +00005 __version__ 54428.
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};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000195static PyTypeObject *GeneratorExp_type;
196static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000197 "elt",
198 "generators",
199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *Yield_type;
201static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000202 "value",
203};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000204static PyTypeObject *Compare_type;
205static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000206 "left",
207 "ops",
208 "comparators",
209};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000210static PyTypeObject *Call_type;
211static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000212 "func",
213 "args",
214 "keywords",
215 "starargs",
216 "kwargs",
217};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000218static PyTypeObject *Num_type;
219static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000220 "n",
221};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000222static PyTypeObject *Str_type;
223static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000224 "s",
225};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000226static PyTypeObject *Bytes_type;
227static char *Bytes_fields[]={
228 "s",
229};
Georg Brandl52318d62006-09-06 07:06:08 +0000230static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000231static PyTypeObject *Attribute_type;
232static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000233 "value",
234 "attr",
235 "ctx",
236};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000237static PyTypeObject *Subscript_type;
238static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000239 "value",
240 "slice",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Name_type;
244static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "id",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *List_type;
249static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000250 "elts",
251 "ctx",
252};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000253static PyTypeObject *Tuple_type;
254static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255 "elts",
256 "ctx",
257};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000258static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
260*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
261static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000262static PyTypeObject *Load_type;
263static PyTypeObject *Store_type;
264static PyTypeObject *Del_type;
265static PyTypeObject *AugLoad_type;
266static PyTypeObject *AugStore_type;
267static PyTypeObject *Param_type;
268static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000270static PyTypeObject *Slice_type;
271static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000272 "lower",
273 "upper",
274 "step",
275};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000276static PyTypeObject *ExtSlice_type;
277static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000278 "dims",
279};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *Index_type;
281static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000282 "value",
283};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000284static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000285static PyObject *And_singleton, *Or_singleton;
286static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000287static PyTypeObject *And_type;
288static PyTypeObject *Or_type;
289static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000290static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
291*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
292*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
293*FloorDiv_singleton;
294static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000295static PyTypeObject *Add_type;
296static PyTypeObject *Sub_type;
297static PyTypeObject *Mult_type;
298static PyTypeObject *Div_type;
299static PyTypeObject *Mod_type;
300static PyTypeObject *Pow_type;
301static PyTypeObject *LShift_type;
302static PyTypeObject *RShift_type;
303static PyTypeObject *BitOr_type;
304static PyTypeObject *BitXor_type;
305static PyTypeObject *BitAnd_type;
306static PyTypeObject *FloorDiv_type;
307static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000308static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
309*USub_singleton;
310static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Invert_type;
312static PyTypeObject *Not_type;
313static PyTypeObject *UAdd_type;
314static PyTypeObject *USub_type;
315static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000316static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
317*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
318*NotIn_singleton;
319static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000320static PyTypeObject *Eq_type;
321static PyTypeObject *NotEq_type;
322static PyTypeObject *Lt_type;
323static PyTypeObject *LtE_type;
324static PyTypeObject *Gt_type;
325static PyTypeObject *GtE_type;
326static PyTypeObject *Is_type;
327static PyTypeObject *IsNot_type;
328static PyTypeObject *In_type;
329static PyTypeObject *NotIn_type;
330static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000332static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333 "target",
334 "iter",
335 "ifs",
336};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000339static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340 "type",
341 "name",
342 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000343 "lineno",
344 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000345};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000346static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000347static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000348static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000349 "args",
350 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000351 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000352 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000353 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000354 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000355 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000356 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000357};
Neal Norwitzc1505362006-12-28 06:47:50 +0000358static PyTypeObject *arg_type;
359static PyObject* ast2obj_arg(void*);
360static PyTypeObject *SimpleArg_type;
361static char *SimpleArg_fields[]={
362 "arg",
363 "annotation",
364};
365static PyTypeObject *NestedArgs_type;
366static char *NestedArgs_fields[]={
367 "args",
368};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000369static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000370static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000371static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000372 "arg",
373 "value",
374};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000375static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000376static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000377static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000378 "name",
379 "asname",
380};
381
382
383static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
384{
385 PyObject *fnames, *result;
386 int i;
387 if (num_fields) {
388 fnames = PyTuple_New(num_fields);
389 if (!fnames) return NULL;
390 } else {
391 fnames = Py_None;
392 Py_INCREF(Py_None);
393 }
394 for(i=0; i < num_fields; i++) {
395 PyObject *field = PyString_FromString(fields[i]);
396 if (!field) {
397 Py_DECREF(fnames);
398 return NULL;
399 }
400 PyTuple_SET_ITEM(fnames, i, field);
401 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000402 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000403 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000404 Py_DECREF(fnames);
405 return (PyTypeObject*)result;
406}
407
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000408static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
409{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000410 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000411 PyObject *s, *l = PyList_New(num_fields);
412 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000413 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000414 s = PyString_FromString(attrs[i]);
415 if (!s) {
416 Py_DECREF(l);
417 return 0;
418 }
419 PyList_SET_ITEM(l, i, s);
420 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000421 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
422 Py_DECREF(l);
423 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000424}
425
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000426static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
427{
428 int i, n = asdl_seq_LEN(seq);
429 PyObject *result = PyList_New(n);
430 PyObject *value;
431 if (!result)
432 return NULL;
433 for (i = 0; i < n; i++) {
434 value = func(asdl_seq_GET(seq, i));
435 if (!value) {
436 Py_DECREF(result);
437 return NULL;
438 }
439 PyList_SET_ITEM(result, i, value);
440 }
441 return result;
442}
443
444static PyObject* ast2obj_object(void *o)
445{
446 if (!o)
447 o = Py_None;
448 Py_INCREF((PyObject*)o);
449 return (PyObject*)o;
450}
451#define ast2obj_identifier ast2obj_object
452#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000453
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000454static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000455{
456 return PyInt_FromLong(b);
457}
458
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459static int init_types(void)
460{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000461 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000462 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000463 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
464 mod_type = make_type("mod", AST_type, NULL, 0);
465 if (!mod_type) return 0;
466 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Interactive_type = make_type("Interactive", mod_type,
470 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000471 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 Expression_type = make_type("Expression", mod_type, Expression_fields,
473 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!Suite_type) return 0;
477 stmt_type = make_type("stmt", AST_type, NULL, 0);
478 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000479 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000481 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!FunctionDef_type) return 0;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000483 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000484 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000486 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000487 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000488 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000489 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000490 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000499 With_type = make_type("With", stmt_type, With_fields, 3);
500 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
506 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000513 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000514 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000515 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000516 if (!Global_type) return 0;
Jeremy Hylton81e95022007-02-27 06:50:52 +0000517 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
518 if (!Nonlocal_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000519 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000520 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000521 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000523 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000525 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Continue_type) return 0;
527 expr_type = make_type("expr", AST_type, NULL, 0);
528 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000529 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000530 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000532 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000533 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000534 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000535 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000536 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000537 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000538 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000539 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000542 Set_type = make_type("Set", expr_type, Set_fields, 1);
543 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 GeneratorExp_type = make_type("GeneratorExp", expr_type,
547 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000551 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000552 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000554 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000555 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000556 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000557 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000558 if (!Str_type) return 0;
Thomas Wouters00e41de2007-02-23 19:56:57 +0000559 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
560 if (!Bytes_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000561 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
562 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000563 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000564 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000565 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000567 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000569 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000571 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Tuple_type) return 0;
573 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
574 if (!expr_context_type) return 0;
575 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000576 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000577 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000578 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000579 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000580 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000581 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000582 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000583 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000584 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000585 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000586 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000588 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000590 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000592 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000596 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Param_singleton) return 0;
600 slice_type = make_type("slice", AST_type, NULL, 0);
601 if (!slice_type) return 0;
602 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Index_type) return 0;
609 boolop_type = make_type("boolop", AST_type, NULL, 0);
610 if (!boolop_type) return 0;
611 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000612 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000614 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000616 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000618 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000619 if (!Or_singleton) return 0;
620 operator_type = make_type("operator", AST_type, NULL, 0);
621 if (!operator_type) return 0;
622 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000647 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000649 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000651 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000653 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000655 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000656 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000657 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000658 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000659 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000660 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000661 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000662 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000663 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000664 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000665 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000667 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000669 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!FloorDiv_singleton) return 0;
671 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
672 if (!unaryop_type) return 0;
673 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000674 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000676 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000678 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000679 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000680 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000681 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000682 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000683 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000684 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000686 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000688 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!USub_singleton) return 0;
690 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
691 if (!cmpop_type) return 0;
692 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000705 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000707 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000709 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000711 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000713 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000715 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000717 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000718 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000719 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000720 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000721 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000722 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000723 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000724 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000725 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000726 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000727 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000728 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000729 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000730 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000731 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000732 if (!NotIn_singleton) return 0;
733 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000734 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000735 if (!comprehension_type) return 0;
736 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000737 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000738 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000739 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000740 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000741 arg_type = make_type("arg", AST_type, NULL, 0);
742 if (!arg_type) return 0;
743 if (!add_attributes(arg_type, NULL, 0)) return 0;
744 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
745 if (!SimpleArg_type) return 0;
746 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
747 1);
748 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000749 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
750 if (!keyword_type) return 0;
751 alias_type = make_type("alias", AST_type, alias_fields, 2);
752 if (!alias_type) return 0;
753 initialized = 1;
754 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000755}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000756
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000757mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000758Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759{
760 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000761 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000762 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000764 p->kind = Module_kind;
765 p->v.Module.body = body;
766 return p;
767}
768
769mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000770Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771{
772 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000773 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000774 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000776 p->kind = Interactive_kind;
777 p->v.Interactive.body = body;
778 return p;
779}
780
781mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000782Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000783{
784 mod_ty p;
785 if (!body) {
786 PyErr_SetString(PyExc_ValueError,
787 "field body is required for Expression");
788 return NULL;
789 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000790 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000791 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000792 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000793 p->kind = Expression_kind;
794 p->v.Expression.body = body;
795 return p;
796}
797
798mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000799Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800{
801 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000802 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000803 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000805 p->kind = Suite_kind;
806 p->v.Suite.body = body;
807 return p;
808}
809
810stmt_ty
811FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000812 decorators, expr_ty returns, int lineno, int col_offset, PyArena
813 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000814{
815 stmt_ty p;
816 if (!name) {
817 PyErr_SetString(PyExc_ValueError,
818 "field name is required for FunctionDef");
819 return NULL;
820 }
821 if (!args) {
822 PyErr_SetString(PyExc_ValueError,
823 "field args is required for FunctionDef");
824 return NULL;
825 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000826 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000827 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000828 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000829 p->kind = FunctionDef_kind;
830 p->v.FunctionDef.name = name;
831 p->v.FunctionDef.args = args;
832 p->v.FunctionDef.body = body;
833 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000834 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000836 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000837 return p;
838}
839
840stmt_ty
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000841ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
842 starargs, expr_ty kwargs, asdl_seq * body, int lineno, int col_offset,
843 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000844{
845 stmt_ty p;
846 if (!name) {
847 PyErr_SetString(PyExc_ValueError,
848 "field name is required for ClassDef");
849 return NULL;
850 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000851 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000852 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000853 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000854 p->kind = ClassDef_kind;
855 p->v.ClassDef.name = name;
856 p->v.ClassDef.bases = bases;
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000857 p->v.ClassDef.keywords = keywords;
858 p->v.ClassDef.starargs = starargs;
859 p->v.ClassDef.kwargs = kwargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860 p->v.ClassDef.body = body;
861 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000862 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000863 return p;
864}
865
866stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000867Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868{
869 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000870 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000871 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000872 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873 p->kind = Return_kind;
874 p->v.Return.value = value;
875 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000876 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877 return p;
878}
879
880stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882{
883 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000884 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000885 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000886 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887 p->kind = Delete_kind;
888 p->v.Delete.targets = targets;
889 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000890 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000891 return p;
892}
893
894stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000895Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
896 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000897{
898 stmt_ty p;
899 if (!value) {
900 PyErr_SetString(PyExc_ValueError,
901 "field value is required for Assign");
902 return NULL;
903 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000904 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000905 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000906 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000907 p->kind = Assign_kind;
908 p->v.Assign.targets = targets;
909 p->v.Assign.value = value;
910 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000911 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000912 return p;
913}
914
915stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000916AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
917 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000918{
919 stmt_ty p;
920 if (!target) {
921 PyErr_SetString(PyExc_ValueError,
922 "field target is required for AugAssign");
923 return NULL;
924 }
925 if (!op) {
926 PyErr_SetString(PyExc_ValueError,
927 "field op is required for AugAssign");
928 return NULL;
929 }
930 if (!value) {
931 PyErr_SetString(PyExc_ValueError,
932 "field value is required for AugAssign");
933 return NULL;
934 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000935 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000936 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000937 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000938 p->kind = AugAssign_kind;
939 p->v.AugAssign.target = target;
940 p->v.AugAssign.op = op;
941 p->v.AugAssign.value = value;
942 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000943 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000944 return p;
945}
946
947stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000948For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000949 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000950{
951 stmt_ty p;
952 if (!target) {
953 PyErr_SetString(PyExc_ValueError,
954 "field target is required for For");
955 return NULL;
956 }
957 if (!iter) {
958 PyErr_SetString(PyExc_ValueError,
959 "field iter is required for For");
960 return NULL;
961 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000962 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000963 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000965 p->kind = For_kind;
966 p->v.For.target = target;
967 p->v.For.iter = iter;
968 p->v.For.body = body;
969 p->v.For.orelse = orelse;
970 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000971 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000972 return p;
973}
974
975stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000976While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
977 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000978{
979 stmt_ty p;
980 if (!test) {
981 PyErr_SetString(PyExc_ValueError,
982 "field test is required for While");
983 return NULL;
984 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000985 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000986 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000988 p->kind = While_kind;
989 p->v.While.test = test;
990 p->v.While.body = body;
991 p->v.While.orelse = orelse;
992 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000993 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000994 return p;
995}
996
997stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000998If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
999 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001000{
1001 stmt_ty p;
1002 if (!test) {
1003 PyErr_SetString(PyExc_ValueError,
1004 "field test is required for If");
1005 return NULL;
1006 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001007 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001008 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001010 p->kind = If_kind;
1011 p->v.If.test = test;
1012 p->v.If.body = body;
1013 p->v.If.orelse = orelse;
1014 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001015 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001016 return p;
1017}
1018
1019stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001020With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001021 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001022{
1023 stmt_ty p;
1024 if (!context_expr) {
1025 PyErr_SetString(PyExc_ValueError,
1026 "field context_expr is required for With");
1027 return NULL;
1028 }
1029 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001030 if (!p)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001031 return NULL;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001032 p->kind = With_kind;
1033 p->v.With.context_expr = context_expr;
1034 p->v.With.optional_vars = optional_vars;
1035 p->v.With.body = body;
1036 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001037 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001038 return p;
1039}
1040
1041stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001042Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1043 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001044{
1045 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001046 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001047 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001048 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001049 p->kind = Raise_kind;
1050 p->v.Raise.type = type;
1051 p->v.Raise.inst = inst;
1052 p->v.Raise.tback = tback;
1053 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001054 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001055 return p;
1056}
1057
1058stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001059TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001060 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001061{
1062 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001063 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001064 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001065 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001066 p->kind = TryExcept_kind;
1067 p->v.TryExcept.body = body;
1068 p->v.TryExcept.handlers = handlers;
1069 p->v.TryExcept.orelse = orelse;
1070 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001071 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001072 return p;
1073}
1074
1075stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001076TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1077 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001078{
1079 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001080 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001081 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001082 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001083 p->kind = TryFinally_kind;
1084 p->v.TryFinally.body = body;
1085 p->v.TryFinally.finalbody = finalbody;
1086 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001087 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001088 return p;
1089}
1090
1091stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001092Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001093{
1094 stmt_ty p;
1095 if (!test) {
1096 PyErr_SetString(PyExc_ValueError,
1097 "field test is required for Assert");
1098 return NULL;
1099 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001100 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001101 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001102 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001103 p->kind = Assert_kind;
1104 p->v.Assert.test = test;
1105 p->v.Assert.msg = msg;
1106 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001107 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001108 return p;
1109}
1110
1111stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001112Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113{
1114 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001115 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001116 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001117 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118 p->kind = Import_kind;
1119 p->v.Import.names = names;
1120 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001121 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return p;
1123}
1124
1125stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001126ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1127 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128{
1129 stmt_ty p;
1130 if (!module) {
1131 PyErr_SetString(PyExc_ValueError,
1132 "field module is required for ImportFrom");
1133 return NULL;
1134 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001135 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001136 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001138 p->kind = ImportFrom_kind;
1139 p->v.ImportFrom.module = module;
1140 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001141 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001142 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001143 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001144 return p;
1145}
1146
1147stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001148Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149{
1150 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001151 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001152 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001153 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154 p->kind = Global_kind;
1155 p->v.Global.names = names;
1156 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001157 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001158 return p;
1159}
1160
1161stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001162Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1163{
1164 stmt_ty p;
1165 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1166 if (!p)
1167 return NULL;
1168 p->kind = Nonlocal_kind;
1169 p->v.Nonlocal.names = names;
1170 p->lineno = lineno;
1171 p->col_offset = col_offset;
1172 return p;
1173}
1174
1175stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001176Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177{
1178 stmt_ty p;
1179 if (!value) {
1180 PyErr_SetString(PyExc_ValueError,
1181 "field value is required for Expr");
1182 return NULL;
1183 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001184 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001185 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001186 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001187 p->kind = Expr_kind;
1188 p->v.Expr.value = value;
1189 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001190 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 return p;
1192}
1193
1194stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001195Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001196{
1197 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001198 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001199 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201 p->kind = Pass_kind;
1202 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001203 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204 return p;
1205}
1206
1207stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001208Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209{
1210 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001211 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001212 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001213 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214 p->kind = Break_kind;
1215 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001216 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217 return p;
1218}
1219
1220stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001221Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222{
1223 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001224 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001225 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001226 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001227 p->kind = Continue_kind;
1228 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001229 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230 return p;
1231}
1232
1233expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001234BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1235 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236{
1237 expr_ty p;
1238 if (!op) {
1239 PyErr_SetString(PyExc_ValueError,
1240 "field op is required for BoolOp");
1241 return NULL;
1242 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001243 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001244 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001245 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001246 p->kind = BoolOp_kind;
1247 p->v.BoolOp.op = op;
1248 p->v.BoolOp.values = values;
1249 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001250 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001251 return p;
1252}
1253
1254expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001255BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1256 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001257{
1258 expr_ty p;
1259 if (!left) {
1260 PyErr_SetString(PyExc_ValueError,
1261 "field left is required for BinOp");
1262 return NULL;
1263 }
1264 if (!op) {
1265 PyErr_SetString(PyExc_ValueError,
1266 "field op is required for BinOp");
1267 return NULL;
1268 }
1269 if (!right) {
1270 PyErr_SetString(PyExc_ValueError,
1271 "field right is required for BinOp");
1272 return NULL;
1273 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001274 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001275 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001276 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001277 p->kind = BinOp_kind;
1278 p->v.BinOp.left = left;
1279 p->v.BinOp.op = op;
1280 p->v.BinOp.right = right;
1281 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001282 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001283 return p;
1284}
1285
1286expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001287UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1288 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001289{
1290 expr_ty p;
1291 if (!op) {
1292 PyErr_SetString(PyExc_ValueError,
1293 "field op is required for UnaryOp");
1294 return NULL;
1295 }
1296 if (!operand) {
1297 PyErr_SetString(PyExc_ValueError,
1298 "field operand is required for UnaryOp");
1299 return NULL;
1300 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001301 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001302 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001303 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001304 p->kind = UnaryOp_kind;
1305 p->v.UnaryOp.op = op;
1306 p->v.UnaryOp.operand = operand;
1307 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001308 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001309 return p;
1310}
1311
1312expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001313Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1314 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001315{
1316 expr_ty p;
1317 if (!args) {
1318 PyErr_SetString(PyExc_ValueError,
1319 "field args is required for Lambda");
1320 return NULL;
1321 }
1322 if (!body) {
1323 PyErr_SetString(PyExc_ValueError,
1324 "field body is required for Lambda");
1325 return NULL;
1326 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001327 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001328 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001329 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001330 p->kind = Lambda_kind;
1331 p->v.Lambda.args = args;
1332 p->v.Lambda.body = body;
1333 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001334 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001335 return p;
1336}
1337
1338expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001339IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1340 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001341{
1342 expr_ty p;
1343 if (!test) {
1344 PyErr_SetString(PyExc_ValueError,
1345 "field test is required for IfExp");
1346 return NULL;
1347 }
1348 if (!body) {
1349 PyErr_SetString(PyExc_ValueError,
1350 "field body is required for IfExp");
1351 return NULL;
1352 }
1353 if (!orelse) {
1354 PyErr_SetString(PyExc_ValueError,
1355 "field orelse is required for IfExp");
1356 return NULL;
1357 }
1358 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001359 if (!p)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001360 return NULL;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001361 p->kind = IfExp_kind;
1362 p->v.IfExp.test = test;
1363 p->v.IfExp.body = body;
1364 p->v.IfExp.orelse = orelse;
1365 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001366 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001367 return p;
1368}
1369
1370expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001371Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1372 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001373{
1374 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001375 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001376 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001377 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001378 p->kind = Dict_kind;
1379 p->v.Dict.keys = keys;
1380 p->v.Dict.values = values;
1381 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001382 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001383 return p;
1384}
1385
1386expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001387Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1388{
1389 expr_ty p;
1390 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001391 if (!p)
Guido van Rossum86e58e22006-08-28 15:27:34 +00001392 return NULL;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001393 p->kind = Set_kind;
1394 p->v.Set.elts = elts;
1395 p->lineno = lineno;
1396 p->col_offset = col_offset;
1397 return p;
1398}
1399
1400expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001401ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1402 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001403{
1404 expr_ty p;
1405 if (!elt) {
1406 PyErr_SetString(PyExc_ValueError,
1407 "field elt is required for ListComp");
1408 return NULL;
1409 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001410 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001411 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001412 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001413 p->kind = ListComp_kind;
1414 p->v.ListComp.elt = elt;
1415 p->v.ListComp.generators = generators;
1416 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001417 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001418 return p;
1419}
1420
1421expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001422GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1423 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001424{
1425 expr_ty p;
1426 if (!elt) {
1427 PyErr_SetString(PyExc_ValueError,
1428 "field elt is required for GeneratorExp");
1429 return NULL;
1430 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001431 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001432 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001433 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001434 p->kind = GeneratorExp_kind;
1435 p->v.GeneratorExp.elt = elt;
1436 p->v.GeneratorExp.generators = generators;
1437 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001438 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001439 return p;
1440}
1441
1442expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001443Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001444{
1445 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001446 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001447 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001448 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001449 p->kind = Yield_kind;
1450 p->v.Yield.value = value;
1451 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001452 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001453 return p;
1454}
1455
1456expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001457Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1458 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001459{
1460 expr_ty p;
1461 if (!left) {
1462 PyErr_SetString(PyExc_ValueError,
1463 "field left is required for Compare");
1464 return NULL;
1465 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001466 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001467 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001468 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469 p->kind = Compare_kind;
1470 p->v.Compare.left = left;
1471 p->v.Compare.ops = ops;
1472 p->v.Compare.comparators = comparators;
1473 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001474 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475 return p;
1476}
1477
1478expr_ty
1479Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001480 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001481{
1482 expr_ty p;
1483 if (!func) {
1484 PyErr_SetString(PyExc_ValueError,
1485 "field func is required for Call");
1486 return NULL;
1487 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001488 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001489 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001490 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001491 p->kind = Call_kind;
1492 p->v.Call.func = func;
1493 p->v.Call.args = args;
1494 p->v.Call.keywords = keywords;
1495 p->v.Call.starargs = starargs;
1496 p->v.Call.kwargs = kwargs;
1497 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001498 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001499 return p;
1500}
1501
1502expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001503Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001504{
1505 expr_ty p;
1506 if (!n) {
1507 PyErr_SetString(PyExc_ValueError,
1508 "field n is required for Num");
1509 return NULL;
1510 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001511 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001512 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001513 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 p->kind = Num_kind;
1515 p->v.Num.n = n;
1516 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001517 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001518 return p;
1519}
1520
1521expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001522Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001523{
1524 expr_ty p;
1525 if (!s) {
1526 PyErr_SetString(PyExc_ValueError,
1527 "field s is required for Str");
1528 return NULL;
1529 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001530 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001531 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001533 p->kind = Str_kind;
1534 p->v.Str.s = s;
1535 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001536 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001537 return p;
1538}
1539
1540expr_ty
Thomas Wouters00e41de2007-02-23 19:56:57 +00001541Bytes(string s, int lineno, int col_offset, PyArena *arena)
1542{
1543 expr_ty p;
1544 if (!s) {
1545 PyErr_SetString(PyExc_ValueError,
1546 "field s is required for Bytes");
1547 return NULL;
1548 }
1549 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001550 if (!p)
Thomas Wouters00e41de2007-02-23 19:56:57 +00001551 return NULL;
Thomas Wouters00e41de2007-02-23 19:56:57 +00001552 p->kind = Bytes_kind;
1553 p->v.Bytes.s = s;
1554 p->lineno = lineno;
1555 p->col_offset = col_offset;
1556 return p;
1557}
1558
1559expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001560Ellipsis(int lineno, int col_offset, PyArena *arena)
1561{
1562 expr_ty p;
1563 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001564 if (!p)
Georg Brandl52318d62006-09-06 07:06:08 +00001565 return NULL;
Georg Brandl52318d62006-09-06 07:06:08 +00001566 p->kind = Ellipsis_kind;
1567 p->lineno = lineno;
1568 p->col_offset = col_offset;
1569 return p;
1570}
1571
1572expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001573Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1574 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001575{
1576 expr_ty p;
1577 if (!value) {
1578 PyErr_SetString(PyExc_ValueError,
1579 "field value is required for Attribute");
1580 return NULL;
1581 }
1582 if (!attr) {
1583 PyErr_SetString(PyExc_ValueError,
1584 "field attr is required for Attribute");
1585 return NULL;
1586 }
1587 if (!ctx) {
1588 PyErr_SetString(PyExc_ValueError,
1589 "field ctx is required for Attribute");
1590 return NULL;
1591 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001592 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001593 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001595 p->kind = Attribute_kind;
1596 p->v.Attribute.value = value;
1597 p->v.Attribute.attr = attr;
1598 p->v.Attribute.ctx = ctx;
1599 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001600 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001601 return p;
1602}
1603
1604expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001605Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1606 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001607{
1608 expr_ty p;
1609 if (!value) {
1610 PyErr_SetString(PyExc_ValueError,
1611 "field value is required for Subscript");
1612 return NULL;
1613 }
1614 if (!slice) {
1615 PyErr_SetString(PyExc_ValueError,
1616 "field slice is required for Subscript");
1617 return NULL;
1618 }
1619 if (!ctx) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field ctx is required for Subscript");
1622 return NULL;
1623 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001625 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001626 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 p->kind = Subscript_kind;
1628 p->v.Subscript.value = value;
1629 p->v.Subscript.slice = slice;
1630 p->v.Subscript.ctx = ctx;
1631 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001632 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001633 return p;
1634}
1635
1636expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001637Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1638 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001639{
1640 expr_ty p;
1641 if (!id) {
1642 PyErr_SetString(PyExc_ValueError,
1643 "field id is required for Name");
1644 return NULL;
1645 }
1646 if (!ctx) {
1647 PyErr_SetString(PyExc_ValueError,
1648 "field ctx is required for Name");
1649 return NULL;
1650 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001651 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001652 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001654 p->kind = Name_kind;
1655 p->v.Name.id = id;
1656 p->v.Name.ctx = ctx;
1657 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001658 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659 return p;
1660}
1661
1662expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001663List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1664 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001665{
1666 expr_ty p;
1667 if (!ctx) {
1668 PyErr_SetString(PyExc_ValueError,
1669 "field ctx is required for List");
1670 return NULL;
1671 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001672 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001673 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001674 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001675 p->kind = List_kind;
1676 p->v.List.elts = elts;
1677 p->v.List.ctx = ctx;
1678 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001679 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001680 return p;
1681}
1682
1683expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001684Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1685 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001686{
1687 expr_ty p;
1688 if (!ctx) {
1689 PyErr_SetString(PyExc_ValueError,
1690 "field ctx is required for Tuple");
1691 return NULL;
1692 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001693 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001694 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001695 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001696 p->kind = Tuple_kind;
1697 p->v.Tuple.elts = elts;
1698 p->v.Tuple.ctx = ctx;
1699 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001700 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001701 return p;
1702}
1703
1704slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001705Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706{
1707 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001708 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001709 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001710 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001711 p->kind = Slice_kind;
1712 p->v.Slice.lower = lower;
1713 p->v.Slice.upper = upper;
1714 p->v.Slice.step = step;
1715 return p;
1716}
1717
1718slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001719ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720{
1721 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001722 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001723 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001724 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725 p->kind = ExtSlice_kind;
1726 p->v.ExtSlice.dims = dims;
1727 return p;
1728}
1729
1730slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001731Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001732{
1733 slice_ty p;
1734 if (!value) {
1735 PyErr_SetString(PyExc_ValueError,
1736 "field value is required for Index");
1737 return NULL;
1738 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001739 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001740 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001741 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742 p->kind = Index_kind;
1743 p->v.Index.value = value;
1744 return p;
1745}
1746
1747comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001748comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001749{
1750 comprehension_ty p;
1751 if (!target) {
1752 PyErr_SetString(PyExc_ValueError,
1753 "field target is required for comprehension");
1754 return NULL;
1755 }
1756 if (!iter) {
1757 PyErr_SetString(PyExc_ValueError,
1758 "field iter is required for comprehension");
1759 return NULL;
1760 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001761 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001762 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001764 p->target = target;
1765 p->iter = iter;
1766 p->ifs = ifs;
1767 return p;
1768}
1769
1770excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001771excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001772 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001773{
1774 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001775 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001776 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001777 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 p->type = type;
1779 p->name = name;
1780 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001781 p->lineno = lineno;
1782 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001783 return p;
1784}
1785
1786arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001787arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1788 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1789 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001790{
1791 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001792 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001793 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001795 p->args = args;
1796 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001797 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001798 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001799 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001800 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001801 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001802 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803 return p;
1804}
1805
Neal Norwitzc1505362006-12-28 06:47:50 +00001806arg_ty
1807SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1808{
1809 arg_ty p;
1810 if (!arg) {
1811 PyErr_SetString(PyExc_ValueError,
1812 "field arg is required for SimpleArg");
1813 return NULL;
1814 }
1815 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001816 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001817 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001818 p->kind = SimpleArg_kind;
1819 p->v.SimpleArg.arg = arg;
1820 p->v.SimpleArg.annotation = annotation;
1821 return p;
1822}
1823
1824arg_ty
1825NestedArgs(asdl_seq * args, PyArena *arena)
1826{
1827 arg_ty p;
1828 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001829 if (!p)
Neal Norwitzc1505362006-12-28 06:47:50 +00001830 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00001831 p->kind = NestedArgs_kind;
1832 p->v.NestedArgs.args = args;
1833 return p;
1834}
1835
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001836keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001837keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001838{
1839 keyword_ty p;
1840 if (!arg) {
1841 PyErr_SetString(PyExc_ValueError,
1842 "field arg is required for keyword");
1843 return NULL;
1844 }
1845 if (!value) {
1846 PyErr_SetString(PyExc_ValueError,
1847 "field value is required for keyword");
1848 return NULL;
1849 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001850 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001851 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001852 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 p->arg = arg;
1854 p->value = value;
1855 return p;
1856}
1857
1858alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001859alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001860{
1861 alias_ty p;
1862 if (!name) {
1863 PyErr_SetString(PyExc_ValueError,
1864 "field name is required for alias");
1865 return NULL;
1866 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001867 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001868 if (!p)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001869 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870 p->name = name;
1871 p->asname = asname;
1872 return p;
1873}
1874
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001875
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001876PyObject*
1877ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001878{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001879 mod_ty o = (mod_ty)_o;
1880 PyObject *result = NULL, *value = NULL;
1881 if (!o) {
1882 Py_INCREF(Py_None);
1883 return Py_None;
1884 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001885
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886 switch (o->kind) {
1887 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001888 result = PyType_GenericNew(Module_type, NULL, NULL);
1889 if (!result) goto failed;
1890 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1891 if (!value) goto failed;
1892 if (PyObject_SetAttrString(result, "body", value) == -1)
1893 goto failed;
1894 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001895 break;
1896 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001897 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1898 if (!result) goto failed;
1899 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1900 if (!value) goto failed;
1901 if (PyObject_SetAttrString(result, "body", value) == -1)
1902 goto failed;
1903 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001904 break;
1905 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001906 result = PyType_GenericNew(Expression_type, NULL, NULL);
1907 if (!result) goto failed;
1908 value = ast2obj_expr(o->v.Expression.body);
1909 if (!value) goto failed;
1910 if (PyObject_SetAttrString(result, "body", value) == -1)
1911 goto failed;
1912 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913 break;
1914 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001915 result = PyType_GenericNew(Suite_type, NULL, NULL);
1916 if (!result) goto failed;
1917 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1918 if (!value) goto failed;
1919 if (PyObject_SetAttrString(result, "body", value) == -1)
1920 goto failed;
1921 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001922 break;
1923 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001924 return result;
1925failed:
1926 Py_XDECREF(value);
1927 Py_XDECREF(result);
1928 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001929}
1930
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001931PyObject*
1932ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001933{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001934 stmt_ty o = (stmt_ty)_o;
1935 PyObject *result = NULL, *value = NULL;
1936 if (!o) {
1937 Py_INCREF(Py_None);
1938 return Py_None;
1939 }
1940
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 switch (o->kind) {
1942 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001943 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1944 if (!result) goto failed;
1945 value = ast2obj_identifier(o->v.FunctionDef.name);
1946 if (!value) goto failed;
1947 if (PyObject_SetAttrString(result, "name", value) == -1)
1948 goto failed;
1949 Py_DECREF(value);
1950 value = ast2obj_arguments(o->v.FunctionDef.args);
1951 if (!value) goto failed;
1952 if (PyObject_SetAttrString(result, "args", value) == -1)
1953 goto failed;
1954 Py_DECREF(value);
1955 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1956 if (!value) goto failed;
1957 if (PyObject_SetAttrString(result, "body", value) == -1)
1958 goto failed;
1959 Py_DECREF(value);
1960 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00001965 value = ast2obj_expr(o->v.FunctionDef.returns);
1966 if (!value) goto failed;
1967 if (PyObject_SetAttrString(result, "returns", value) == -1)
1968 goto failed;
1969 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001970 break;
1971 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001972 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1973 if (!result) goto failed;
1974 value = ast2obj_identifier(o->v.ClassDef.name);
1975 if (!value) goto failed;
1976 if (PyObject_SetAttrString(result, "name", value) == -1)
1977 goto failed;
1978 Py_DECREF(value);
1979 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "bases", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Guido van Rossum52cc1d82007-03-18 15:41:51 +00001984 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
1985 if (!value) goto failed;
1986 if (PyObject_SetAttrString(result, "keywords", value) == -1)
1987 goto failed;
1988 Py_DECREF(value);
1989 value = ast2obj_expr(o->v.ClassDef.starargs);
1990 if (!value) goto failed;
1991 if (PyObject_SetAttrString(result, "starargs", value) == -1)
1992 goto failed;
1993 Py_DECREF(value);
1994 value = ast2obj_expr(o->v.ClassDef.kwargs);
1995 if (!value) goto failed;
1996 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
1997 goto failed;
1998 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001999 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2000 if (!value) goto failed;
2001 if (PyObject_SetAttrString(result, "body", value) == -1)
2002 goto failed;
2003 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002004 break;
2005 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002006 result = PyType_GenericNew(Return_type, NULL, NULL);
2007 if (!result) goto failed;
2008 value = ast2obj_expr(o->v.Return.value);
2009 if (!value) goto failed;
2010 if (PyObject_SetAttrString(result, "value", value) == -1)
2011 goto failed;
2012 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002013 break;
2014 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002015 result = PyType_GenericNew(Delete_type, NULL, NULL);
2016 if (!result) goto failed;
2017 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "targets", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002022 break;
2023 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002024 result = PyType_GenericNew(Assign_type, NULL, NULL);
2025 if (!result) goto failed;
2026 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "targets", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
2031 value = ast2obj_expr(o->v.Assign.value);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "value", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002036 break;
2037 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002038 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2039 if (!result) goto failed;
2040 value = ast2obj_expr(o->v.AugAssign.target);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "target", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
2045 value = ast2obj_operator(o->v.AugAssign.op);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "op", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
2050 value = ast2obj_expr(o->v.AugAssign.value);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "value", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002055 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002056 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002057 result = PyType_GenericNew(For_type, NULL, NULL);
2058 if (!result) goto failed;
2059 value = ast2obj_expr(o->v.For.target);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "target", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
2064 value = ast2obj_expr(o->v.For.iter);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "iter", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
2069 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2070 if (!value) goto failed;
2071 if (PyObject_SetAttrString(result, "body", value) == -1)
2072 goto failed;
2073 Py_DECREF(value);
2074 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2075 if (!value) goto failed;
2076 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2077 goto failed;
2078 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002079 break;
2080 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002081 result = PyType_GenericNew(While_type, NULL, NULL);
2082 if (!result) goto failed;
2083 value = ast2obj_expr(o->v.While.test);
2084 if (!value) goto failed;
2085 if (PyObject_SetAttrString(result, "test", value) == -1)
2086 goto failed;
2087 Py_DECREF(value);
2088 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "body", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
2093 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2094 if (!value) goto failed;
2095 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2096 goto failed;
2097 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002098 break;
2099 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002100 result = PyType_GenericNew(If_type, NULL, NULL);
2101 if (!result) goto failed;
2102 value = ast2obj_expr(o->v.If.test);
2103 if (!value) goto failed;
2104 if (PyObject_SetAttrString(result, "test", value) == -1)
2105 goto failed;
2106 Py_DECREF(value);
2107 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "body", value) == -1)
2110 goto failed;
2111 Py_DECREF(value);
2112 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2113 if (!value) goto failed;
2114 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2115 goto failed;
2116 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002117 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002118 case With_kind:
2119 result = PyType_GenericNew(With_type, NULL, NULL);
2120 if (!result) goto failed;
2121 value = ast2obj_expr(o->v.With.context_expr);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
2126 value = ast2obj_expr(o->v.With.optional_vars);
2127 if (!value) goto failed;
2128 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2129 -1)
2130 goto failed;
2131 Py_DECREF(value);
2132 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "body", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
2137 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002138 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002139 result = PyType_GenericNew(Raise_type, NULL, NULL);
2140 if (!result) goto failed;
2141 value = ast2obj_expr(o->v.Raise.type);
2142 if (!value) goto failed;
2143 if (PyObject_SetAttrString(result, "type", value) == -1)
2144 goto failed;
2145 Py_DECREF(value);
2146 value = ast2obj_expr(o->v.Raise.inst);
2147 if (!value) goto failed;
2148 if (PyObject_SetAttrString(result, "inst", value) == -1)
2149 goto failed;
2150 Py_DECREF(value);
2151 value = ast2obj_expr(o->v.Raise.tback);
2152 if (!value) goto failed;
2153 if (PyObject_SetAttrString(result, "tback", value) == -1)
2154 goto failed;
2155 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002156 break;
2157 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002158 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2159 if (!result) goto failed;
2160 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2161 if (!value) goto failed;
2162 if (PyObject_SetAttrString(result, "body", value) == -1)
2163 goto failed;
2164 Py_DECREF(value);
2165 value = ast2obj_list(o->v.TryExcept.handlers,
2166 ast2obj_excepthandler);
2167 if (!value) goto failed;
2168 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2169 goto failed;
2170 Py_DECREF(value);
2171 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2172 if (!value) goto failed;
2173 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2174 goto failed;
2175 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002176 break;
2177 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002178 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2179 if (!result) goto failed;
2180 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2181 if (!value) goto failed;
2182 if (PyObject_SetAttrString(result, "body", value) == -1)
2183 goto failed;
2184 Py_DECREF(value);
2185 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002190 break;
2191 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002192 result = PyType_GenericNew(Assert_type, NULL, NULL);
2193 if (!result) goto failed;
2194 value = ast2obj_expr(o->v.Assert.test);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "test", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 value = ast2obj_expr(o->v.Assert.msg);
2200 if (!value) goto failed;
2201 if (PyObject_SetAttrString(result, "msg", value) == -1)
2202 goto failed;
2203 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002204 break;
2205 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002206 result = PyType_GenericNew(Import_type, NULL, NULL);
2207 if (!result) goto failed;
2208 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "names", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002213 break;
2214 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002215 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2216 if (!result) goto failed;
2217 value = ast2obj_identifier(o->v.ImportFrom.module);
2218 if (!value) goto failed;
2219 if (PyObject_SetAttrString(result, "module", value) == -1)
2220 goto failed;
2221 Py_DECREF(value);
2222 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "names", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002227 value = ast2obj_int(o->v.ImportFrom.level);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "level", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002232 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002233 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002234 result = PyType_GenericNew(Global_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
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;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002242 case Nonlocal_kind:
2243 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
2244 if (!result) goto failed;
2245 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "names", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
2250 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002252 result = PyType_GenericNew(Expr_type, NULL, NULL);
2253 if (!result) goto failed;
2254 value = ast2obj_expr(o->v.Expr.value);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "value", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259 break;
2260 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002261 result = PyType_GenericNew(Pass_type, NULL, NULL);
2262 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002263 break;
2264 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002265 result = PyType_GenericNew(Break_type, NULL, NULL);
2266 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002267 break;
2268 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002269 result = PyType_GenericNew(Continue_type, NULL, NULL);
2270 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002271 break;
2272 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002273 value = ast2obj_int(o->lineno);
2274 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002275 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2276 goto failed;
2277 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002278 value = ast2obj_int(o->col_offset);
2279 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002280 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2281 goto failed;
2282 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002283 return result;
2284failed:
2285 Py_XDECREF(value);
2286 Py_XDECREF(result);
2287 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288}
2289
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002290PyObject*
2291ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002292{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002293 expr_ty o = (expr_ty)_o;
2294 PyObject *result = NULL, *value = NULL;
2295 if (!o) {
2296 Py_INCREF(Py_None);
2297 return Py_None;
2298 }
2299
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002300 switch (o->kind) {
2301 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002302 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2303 if (!result) goto failed;
2304 value = ast2obj_boolop(o->v.BoolOp.op);
2305 if (!value) goto failed;
2306 if (PyObject_SetAttrString(result, "op", value) == -1)
2307 goto failed;
2308 Py_DECREF(value);
2309 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "values", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002314 break;
2315 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002316 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2317 if (!result) goto failed;
2318 value = ast2obj_expr(o->v.BinOp.left);
2319 if (!value) goto failed;
2320 if (PyObject_SetAttrString(result, "left", value) == -1)
2321 goto failed;
2322 Py_DECREF(value);
2323 value = ast2obj_operator(o->v.BinOp.op);
2324 if (!value) goto failed;
2325 if (PyObject_SetAttrString(result, "op", value) == -1)
2326 goto failed;
2327 Py_DECREF(value);
2328 value = ast2obj_expr(o->v.BinOp.right);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "right", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002333 break;
2334 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002335 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2336 if (!result) goto failed;
2337 value = ast2obj_unaryop(o->v.UnaryOp.op);
2338 if (!value) goto failed;
2339 if (PyObject_SetAttrString(result, "op", value) == -1)
2340 goto failed;
2341 Py_DECREF(value);
2342 value = ast2obj_expr(o->v.UnaryOp.operand);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "operand", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002347 break;
2348 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002349 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2350 if (!result) goto failed;
2351 value = ast2obj_arguments(o->v.Lambda.args);
2352 if (!value) goto failed;
2353 if (PyObject_SetAttrString(result, "args", value) == -1)
2354 goto failed;
2355 Py_DECREF(value);
2356 value = ast2obj_expr(o->v.Lambda.body);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "body", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002361 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002362 case IfExp_kind:
2363 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2364 if (!result) goto failed;
2365 value = ast2obj_expr(o->v.IfExp.test);
2366 if (!value) goto failed;
2367 if (PyObject_SetAttrString(result, "test", value) == -1)
2368 goto failed;
2369 Py_DECREF(value);
2370 value = ast2obj_expr(o->v.IfExp.body);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "body", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
2375 value = ast2obj_expr(o->v.IfExp.orelse);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002381 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002382 result = PyType_GenericNew(Dict_type, NULL, NULL);
2383 if (!result) goto failed;
2384 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2385 if (!value) goto failed;
2386 if (PyObject_SetAttrString(result, "keys", value) == -1)
2387 goto failed;
2388 Py_DECREF(value);
2389 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "values", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002394 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002395 case Set_kind:
2396 result = PyType_GenericNew(Set_type, NULL, NULL);
2397 if (!result) goto failed;
2398 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "elts", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002404 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002405 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2406 if (!result) goto failed;
2407 value = ast2obj_expr(o->v.ListComp.elt);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "elt", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
2412 value = ast2obj_list(o->v.ListComp.generators,
2413 ast2obj_comprehension);
2414 if (!value) goto failed;
2415 if (PyObject_SetAttrString(result, "generators", value) == -1)
2416 goto failed;
2417 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002418 break;
2419 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002420 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2421 if (!result) goto failed;
2422 value = ast2obj_expr(o->v.GeneratorExp.elt);
2423 if (!value) goto failed;
2424 if (PyObject_SetAttrString(result, "elt", value) == -1)
2425 goto failed;
2426 Py_DECREF(value);
2427 value = ast2obj_list(o->v.GeneratorExp.generators,
2428 ast2obj_comprehension);
2429 if (!value) goto failed;
2430 if (PyObject_SetAttrString(result, "generators", value) == -1)
2431 goto failed;
2432 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002433 break;
2434 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002435 result = PyType_GenericNew(Yield_type, NULL, NULL);
2436 if (!result) goto failed;
2437 value = ast2obj_expr(o->v.Yield.value);
2438 if (!value) goto failed;
2439 if (PyObject_SetAttrString(result, "value", value) == -1)
2440 goto failed;
2441 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 break;
2443 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002444 result = PyType_GenericNew(Compare_type, NULL, NULL);
2445 if (!result) goto failed;
2446 value = ast2obj_expr(o->v.Compare.left);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "left", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002451 {
2452 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2453 value = PyList_New(n);
2454 if (!value) goto failed;
2455 for(i = 0; i < n; i++)
2456 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2457 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002458 if (!value) goto failed;
2459 if (PyObject_SetAttrString(result, "ops", value) == -1)
2460 goto failed;
2461 Py_DECREF(value);
2462 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2463 if (!value) goto failed;
2464 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2465 goto failed;
2466 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002467 break;
2468 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002469 result = PyType_GenericNew(Call_type, NULL, NULL);
2470 if (!result) goto failed;
2471 value = ast2obj_expr(o->v.Call.func);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "func", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
2476 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2477 if (!value) goto failed;
2478 if (PyObject_SetAttrString(result, "args", value) == -1)
2479 goto failed;
2480 Py_DECREF(value);
2481 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 value = ast2obj_expr(o->v.Call.starargs);
2487 if (!value) goto failed;
2488 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2489 goto failed;
2490 Py_DECREF(value);
2491 value = ast2obj_expr(o->v.Call.kwargs);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002497 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002498 result = PyType_GenericNew(Num_type, NULL, NULL);
2499 if (!result) goto failed;
2500 value = ast2obj_object(o->v.Num.n);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "n", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505 break;
2506 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Str_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_string(o->v.Str.s);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "s", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002514 break;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002515 case Bytes_kind:
2516 result = PyType_GenericNew(Bytes_type, NULL, NULL);
2517 if (!result) goto failed;
2518 value = ast2obj_string(o->v.Bytes.s);
2519 if (!value) goto failed;
2520 if (PyObject_SetAttrString(result, "s", value) == -1)
2521 goto failed;
2522 Py_DECREF(value);
2523 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002524 case Ellipsis_kind:
2525 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2526 if (!result) goto failed;
2527 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002529 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2530 if (!result) goto failed;
2531 value = ast2obj_expr(o->v.Attribute.value);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "value", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_identifier(o->v.Attribute.attr);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "attr", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 value = ast2obj_expr_context(o->v.Attribute.ctx);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002546 break;
2547 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002548 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2549 if (!result) goto failed;
2550 value = ast2obj_expr(o->v.Subscript.value);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "value", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
2555 value = ast2obj_slice(o->v.Subscript.slice);
2556 if (!value) goto failed;
2557 if (PyObject_SetAttrString(result, "slice", value) == -1)
2558 goto failed;
2559 Py_DECREF(value);
2560 value = ast2obj_expr_context(o->v.Subscript.ctx);
2561 if (!value) goto failed;
2562 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2563 goto failed;
2564 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002565 break;
2566 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002567 result = PyType_GenericNew(Name_type, NULL, NULL);
2568 if (!result) goto failed;
2569 value = ast2obj_identifier(o->v.Name.id);
2570 if (!value) goto failed;
2571 if (PyObject_SetAttrString(result, "id", value) == -1)
2572 goto failed;
2573 Py_DECREF(value);
2574 value = ast2obj_expr_context(o->v.Name.ctx);
2575 if (!value) goto failed;
2576 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2577 goto failed;
2578 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002579 break;
2580 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002581 result = PyType_GenericNew(List_type, NULL, NULL);
2582 if (!result) goto failed;
2583 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2584 if (!value) goto failed;
2585 if (PyObject_SetAttrString(result, "elts", value) == -1)
2586 goto failed;
2587 Py_DECREF(value);
2588 value = ast2obj_expr_context(o->v.List.ctx);
2589 if (!value) goto failed;
2590 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2591 goto failed;
2592 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002593 break;
2594 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002595 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2596 if (!result) goto failed;
2597 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2598 if (!value) goto failed;
2599 if (PyObject_SetAttrString(result, "elts", value) == -1)
2600 goto failed;
2601 Py_DECREF(value);
2602 value = ast2obj_expr_context(o->v.Tuple.ctx);
2603 if (!value) goto failed;
2604 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2605 goto failed;
2606 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002607 break;
2608 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002609 value = ast2obj_int(o->lineno);
2610 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002611 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2612 goto failed;
2613 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002614 value = ast2obj_int(o->col_offset);
2615 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002616 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2617 goto failed;
2618 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002619 return result;
2620failed:
2621 Py_XDECREF(value);
2622 Py_XDECREF(result);
2623 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002624}
2625
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002626PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002627{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002628 switch(o) {
2629 case Load:
2630 Py_INCREF(Load_singleton);
2631 return Load_singleton;
2632 case Store:
2633 Py_INCREF(Store_singleton);
2634 return Store_singleton;
2635 case Del:
2636 Py_INCREF(Del_singleton);
2637 return Del_singleton;
2638 case AugLoad:
2639 Py_INCREF(AugLoad_singleton);
2640 return AugLoad_singleton;
2641 case AugStore:
2642 Py_INCREF(AugStore_singleton);
2643 return AugStore_singleton;
2644 case Param:
2645 Py_INCREF(Param_singleton);
2646 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002649}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002650PyObject*
2651ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002652{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002653 slice_ty o = (slice_ty)_o;
2654 PyObject *result = NULL, *value = NULL;
2655 if (!o) {
2656 Py_INCREF(Py_None);
2657 return Py_None;
2658 }
2659
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002660 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002661 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002662 result = PyType_GenericNew(Slice_type, NULL, NULL);
2663 if (!result) goto failed;
2664 value = ast2obj_expr(o->v.Slice.lower);
2665 if (!value) goto failed;
2666 if (PyObject_SetAttrString(result, "lower", value) == -1)
2667 goto failed;
2668 Py_DECREF(value);
2669 value = ast2obj_expr(o->v.Slice.upper);
2670 if (!value) goto failed;
2671 if (PyObject_SetAttrString(result, "upper", value) == -1)
2672 goto failed;
2673 Py_DECREF(value);
2674 value = ast2obj_expr(o->v.Slice.step);
2675 if (!value) goto failed;
2676 if (PyObject_SetAttrString(result, "step", value) == -1)
2677 goto failed;
2678 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002679 break;
2680 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002681 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2682 if (!result) goto failed;
2683 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2684 if (!value) goto failed;
2685 if (PyObject_SetAttrString(result, "dims", value) == -1)
2686 goto failed;
2687 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688 break;
2689 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002690 result = PyType_GenericNew(Index_type, NULL, NULL);
2691 if (!result) goto failed;
2692 value = ast2obj_expr(o->v.Index.value);
2693 if (!value) goto failed;
2694 if (PyObject_SetAttrString(result, "value", value) == -1)
2695 goto failed;
2696 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002697 break;
2698 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002699 return result;
2700failed:
2701 Py_XDECREF(value);
2702 Py_XDECREF(result);
2703 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002704}
2705
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002706PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002707{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002708 switch(o) {
2709 case And:
2710 Py_INCREF(And_singleton);
2711 return And_singleton;
2712 case Or:
2713 Py_INCREF(Or_singleton);
2714 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002716 return NULL; /* cannot happen */
2717}
2718PyObject* ast2obj_operator(operator_ty o)
2719{
2720 switch(o) {
2721 case Add:
2722 Py_INCREF(Add_singleton);
2723 return Add_singleton;
2724 case Sub:
2725 Py_INCREF(Sub_singleton);
2726 return Sub_singleton;
2727 case Mult:
2728 Py_INCREF(Mult_singleton);
2729 return Mult_singleton;
2730 case Div:
2731 Py_INCREF(Div_singleton);
2732 return Div_singleton;
2733 case Mod:
2734 Py_INCREF(Mod_singleton);
2735 return Mod_singleton;
2736 case Pow:
2737 Py_INCREF(Pow_singleton);
2738 return Pow_singleton;
2739 case LShift:
2740 Py_INCREF(LShift_singleton);
2741 return LShift_singleton;
2742 case RShift:
2743 Py_INCREF(RShift_singleton);
2744 return RShift_singleton;
2745 case BitOr:
2746 Py_INCREF(BitOr_singleton);
2747 return BitOr_singleton;
2748 case BitXor:
2749 Py_INCREF(BitXor_singleton);
2750 return BitXor_singleton;
2751 case BitAnd:
2752 Py_INCREF(BitAnd_singleton);
2753 return BitAnd_singleton;
2754 case FloorDiv:
2755 Py_INCREF(FloorDiv_singleton);
2756 return FloorDiv_singleton;
2757 }
2758 return NULL; /* cannot happen */
2759}
2760PyObject* ast2obj_unaryop(unaryop_ty o)
2761{
2762 switch(o) {
2763 case Invert:
2764 Py_INCREF(Invert_singleton);
2765 return Invert_singleton;
2766 case Not:
2767 Py_INCREF(Not_singleton);
2768 return Not_singleton;
2769 case UAdd:
2770 Py_INCREF(UAdd_singleton);
2771 return UAdd_singleton;
2772 case USub:
2773 Py_INCREF(USub_singleton);
2774 return USub_singleton;
2775 }
2776 return NULL; /* cannot happen */
2777}
2778PyObject* ast2obj_cmpop(cmpop_ty o)
2779{
2780 switch(o) {
2781 case Eq:
2782 Py_INCREF(Eq_singleton);
2783 return Eq_singleton;
2784 case NotEq:
2785 Py_INCREF(NotEq_singleton);
2786 return NotEq_singleton;
2787 case Lt:
2788 Py_INCREF(Lt_singleton);
2789 return Lt_singleton;
2790 case LtE:
2791 Py_INCREF(LtE_singleton);
2792 return LtE_singleton;
2793 case Gt:
2794 Py_INCREF(Gt_singleton);
2795 return Gt_singleton;
2796 case GtE:
2797 Py_INCREF(GtE_singleton);
2798 return GtE_singleton;
2799 case Is:
2800 Py_INCREF(Is_singleton);
2801 return Is_singleton;
2802 case IsNot:
2803 Py_INCREF(IsNot_singleton);
2804 return IsNot_singleton;
2805 case In:
2806 Py_INCREF(In_singleton);
2807 return In_singleton;
2808 case NotIn:
2809 Py_INCREF(NotIn_singleton);
2810 return NotIn_singleton;
2811 }
2812 return NULL; /* cannot happen */
2813}
2814PyObject*
2815ast2obj_comprehension(void* _o)
2816{
2817 comprehension_ty o = (comprehension_ty)_o;
2818 PyObject *result = NULL, *value = NULL;
2819 if (!o) {
2820 Py_INCREF(Py_None);
2821 return Py_None;
2822 }
2823
2824 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2825 if (!result) return NULL;
2826 value = ast2obj_expr(o->target);
2827 if (!value) goto failed;
2828 if (PyObject_SetAttrString(result, "target", value) == -1)
2829 goto failed;
2830 Py_DECREF(value);
2831 value = ast2obj_expr(o->iter);
2832 if (!value) goto failed;
2833 if (PyObject_SetAttrString(result, "iter", value) == -1)
2834 goto failed;
2835 Py_DECREF(value);
2836 value = ast2obj_list(o->ifs, ast2obj_expr);
2837 if (!value) goto failed;
2838 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2839 goto failed;
2840 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002841 return result;
2842failed:
2843 Py_XDECREF(value);
2844 Py_XDECREF(result);
2845 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002846}
2847
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002848PyObject*
2849ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002850{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002851 excepthandler_ty o = (excepthandler_ty)_o;
2852 PyObject *result = NULL, *value = NULL;
2853 if (!o) {
2854 Py_INCREF(Py_None);
2855 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002856 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002857
2858 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2859 if (!result) return NULL;
2860 value = ast2obj_expr(o->type);
2861 if (!value) goto failed;
2862 if (PyObject_SetAttrString(result, "type", value) == -1)
2863 goto failed;
2864 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002865 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002866 if (!value) goto failed;
2867 if (PyObject_SetAttrString(result, "name", value) == -1)
2868 goto failed;
2869 Py_DECREF(value);
2870 value = ast2obj_list(o->body, ast2obj_stmt);
2871 if (!value) goto failed;
2872 if (PyObject_SetAttrString(result, "body", value) == -1)
2873 goto failed;
2874 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002875 value = ast2obj_int(o->lineno);
2876 if (!value) goto failed;
2877 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2878 goto failed;
2879 Py_DECREF(value);
2880 value = ast2obj_int(o->col_offset);
2881 if (!value) goto failed;
2882 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2883 goto failed;
2884 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002885 return result;
2886failed:
2887 Py_XDECREF(value);
2888 Py_XDECREF(result);
2889 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002890}
2891
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002892PyObject*
2893ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002894{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002895 arguments_ty o = (arguments_ty)_o;
2896 PyObject *result = NULL, *value = NULL;
2897 if (!o) {
2898 Py_INCREF(Py_None);
2899 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002900 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002901
2902 result = PyType_GenericNew(arguments_type, NULL, NULL);
2903 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002904 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002905 if (!value) goto failed;
2906 if (PyObject_SetAttrString(result, "args", value) == -1)
2907 goto failed;
2908 Py_DECREF(value);
2909 value = ast2obj_identifier(o->vararg);
2910 if (!value) goto failed;
2911 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2912 goto failed;
2913 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002914 value = ast2obj_expr(o->varargannotation);
2915 if (!value) goto failed;
2916 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2917 goto failed;
2918 Py_DECREF(value);
2919 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002920 if (!value) goto failed;
2921 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2922 goto failed;
2923 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002924 value = ast2obj_identifier(o->kwarg);
2925 if (!value) goto failed;
2926 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2927 goto failed;
2928 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002929 value = ast2obj_expr(o->kwargannotation);
2930 if (!value) goto failed;
2931 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2932 goto failed;
2933 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934 value = ast2obj_list(o->defaults, ast2obj_expr);
2935 if (!value) goto failed;
2936 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2937 goto failed;
2938 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002939 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2940 if (!value) goto failed;
2941 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2942 goto failed;
2943 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002944 return result;
2945failed:
2946 Py_XDECREF(value);
2947 Py_XDECREF(result);
2948 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002949}
2950
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002952ast2obj_arg(void* _o)
2953{
2954 arg_ty o = (arg_ty)_o;
2955 PyObject *result = NULL, *value = NULL;
2956 if (!o) {
2957 Py_INCREF(Py_None);
2958 return Py_None;
2959 }
2960
2961 switch (o->kind) {
2962 case SimpleArg_kind:
2963 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2964 if (!result) goto failed;
2965 value = ast2obj_identifier(o->v.SimpleArg.arg);
2966 if (!value) goto failed;
2967 if (PyObject_SetAttrString(result, "arg", value) == -1)
2968 goto failed;
2969 Py_DECREF(value);
2970 value = ast2obj_expr(o->v.SimpleArg.annotation);
2971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "annotation", value) == -1)
2973 goto failed;
2974 Py_DECREF(value);
2975 break;
2976 case NestedArgs_kind:
2977 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
2978 if (!result) goto failed;
2979 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
2980 if (!value) goto failed;
2981 if (PyObject_SetAttrString(result, "args", value) == -1)
2982 goto failed;
2983 Py_DECREF(value);
2984 break;
2985 }
2986 return result;
2987failed:
2988 Py_XDECREF(value);
2989 Py_XDECREF(result);
2990 return NULL;
2991}
2992
2993PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002994ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002995{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002996 keyword_ty o = (keyword_ty)_o;
2997 PyObject *result = NULL, *value = NULL;
2998 if (!o) {
2999 Py_INCREF(Py_None);
3000 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003001 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003002
3003 result = PyType_GenericNew(keyword_type, NULL, NULL);
3004 if (!result) return NULL;
3005 value = ast2obj_identifier(o->arg);
3006 if (!value) goto failed;
3007 if (PyObject_SetAttrString(result, "arg", value) == -1)
3008 goto failed;
3009 Py_DECREF(value);
3010 value = ast2obj_expr(o->value);
3011 if (!value) goto failed;
3012 if (PyObject_SetAttrString(result, "value", value) == -1)
3013 goto failed;
3014 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003015 return result;
3016failed:
3017 Py_XDECREF(value);
3018 Py_XDECREF(result);
3019 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003020}
3021
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003022PyObject*
3023ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003024{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003025 alias_ty o = (alias_ty)_o;
3026 PyObject *result = NULL, *value = NULL;
3027 if (!o) {
3028 Py_INCREF(Py_None);
3029 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003030 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003031
3032 result = PyType_GenericNew(alias_type, NULL, NULL);
3033 if (!result) return NULL;
3034 value = ast2obj_identifier(o->name);
3035 if (!value) goto failed;
3036 if (PyObject_SetAttrString(result, "name", value) == -1)
3037 goto failed;
3038 Py_DECREF(value);
3039 value = ast2obj_identifier(o->asname);
3040 if (!value) goto failed;
3041 if (PyObject_SetAttrString(result, "asname", value) == -1)
3042 goto failed;
3043 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003044 return result;
3045failed:
3046 Py_XDECREF(value);
3047 Py_XDECREF(result);
3048 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003049}
3050
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003051
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003052PyMODINIT_FUNC
3053init_ast(void)
3054{
3055 PyObject *m, *d;
3056 if (!init_types()) return;
3057 m = Py_InitModule3("_ast", NULL, NULL);
3058 if (!m) return;
3059 d = PyModule_GetDict(m);
3060 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3061 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3062 return;
Guido van Rossum9091e3a2007-03-18 16:10:35 +00003063 if (PyModule_AddStringConstant(m, "__version__", "54428") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003064 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003065 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3066 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3067 return;
3068 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3069 < 0) return;
3070 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3071 0) return;
3072 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3073 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3074 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3075 < 0) return;
3076 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3077 return;
3078 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3079 return;
3080 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3081 return;
3082 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3083 return;
3084 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3085 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003086 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3087 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3088 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3089 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3090 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3091 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3092 0) return;
3093 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3094 0) return;
3095 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3096 return;
3097 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3098 return;
3099 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3100 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003101 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3102 return;
Jeremy Hylton81e95022007-02-27 06:50:52 +00003103 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
3104 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003105 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3106 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3107 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3108 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3109 return;
3110 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3111 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3114 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3115 return;
3116 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3117 return;
3118 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003120 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003121 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3122 return;
3123 if (PyDict_SetItemString(d, "GeneratorExp",
3124 (PyObject*)GeneratorExp_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3126 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003129 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3130 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Thomas Wouters00e41de2007-02-23 19:56:57 +00003131 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003132 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3133 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003134 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3135 0) return;
3136 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3137 0) return;
3138 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3139 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3140 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3141 if (PyDict_SetItemString(d, "expr_context",
3142 (PyObject*)expr_context_type) < 0) return;
3143 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3144 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3145 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3146 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3147 return;
3148 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3149 return;
3150 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3151 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003152 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3153 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3154 return;
3155 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3156 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3157 return;
3158 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3159 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3160 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3161 return;
3162 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3163 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3164 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3165 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3166 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3167 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3168 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3169 return;
3170 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3171 return;
3172 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3173 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3174 return;
3175 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3176 return;
3177 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3178 return;
3179 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3180 return;
3181 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3182 return;
3183 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3184 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3185 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3186 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3187 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3188 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3189 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3190 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3191 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3192 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3193 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3194 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3195 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3196 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3197 if (PyDict_SetItemString(d, "comprehension",
3198 (PyObject*)comprehension_type) < 0) return;
3199 if (PyDict_SetItemString(d, "excepthandler",
3200 (PyObject*)excepthandler_type) < 0) return;
3201 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3202 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003203 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3204 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3205 0) return;
3206 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3207 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003208 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3209 return;
3210 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003211}
3212
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003213
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003214PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003215{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003216 init_types();
3217 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003218}
3219
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003220