blob: ae3a39604875e9ce043f4361b229e02f5821eb56 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
3
4/*
5 __version__ 53731.
6
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
10*/
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000011
12#include "Python.h"
13#include "Python-ast.h"
14
Neal Norwitz53d960c2006-02-28 22:47:29 +000015static PyTypeObject* AST_type;
16static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000017static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000018static PyTypeObject *Module_type;
19static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000020 "body",
21};
Neal Norwitz53d960c2006-02-28 22:47:29 +000022static PyTypeObject *Interactive_type;
23static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000024 "body",
25};
Neal Norwitz53d960c2006-02-28 22:47:29 +000026static PyTypeObject *Expression_type;
27static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000028 "body",
29};
Neal Norwitz53d960c2006-02-28 22:47:29 +000030static PyTypeObject *Suite_type;
31static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000032 "body",
33};
Neal Norwitz53d960c2006-02-28 22:47:29 +000034static PyTypeObject *stmt_type;
35static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000036 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000037 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000038};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000039static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000040static PyTypeObject *FunctionDef_type;
41static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000042 "name",
43 "args",
44 "body",
45 "decorators",
Neal Norwitzc1505362006-12-28 06:47:50 +000046 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *ClassDef_type;
49static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "name",
51 "bases",
52 "body",
53};
Neal Norwitz53d960c2006-02-28 22:47:29 +000054static PyTypeObject *Return_type;
55static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000056 "value",
57};
Neal Norwitz53d960c2006-02-28 22:47:29 +000058static PyTypeObject *Delete_type;
59static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000060 "targets",
61};
Neal Norwitz53d960c2006-02-28 22:47:29 +000062static PyTypeObject *Assign_type;
63static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000064 "targets",
65 "value",
66};
Neal Norwitz53d960c2006-02-28 22:47:29 +000067static PyTypeObject *AugAssign_type;
68static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000069 "target",
70 "op",
71 "value",
72};
Neal Norwitz53d960c2006-02-28 22:47:29 +000073static PyTypeObject *For_type;
74static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000075 "target",
76 "iter",
77 "body",
78 "orelse",
79};
Neal Norwitz53d960c2006-02-28 22:47:29 +000080static PyTypeObject *While_type;
81static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000082 "test",
83 "body",
84 "orelse",
85};
Neal Norwitz53d960c2006-02-28 22:47:29 +000086static PyTypeObject *If_type;
87static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000088 "test",
89 "body",
90 "orelse",
91};
Neal Norwitz53d960c2006-02-28 22:47:29 +000092static PyTypeObject *With_type;
93static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000094 "context_expr",
95 "optional_vars",
96 "body",
97};
Neal Norwitz53d960c2006-02-28 22:47:29 +000098static PyTypeObject *Raise_type;
99static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000100 "type",
101 "inst",
102 "tback",
103};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000104static PyTypeObject *TryExcept_type;
105static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000106 "body",
107 "handlers",
108 "orelse",
109};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000110static PyTypeObject *TryFinally_type;
111static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000112 "body",
113 "finalbody",
114};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000115static PyTypeObject *Assert_type;
116static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000117 "test",
118 "msg",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *Import_type;
121static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "names",
123};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000124static PyTypeObject *ImportFrom_type;
125static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000126 "module",
127 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000128 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000129};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000130static PyTypeObject *Global_type;
131static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000132 "names",
133};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000134static PyTypeObject *Expr_type;
135static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000136 "value",
137};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000138static PyTypeObject *Pass_type;
139static PyTypeObject *Break_type;
140static PyTypeObject *Continue_type;
141static PyTypeObject *expr_type;
142static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000143 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000144 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000145};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000146static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000147static PyTypeObject *BoolOp_type;
148static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000149 "op",
150 "values",
151};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000152static PyTypeObject *BinOp_type;
153static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000154 "left",
155 "op",
156 "right",
157};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000158static PyTypeObject *UnaryOp_type;
159static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000160 "op",
161 "operand",
162};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000163static PyTypeObject *Lambda_type;
164static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000165 "args",
166 "body",
167};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000168static PyTypeObject *IfExp_type;
169static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000170 "test",
171 "body",
172 "orelse",
173};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000174static PyTypeObject *Dict_type;
175static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000176 "keys",
177 "values",
178};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000179static PyTypeObject *Set_type;
180static char *Set_fields[]={
181 "elts",
182};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000183static PyTypeObject *ListComp_type;
184static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000185 "elt",
186 "generators",
187};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000188static PyTypeObject *GeneratorExp_type;
189static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000190 "elt",
191 "generators",
192};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000193static PyTypeObject *Yield_type;
194static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000195 "value",
196};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000197static PyTypeObject *Compare_type;
198static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000199 "left",
200 "ops",
201 "comparators",
202};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000203static PyTypeObject *Call_type;
204static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000205 "func",
206 "args",
207 "keywords",
208 "starargs",
209 "kwargs",
210};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000211static PyTypeObject *Num_type;
212static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213 "n",
214};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000215static PyTypeObject *Str_type;
216static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000217 "s",
218};
Georg Brandl52318d62006-09-06 07:06:08 +0000219static PyTypeObject *Ellipsis_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000220static PyTypeObject *Attribute_type;
221static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000222 "value",
223 "attr",
224 "ctx",
225};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000226static PyTypeObject *Subscript_type;
227static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000228 "value",
229 "slice",
230 "ctx",
231};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000232static PyTypeObject *Name_type;
233static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000234 "id",
235 "ctx",
236};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000237static PyTypeObject *List_type;
238static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000239 "elts",
240 "ctx",
241};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Tuple_type;
243static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244 "elts",
245 "ctx",
246};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000247static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000248static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
249*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
250static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000251static PyTypeObject *Load_type;
252static PyTypeObject *Store_type;
253static PyTypeObject *Del_type;
254static PyTypeObject *AugLoad_type;
255static PyTypeObject *AugStore_type;
256static PyTypeObject *Param_type;
257static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000258static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000259static PyTypeObject *Slice_type;
260static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000261 "lower",
262 "upper",
263 "step",
264};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000265static PyTypeObject *ExtSlice_type;
266static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000267 "dims",
268};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *Index_type;
270static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271 "value",
272};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000273static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000274static PyObject *And_singleton, *Or_singleton;
275static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000276static PyTypeObject *And_type;
277static PyTypeObject *Or_type;
278static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000279static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
280*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
281*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
282*FloorDiv_singleton;
283static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000284static PyTypeObject *Add_type;
285static PyTypeObject *Sub_type;
286static PyTypeObject *Mult_type;
287static PyTypeObject *Div_type;
288static PyTypeObject *Mod_type;
289static PyTypeObject *Pow_type;
290static PyTypeObject *LShift_type;
291static PyTypeObject *RShift_type;
292static PyTypeObject *BitOr_type;
293static PyTypeObject *BitXor_type;
294static PyTypeObject *BitAnd_type;
295static PyTypeObject *FloorDiv_type;
296static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000297static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
298*USub_singleton;
299static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000300static PyTypeObject *Invert_type;
301static PyTypeObject *Not_type;
302static PyTypeObject *UAdd_type;
303static PyTypeObject *USub_type;
304static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000305static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
306*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
307*NotIn_singleton;
308static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000309static PyTypeObject *Eq_type;
310static PyTypeObject *NotEq_type;
311static PyTypeObject *Lt_type;
312static PyTypeObject *LtE_type;
313static PyTypeObject *Gt_type;
314static PyTypeObject *GtE_type;
315static PyTypeObject *Is_type;
316static PyTypeObject *IsNot_type;
317static PyTypeObject *In_type;
318static PyTypeObject *NotIn_type;
319static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000320static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000321static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000322 "target",
323 "iter",
324 "ifs",
325};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000326static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000327static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329 "type",
330 "name",
331 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000332 "lineno",
333 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000334};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000335static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338 "args",
339 "vararg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000340 "varargannotation",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000341 "kwonlyargs",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342 "kwarg",
Neal Norwitzc1505362006-12-28 06:47:50 +0000343 "kwargannotation",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344 "defaults",
Guido van Rossum4f72a782006-10-27 23:31:49 +0000345 "kw_defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346};
Neal Norwitzc1505362006-12-28 06:47:50 +0000347static PyTypeObject *arg_type;
348static PyObject* ast2obj_arg(void*);
349static PyTypeObject *SimpleArg_type;
350static char *SimpleArg_fields[]={
351 "arg",
352 "annotation",
353};
354static PyTypeObject *NestedArgs_type;
355static char *NestedArgs_fields[]={
356 "args",
357};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000358static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000359static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000360static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000361 "arg",
362 "value",
363};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000364static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000365static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000366static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000367 "name",
368 "asname",
369};
370
371
372static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
373{
374 PyObject *fnames, *result;
375 int i;
376 if (num_fields) {
377 fnames = PyTuple_New(num_fields);
378 if (!fnames) return NULL;
379 } else {
380 fnames = Py_None;
381 Py_INCREF(Py_None);
382 }
383 for(i=0; i < num_fields; i++) {
384 PyObject *field = PyString_FromString(fields[i]);
385 if (!field) {
386 Py_DECREF(fnames);
387 return NULL;
388 }
389 PyTuple_SET_ITEM(fnames, i, field);
390 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000391 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000392 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000393 Py_DECREF(fnames);
394 return (PyTypeObject*)result;
395}
396
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000397static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
398{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000399 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000400 PyObject *s, *l = PyList_New(num_fields);
401 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000402 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000403 s = PyString_FromString(attrs[i]);
404 if (!s) {
405 Py_DECREF(l);
406 return 0;
407 }
408 PyList_SET_ITEM(l, i, s);
409 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000410 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
411 Py_DECREF(l);
412 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000413}
414
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000415static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
416{
417 int i, n = asdl_seq_LEN(seq);
418 PyObject *result = PyList_New(n);
419 PyObject *value;
420 if (!result)
421 return NULL;
422 for (i = 0; i < n; i++) {
423 value = func(asdl_seq_GET(seq, i));
424 if (!value) {
425 Py_DECREF(result);
426 return NULL;
427 }
428 PyList_SET_ITEM(result, i, value);
429 }
430 return result;
431}
432
433static PyObject* ast2obj_object(void *o)
434{
435 if (!o)
436 o = Py_None;
437 Py_INCREF((PyObject*)o);
438 return (PyObject*)o;
439}
440#define ast2obj_identifier ast2obj_object
441#define ast2obj_string ast2obj_object
442static PyObject* ast2obj_bool(bool b)
443{
444 return PyBool_FromLong(b);
445}
446
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000447static PyObject* ast2obj_int(bool b)
448{
449 return PyInt_FromLong(b);
450}
451
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000452static int init_types(void)
453{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000454 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000455 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000456 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
457 mod_type = make_type("mod", AST_type, NULL, 0);
458 if (!mod_type) return 0;
459 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000460 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000461 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000462 Interactive_type = make_type("Interactive", mod_type,
463 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Expression_type = make_type("Expression", mod_type, Expression_fields,
466 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000467 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000468 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000469 if (!Suite_type) return 0;
470 stmt_type = make_type("stmt", AST_type, NULL, 0);
471 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000472 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 FunctionDef_type = make_type("FunctionDef", stmt_type,
Neal Norwitzc1505362006-12-28 06:47:50 +0000474 FunctionDef_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000475 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000476 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000477 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000478 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000492 With_type = make_type("With", stmt_type, With_fields, 3);
493 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000497 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000498 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
499 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000506 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000512 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000514 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000516 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Continue_type) return 0;
518 expr_type = make_type("expr", AST_type, NULL, 0);
519 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000520 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000521 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000523 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000529 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Dict_type) return 0;
Guido van Rossum86e58e22006-08-28 15:27:34 +0000533 Set_type = make_type("Set", expr_type, Set_fields, 1);
534 if (!Set_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 GeneratorExp_type = make_type("GeneratorExp", expr_type,
538 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000539 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000547 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000548 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Str_type) return 0;
Georg Brandl52318d62006-09-06 07:06:08 +0000550 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
551 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Tuple_type) return 0;
562 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
563 if (!expr_context_type) return 0;
564 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000565 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000567 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000569 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000571 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000573 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000575 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000577 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000581 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000585 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000587 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000588 if (!Param_singleton) return 0;
589 slice_type = make_type("slice", AST_type, NULL, 0);
590 if (!slice_type) return 0;
591 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Index_type) return 0;
598 boolop_type = make_type("boolop", AST_type, NULL, 0);
599 if (!boolop_type) return 0;
600 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Or_singleton) return 0;
609 operator_type = make_type("operator", AST_type, NULL, 0);
610 if (!operator_type) return 0;
611 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000612 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000614 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000616 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000618 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000619 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000620 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000622 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000624 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000626 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000628 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000630 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000632 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000634 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000636 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000637 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000638 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000639 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000640 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000641 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000642 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000643 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000644 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000645 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000646 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000647 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!FloorDiv_singleton) return 0;
660 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
661 if (!unaryop_type) return 0;
662 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000663 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000664 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000665 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000666 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000667 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000669 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000671 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000673 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000675 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000677 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!USub_singleton) return 0;
679 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
680 if (!cmpop_type) return 0;
681 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000682 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000683 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000684 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000686 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000688 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000690 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000692 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000694 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000696 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000698 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000699 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000700 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000701 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000702 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000704 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000705 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000706 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000707 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000708 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000710 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000714 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000715 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000716 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000717 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000718 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000719 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000720 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000721 if (!NotIn_singleton) return 0;
722 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000723 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000724 if (!comprehension_type) return 0;
725 excepthandler_type = make_type("excepthandler", AST_type,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000726 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!excepthandler_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000728 arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000729 if (!arguments_type) return 0;
Neal Norwitzc1505362006-12-28 06:47:50 +0000730 arg_type = make_type("arg", AST_type, NULL, 0);
731 if (!arg_type) return 0;
732 if (!add_attributes(arg_type, NULL, 0)) return 0;
733 SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
734 if (!SimpleArg_type) return 0;
735 NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
736 1);
737 if (!NestedArgs_type) return 0;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000738 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
739 if (!keyword_type) return 0;
740 alias_type = make_type("alias", AST_type, alias_fields, 2);
741 if (!alias_type) return 0;
742 initialized = 1;
743 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000744}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000745
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000746mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000747Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000748{
749 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000750 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000751 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000752 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000753 return NULL;
754 }
755 p->kind = Module_kind;
756 p->v.Module.body = body;
757 return p;
758}
759
760mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000761Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000762{
763 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000764 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000765 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000766 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 return NULL;
768 }
769 p->kind = Interactive_kind;
770 p->v.Interactive.body = body;
771 return p;
772}
773
774mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000775Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000776{
777 mod_ty p;
778 if (!body) {
779 PyErr_SetString(PyExc_ValueError,
780 "field body is required for Expression");
781 return NULL;
782 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000783 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000784 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000785 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000786 return NULL;
787 }
788 p->kind = Expression_kind;
789 p->v.Expression.body = body;
790 return p;
791}
792
793mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000794Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000795{
796 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000797 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000798 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000799 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 return NULL;
801 }
802 p->kind = Suite_kind;
803 p->v.Suite.body = body;
804 return p;
805}
806
807stmt_ty
808FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzc1505362006-12-28 06:47:50 +0000809 decorators, expr_ty returns, int lineno, int col_offset, PyArena
810 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811{
812 stmt_ty p;
813 if (!name) {
814 PyErr_SetString(PyExc_ValueError,
815 "field name is required for FunctionDef");
816 return NULL;
817 }
818 if (!args) {
819 PyErr_SetString(PyExc_ValueError,
820 "field args is required for FunctionDef");
821 return NULL;
822 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000823 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000824 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000825 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826 return NULL;
827 }
828 p->kind = FunctionDef_kind;
829 p->v.FunctionDef.name = name;
830 p->v.FunctionDef.args = args;
831 p->v.FunctionDef.body = body;
832 p->v.FunctionDef.decorators = decorators;
Neal Norwitzc1505362006-12-28 06:47:50 +0000833 p->v.FunctionDef.returns = returns;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000834 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000835 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000836 return p;
837}
838
839stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000840ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
841 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842{
843 stmt_ty p;
844 if (!name) {
845 PyErr_SetString(PyExc_ValueError,
846 "field name is required for ClassDef");
847 return NULL;
848 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000849 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000850 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000851 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000852 return NULL;
853 }
854 p->kind = ClassDef_kind;
855 p->v.ClassDef.name = name;
856 p->v.ClassDef.bases = bases;
857 p->v.ClassDef.body = body;
858 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000859 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860 return p;
861}
862
863stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000864Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865{
866 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000867 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000869 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000870 return NULL;
871 }
872 p->kind = Return_kind;
873 p->v.Return.value = value;
874 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000875 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 return p;
877}
878
879stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000880Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881{
882 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000883 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000884 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000885 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000886 return NULL;
887 }
888 p->kind = Delete_kind;
889 p->v.Delete.targets = targets;
890 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000891 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000892 return p;
893}
894
895stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000896Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
897 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898{
899 stmt_ty p;
900 if (!value) {
901 PyErr_SetString(PyExc_ValueError,
902 "field value is required for Assign");
903 return NULL;
904 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000905 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000906 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000907 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000908 return NULL;
909 }
910 p->kind = Assign_kind;
911 p->v.Assign.targets = targets;
912 p->v.Assign.value = value;
913 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000914 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000915 return p;
916}
917
918stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000919AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
920 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000921{
922 stmt_ty p;
923 if (!target) {
924 PyErr_SetString(PyExc_ValueError,
925 "field target is required for AugAssign");
926 return NULL;
927 }
928 if (!op) {
929 PyErr_SetString(PyExc_ValueError,
930 "field op is required for AugAssign");
931 return NULL;
932 }
933 if (!value) {
934 PyErr_SetString(PyExc_ValueError,
935 "field value is required for AugAssign");
936 return NULL;
937 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000938 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000939 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000940 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000941 return NULL;
942 }
943 p->kind = AugAssign_kind;
944 p->v.AugAssign.target = target;
945 p->v.AugAssign.op = op;
946 p->v.AugAssign.value = value;
947 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000948 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949 return p;
950}
951
952stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000953For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000954 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955{
956 stmt_ty p;
957 if (!target) {
958 PyErr_SetString(PyExc_ValueError,
959 "field target is required for For");
960 return NULL;
961 }
962 if (!iter) {
963 PyErr_SetString(PyExc_ValueError,
964 "field iter is required for For");
965 return NULL;
966 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000967 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000968 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000969 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000970 return NULL;
971 }
972 p->kind = For_kind;
973 p->v.For.target = target;
974 p->v.For.iter = iter;
975 p->v.For.body = body;
976 p->v.For.orelse = orelse;
977 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000978 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 return p;
980}
981
982stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000983While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
984 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985{
986 stmt_ty p;
987 if (!test) {
988 PyErr_SetString(PyExc_ValueError,
989 "field test is required for While");
990 return NULL;
991 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000992 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000993 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000994 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000995 return NULL;
996 }
997 p->kind = While_kind;
998 p->v.While.test = test;
999 p->v.While.body = body;
1000 p->v.While.orelse = orelse;
1001 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001002 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003 return p;
1004}
1005
1006stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001007If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1008 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009{
1010 stmt_ty p;
1011 if (!test) {
1012 PyErr_SetString(PyExc_ValueError,
1013 "field test is required for If");
1014 return NULL;
1015 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001016 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001017 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001018 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001019 return NULL;
1020 }
1021 p->kind = If_kind;
1022 p->v.If.test = test;
1023 p->v.If.body = body;
1024 p->v.If.orelse = orelse;
1025 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001026 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001027 return p;
1028}
1029
1030stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001031With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001032 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001033{
1034 stmt_ty p;
1035 if (!context_expr) {
1036 PyErr_SetString(PyExc_ValueError,
1037 "field context_expr is required for With");
1038 return NULL;
1039 }
1040 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1041 if (!p) {
1042 PyErr_NoMemory();
1043 return NULL;
1044 }
1045 p->kind = With_kind;
1046 p->v.With.context_expr = context_expr;
1047 p->v.With.optional_vars = optional_vars;
1048 p->v.With.body = body;
1049 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001050 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001051 return p;
1052}
1053
1054stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001055Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1056 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001057{
1058 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001059 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001060 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001061 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001062 return NULL;
1063 }
1064 p->kind = Raise_kind;
1065 p->v.Raise.type = type;
1066 p->v.Raise.inst = inst;
1067 p->v.Raise.tback = tback;
1068 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001069 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070 return p;
1071}
1072
1073stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001074TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001075 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076{
1077 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001078 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001080 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081 return NULL;
1082 }
1083 p->kind = TryExcept_kind;
1084 p->v.TryExcept.body = body;
1085 p->v.TryExcept.handlers = handlers;
1086 p->v.TryExcept.orelse = orelse;
1087 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001088 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089 return p;
1090}
1091
1092stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001093TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1094 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095{
1096 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001097 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001099 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001100 return NULL;
1101 }
1102 p->kind = TryFinally_kind;
1103 p->v.TryFinally.body = body;
1104 p->v.TryFinally.finalbody = finalbody;
1105 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001106 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107 return p;
1108}
1109
1110stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001111Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001112{
1113 stmt_ty p;
1114 if (!test) {
1115 PyErr_SetString(PyExc_ValueError,
1116 "field test is required for Assert");
1117 return NULL;
1118 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001119 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001121 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return NULL;
1123 }
1124 p->kind = Assert_kind;
1125 p->v.Assert.test = test;
1126 p->v.Assert.msg = msg;
1127 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001128 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 return p;
1130}
1131
1132stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001133Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001134{
1135 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001136 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001138 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001139 return NULL;
1140 }
1141 p->kind = Import_kind;
1142 p->v.Import.names = names;
1143 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001144 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145 return p;
1146}
1147
1148stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001149ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1150 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001151{
1152 stmt_ty p;
1153 if (!module) {
1154 PyErr_SetString(PyExc_ValueError,
1155 "field module is required for ImportFrom");
1156 return NULL;
1157 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001158 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001160 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 return NULL;
1162 }
1163 p->kind = ImportFrom_kind;
1164 p->v.ImportFrom.module = module;
1165 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001166 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001168 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169 return p;
1170}
1171
1172stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001173Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001174{
1175 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001176 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001178 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 return NULL;
1180 }
1181 p->kind = Global_kind;
1182 p->v.Global.names = names;
1183 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001184 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001185 return p;
1186}
1187
1188stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001189Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001190{
1191 stmt_ty p;
1192 if (!value) {
1193 PyErr_SetString(PyExc_ValueError,
1194 "field value is required for Expr");
1195 return NULL;
1196 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001197 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001198 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001199 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 return NULL;
1201 }
1202 p->kind = Expr_kind;
1203 p->v.Expr.value = value;
1204 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001205 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 return p;
1207}
1208
1209stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001210Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001211{
1212 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001213 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001215 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001216 return NULL;
1217 }
1218 p->kind = Pass_kind;
1219 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001220 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001221 return p;
1222}
1223
1224stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001225Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001226{
1227 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001228 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001230 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231 return NULL;
1232 }
1233 p->kind = Break_kind;
1234 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001235 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 return p;
1237}
1238
1239stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001240Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001241{
1242 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001243 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001245 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001246 return NULL;
1247 }
1248 p->kind = Continue_kind;
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 +00001255BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1256 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001257{
1258 expr_ty p;
1259 if (!op) {
1260 PyErr_SetString(PyExc_ValueError,
1261 "field op is required for BoolOp");
1262 return NULL;
1263 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001264 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001265 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001266 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001267 return NULL;
1268 }
1269 p->kind = BoolOp_kind;
1270 p->v.BoolOp.op = op;
1271 p->v.BoolOp.values = values;
1272 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001273 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001274 return p;
1275}
1276
1277expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001278BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1279 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001280{
1281 expr_ty p;
1282 if (!left) {
1283 PyErr_SetString(PyExc_ValueError,
1284 "field left is required for BinOp");
1285 return NULL;
1286 }
1287 if (!op) {
1288 PyErr_SetString(PyExc_ValueError,
1289 "field op is required for BinOp");
1290 return NULL;
1291 }
1292 if (!right) {
1293 PyErr_SetString(PyExc_ValueError,
1294 "field right is required for BinOp");
1295 return NULL;
1296 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001297 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001298 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001299 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001300 return NULL;
1301 }
1302 p->kind = BinOp_kind;
1303 p->v.BinOp.left = left;
1304 p->v.BinOp.op = op;
1305 p->v.BinOp.right = right;
1306 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001307 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001308 return p;
1309}
1310
1311expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001312UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1313 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001314{
1315 expr_ty p;
1316 if (!op) {
1317 PyErr_SetString(PyExc_ValueError,
1318 "field op is required for UnaryOp");
1319 return NULL;
1320 }
1321 if (!operand) {
1322 PyErr_SetString(PyExc_ValueError,
1323 "field operand is required for UnaryOp");
1324 return NULL;
1325 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001326 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001327 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001328 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001329 return NULL;
1330 }
1331 p->kind = UnaryOp_kind;
1332 p->v.UnaryOp.op = op;
1333 p->v.UnaryOp.operand = operand;
1334 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001335 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001336 return p;
1337}
1338
1339expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001340Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1341 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001342{
1343 expr_ty p;
1344 if (!args) {
1345 PyErr_SetString(PyExc_ValueError,
1346 "field args is required for Lambda");
1347 return NULL;
1348 }
1349 if (!body) {
1350 PyErr_SetString(PyExc_ValueError,
1351 "field body is required for Lambda");
1352 return NULL;
1353 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001354 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001355 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001356 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001357 return NULL;
1358 }
1359 p->kind = Lambda_kind;
1360 p->v.Lambda.args = args;
1361 p->v.Lambda.body = body;
1362 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001363 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001364 return p;
1365}
1366
1367expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001368IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1369 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001370{
1371 expr_ty p;
1372 if (!test) {
1373 PyErr_SetString(PyExc_ValueError,
1374 "field test is required for IfExp");
1375 return NULL;
1376 }
1377 if (!body) {
1378 PyErr_SetString(PyExc_ValueError,
1379 "field body is required for IfExp");
1380 return NULL;
1381 }
1382 if (!orelse) {
1383 PyErr_SetString(PyExc_ValueError,
1384 "field orelse is required for IfExp");
1385 return NULL;
1386 }
1387 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1388 if (!p) {
1389 PyErr_NoMemory();
1390 return NULL;
1391 }
1392 p->kind = IfExp_kind;
1393 p->v.IfExp.test = test;
1394 p->v.IfExp.body = body;
1395 p->v.IfExp.orelse = orelse;
1396 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001397 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001398 return p;
1399}
1400
1401expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001402Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1403 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001404{
1405 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001406 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001407 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001408 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001409 return NULL;
1410 }
1411 p->kind = Dict_kind;
1412 p->v.Dict.keys = keys;
1413 p->v.Dict.values = values;
1414 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001416 return p;
1417}
1418
1419expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001420Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1421{
1422 expr_ty p;
1423 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1424 if (!p) {
1425 PyErr_NoMemory();
1426 return NULL;
1427 }
1428 p->kind = Set_kind;
1429 p->v.Set.elts = elts;
1430 p->lineno = lineno;
1431 p->col_offset = col_offset;
1432 return p;
1433}
1434
1435expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001436ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1437 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001438{
1439 expr_ty p;
1440 if (!elt) {
1441 PyErr_SetString(PyExc_ValueError,
1442 "field elt is required for ListComp");
1443 return NULL;
1444 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001445 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001446 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001447 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001448 return NULL;
1449 }
1450 p->kind = ListComp_kind;
1451 p->v.ListComp.elt = elt;
1452 p->v.ListComp.generators = generators;
1453 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001454 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001455 return p;
1456}
1457
1458expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001459GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1460 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001461{
1462 expr_ty p;
1463 if (!elt) {
1464 PyErr_SetString(PyExc_ValueError,
1465 "field elt is required for GeneratorExp");
1466 return NULL;
1467 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001468 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001470 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001471 return NULL;
1472 }
1473 p->kind = GeneratorExp_kind;
1474 p->v.GeneratorExp.elt = elt;
1475 p->v.GeneratorExp.generators = generators;
1476 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001477 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001478 return p;
1479}
1480
1481expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001482Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001483{
1484 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001485 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001486 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001487 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001488 return NULL;
1489 }
1490 p->kind = Yield_kind;
1491 p->v.Yield.value = value;
1492 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001493 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494 return p;
1495}
1496
1497expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001498Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1499 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500{
1501 expr_ty p;
1502 if (!left) {
1503 PyErr_SetString(PyExc_ValueError,
1504 "field left is required for Compare");
1505 return NULL;
1506 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001507 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001508 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001509 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 return NULL;
1511 }
1512 p->kind = Compare_kind;
1513 p->v.Compare.left = left;
1514 p->v.Compare.ops = ops;
1515 p->v.Compare.comparators = comparators;
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
1522Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001523 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524{
1525 expr_ty p;
1526 if (!func) {
1527 PyErr_SetString(PyExc_ValueError,
1528 "field func is required for Call");
1529 return NULL;
1530 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001531 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001533 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001534 return NULL;
1535 }
1536 p->kind = Call_kind;
1537 p->v.Call.func = func;
1538 p->v.Call.args = args;
1539 p->v.Call.keywords = keywords;
1540 p->v.Call.starargs = starargs;
1541 p->v.Call.kwargs = kwargs;
1542 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001543 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001544 return p;
1545}
1546
1547expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001548Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549{
1550 expr_ty p;
1551 if (!n) {
1552 PyErr_SetString(PyExc_ValueError,
1553 "field n is required for Num");
1554 return NULL;
1555 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001556 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001557 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001558 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001559 return NULL;
1560 }
1561 p->kind = Num_kind;
1562 p->v.Num.n = n;
1563 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001564 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565 return p;
1566}
1567
1568expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001569Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001570{
1571 expr_ty p;
1572 if (!s) {
1573 PyErr_SetString(PyExc_ValueError,
1574 "field s is required for Str");
1575 return NULL;
1576 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001577 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001578 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001579 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001580 return NULL;
1581 }
1582 p->kind = Str_kind;
1583 p->v.Str.s = s;
1584 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001585 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001586 return p;
1587}
1588
1589expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00001590Ellipsis(int lineno, int col_offset, PyArena *arena)
1591{
1592 expr_ty p;
1593 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1594 if (!p) {
1595 PyErr_NoMemory();
1596 return NULL;
1597 }
1598 p->kind = Ellipsis_kind;
1599 p->lineno = lineno;
1600 p->col_offset = col_offset;
1601 return p;
1602}
1603
1604expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001605Attribute(expr_ty value, identifier attr, 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 Attribute");
1612 return NULL;
1613 }
1614 if (!attr) {
1615 PyErr_SetString(PyExc_ValueError,
1616 "field attr is required for Attribute");
1617 return NULL;
1618 }
1619 if (!ctx) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field ctx is required for Attribute");
1622 return NULL;
1623 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001625 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001626 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 return NULL;
1628 }
1629 p->kind = Attribute_kind;
1630 p->v.Attribute.value = value;
1631 p->v.Attribute.attr = attr;
1632 p->v.Attribute.ctx = ctx;
1633 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001634 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001635 return p;
1636}
1637
1638expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001639Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1640 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001641{
1642 expr_ty p;
1643 if (!value) {
1644 PyErr_SetString(PyExc_ValueError,
1645 "field value is required for Subscript");
1646 return NULL;
1647 }
1648 if (!slice) {
1649 PyErr_SetString(PyExc_ValueError,
1650 "field slice is required for Subscript");
1651 return NULL;
1652 }
1653 if (!ctx) {
1654 PyErr_SetString(PyExc_ValueError,
1655 "field ctx is required for Subscript");
1656 return NULL;
1657 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001658 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001659 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001660 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001661 return NULL;
1662 }
1663 p->kind = Subscript_kind;
1664 p->v.Subscript.value = value;
1665 p->v.Subscript.slice = slice;
1666 p->v.Subscript.ctx = ctx;
1667 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001668 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669 return p;
1670}
1671
1672expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001673Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1674 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001675{
1676 expr_ty p;
1677 if (!id) {
1678 PyErr_SetString(PyExc_ValueError,
1679 "field id is required for Name");
1680 return NULL;
1681 }
1682 if (!ctx) {
1683 PyErr_SetString(PyExc_ValueError,
1684 "field ctx is required for Name");
1685 return NULL;
1686 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001687 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001689 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001690 return NULL;
1691 }
1692 p->kind = Name_kind;
1693 p->v.Name.id = id;
1694 p->v.Name.ctx = ctx;
1695 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001696 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697 return p;
1698}
1699
1700expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001701List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1702 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001703{
1704 expr_ty p;
1705 if (!ctx) {
1706 PyErr_SetString(PyExc_ValueError,
1707 "field ctx is required for List");
1708 return NULL;
1709 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001710 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001711 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001712 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713 return NULL;
1714 }
1715 p->kind = List_kind;
1716 p->v.List.elts = elts;
1717 p->v.List.ctx = ctx;
1718 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001719 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001720 return p;
1721}
1722
1723expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001724Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1725 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726{
1727 expr_ty p;
1728 if (!ctx) {
1729 PyErr_SetString(PyExc_ValueError,
1730 "field ctx is required for Tuple");
1731 return NULL;
1732 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001733 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001734 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001735 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001736 return NULL;
1737 }
1738 p->kind = Tuple_kind;
1739 p->v.Tuple.elts = elts;
1740 p->v.Tuple.ctx = ctx;
1741 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001742 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001743 return p;
1744}
1745
1746slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001747Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748{
1749 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001750 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001751 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001752 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 return NULL;
1754 }
1755 p->kind = Slice_kind;
1756 p->v.Slice.lower = lower;
1757 p->v.Slice.upper = upper;
1758 p->v.Slice.step = step;
1759 return p;
1760}
1761
1762slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001763ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001764{
1765 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001766 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001768 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769 return NULL;
1770 }
1771 p->kind = ExtSlice_kind;
1772 p->v.ExtSlice.dims = dims;
1773 return p;
1774}
1775
1776slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778{
1779 slice_ty p;
1780 if (!value) {
1781 PyErr_SetString(PyExc_ValueError,
1782 "field value is required for Index");
1783 return NULL;
1784 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001785 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001786 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001787 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001788 return NULL;
1789 }
1790 p->kind = Index_kind;
1791 p->v.Index.value = value;
1792 return p;
1793}
1794
1795comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001796comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001797{
1798 comprehension_ty p;
1799 if (!target) {
1800 PyErr_SetString(PyExc_ValueError,
1801 "field target is required for comprehension");
1802 return NULL;
1803 }
1804 if (!iter) {
1805 PyErr_SetString(PyExc_ValueError,
1806 "field iter is required for comprehension");
1807 return NULL;
1808 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001809 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001810 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001811 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001812 return NULL;
1813 }
1814 p->target = target;
1815 p->iter = iter;
1816 p->ifs = ifs;
1817 return p;
1818}
1819
1820excepthandler_ty
Guido van Rossum16be03e2007-01-10 18:51:35 +00001821excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001822 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001823{
1824 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001825 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001826 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001827 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001828 return NULL;
1829 }
1830 p->type = type;
1831 p->name = name;
1832 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001833 p->lineno = lineno;
1834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835 return p;
1836}
1837
1838arguments_ty
Neal Norwitzc1505362006-12-28 06:47:50 +00001839arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
1840 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
1841 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001842{
1843 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001844 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001846 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847 return NULL;
1848 }
1849 p->args = args;
1850 p->vararg = vararg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001851 p->varargannotation = varargannotation;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001852 p->kwonlyargs = kwonlyargs;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001853 p->kwarg = kwarg;
Neal Norwitzc1505362006-12-28 06:47:50 +00001854 p->kwargannotation = kwargannotation;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855 p->defaults = defaults;
Guido van Rossum4f72a782006-10-27 23:31:49 +00001856 p->kw_defaults = kw_defaults;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857 return p;
1858}
1859
Neal Norwitzc1505362006-12-28 06:47:50 +00001860arg_ty
1861SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
1862{
1863 arg_ty p;
1864 if (!arg) {
1865 PyErr_SetString(PyExc_ValueError,
1866 "field arg is required for SimpleArg");
1867 return NULL;
1868 }
1869 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1870 if (!p) {
1871 PyErr_NoMemory();
1872 return NULL;
1873 }
1874 p->kind = SimpleArg_kind;
1875 p->v.SimpleArg.arg = arg;
1876 p->v.SimpleArg.annotation = annotation;
1877 return p;
1878}
1879
1880arg_ty
1881NestedArgs(asdl_seq * args, PyArena *arena)
1882{
1883 arg_ty p;
1884 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
1885 if (!p) {
1886 PyErr_NoMemory();
1887 return NULL;
1888 }
1889 p->kind = NestedArgs_kind;
1890 p->v.NestedArgs.args = args;
1891 return p;
1892}
1893
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001894keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001895keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001896{
1897 keyword_ty p;
1898 if (!arg) {
1899 PyErr_SetString(PyExc_ValueError,
1900 "field arg is required for keyword");
1901 return NULL;
1902 }
1903 if (!value) {
1904 PyErr_SetString(PyExc_ValueError,
1905 "field value is required for keyword");
1906 return NULL;
1907 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001908 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001910 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911 return NULL;
1912 }
1913 p->arg = arg;
1914 p->value = value;
1915 return p;
1916}
1917
1918alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001919alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001920{
1921 alias_ty p;
1922 if (!name) {
1923 PyErr_SetString(PyExc_ValueError,
1924 "field name is required for alias");
1925 return NULL;
1926 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001927 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001928 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001929 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001930 return NULL;
1931 }
1932 p->name = name;
1933 p->asname = asname;
1934 return p;
1935}
1936
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001937
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001938PyObject*
1939ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001940{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001941 mod_ty o = (mod_ty)_o;
1942 PyObject *result = NULL, *value = NULL;
1943 if (!o) {
1944 Py_INCREF(Py_None);
1945 return Py_None;
1946 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001947
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948 switch (o->kind) {
1949 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001950 result = PyType_GenericNew(Module_type, NULL, NULL);
1951 if (!result) goto failed;
1952 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1953 if (!value) goto failed;
1954 if (PyObject_SetAttrString(result, "body", value) == -1)
1955 goto failed;
1956 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001957 break;
1958 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001959 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1960 if (!result) goto failed;
1961 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1962 if (!value) goto failed;
1963 if (PyObject_SetAttrString(result, "body", value) == -1)
1964 goto failed;
1965 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 break;
1967 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Expression_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_expr(o->v.Expression.body);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "body", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Suite_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "body", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 return result;
1987failed:
1988 Py_XDECREF(value);
1989 Py_XDECREF(result);
1990 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001991}
1992
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001993PyObject*
1994ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001995{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001996 stmt_ty o = (stmt_ty)_o;
1997 PyObject *result = NULL, *value = NULL;
1998 if (!o) {
1999 Py_INCREF(Py_None);
2000 return Py_None;
2001 }
2002
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002003 switch (o->kind) {
2004 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002005 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2006 if (!result) goto failed;
2007 value = ast2obj_identifier(o->v.FunctionDef.name);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "name", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
2012 value = ast2obj_arguments(o->v.FunctionDef.args);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "args", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
2017 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "body", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002027 value = ast2obj_expr(o->v.FunctionDef.returns);
2028 if (!value) goto failed;
2029 if (PyObject_SetAttrString(result, "returns", value) == -1)
2030 goto failed;
2031 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002032 break;
2033 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002034 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2035 if (!result) goto failed;
2036 value = ast2obj_identifier(o->v.ClassDef.name);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "name", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
2041 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2042 if (!value) goto failed;
2043 if (PyObject_SetAttrString(result, "bases", value) == -1)
2044 goto failed;
2045 Py_DECREF(value);
2046 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2047 if (!value) goto failed;
2048 if (PyObject_SetAttrString(result, "body", value) == -1)
2049 goto failed;
2050 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002051 break;
2052 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002053 result = PyType_GenericNew(Return_type, NULL, NULL);
2054 if (!result) goto failed;
2055 value = ast2obj_expr(o->v.Return.value);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "value", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002060 break;
2061 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002062 result = PyType_GenericNew(Delete_type, NULL, NULL);
2063 if (!result) goto failed;
2064 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "targets", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002069 break;
2070 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002071 result = PyType_GenericNew(Assign_type, NULL, NULL);
2072 if (!result) goto failed;
2073 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "targets", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
2078 value = ast2obj_expr(o->v.Assign.value);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "value", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002083 break;
2084 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002085 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2086 if (!result) goto failed;
2087 value = ast2obj_expr(o->v.AugAssign.target);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "target", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_operator(o->v.AugAssign.op);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "op", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
2097 value = ast2obj_expr(o->v.AugAssign.value);
2098 if (!value) goto failed;
2099 if (PyObject_SetAttrString(result, "value", value) == -1)
2100 goto failed;
2101 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002102 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002103 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002104 result = PyType_GenericNew(For_type, NULL, NULL);
2105 if (!result) goto failed;
2106 value = ast2obj_expr(o->v.For.target);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "target", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_expr(o->v.For.iter);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "iter", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
2116 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2117 if (!value) goto failed;
2118 if (PyObject_SetAttrString(result, "body", value) == -1)
2119 goto failed;
2120 Py_DECREF(value);
2121 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002126 break;
2127 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002128 result = PyType_GenericNew(While_type, NULL, NULL);
2129 if (!result) goto failed;
2130 value = ast2obj_expr(o->v.While.test);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "test", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "body", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
2140 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2141 if (!value) goto failed;
2142 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2143 goto failed;
2144 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002145 break;
2146 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002147 result = PyType_GenericNew(If_type, NULL, NULL);
2148 if (!result) goto failed;
2149 value = ast2obj_expr(o->v.If.test);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "test", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "body", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
2159 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2160 if (!value) goto failed;
2161 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2162 goto failed;
2163 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002164 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002165 case With_kind:
2166 result = PyType_GenericNew(With_type, NULL, NULL);
2167 if (!result) goto failed;
2168 value = ast2obj_expr(o->v.With.context_expr);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2171 goto failed;
2172 Py_DECREF(value);
2173 value = ast2obj_expr(o->v.With.optional_vars);
2174 if (!value) goto failed;
2175 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2176 -1)
2177 goto failed;
2178 Py_DECREF(value);
2179 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2180 if (!value) goto failed;
2181 if (PyObject_SetAttrString(result, "body", value) == -1)
2182 goto failed;
2183 Py_DECREF(value);
2184 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002185 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002186 result = PyType_GenericNew(Raise_type, NULL, NULL);
2187 if (!result) goto failed;
2188 value = ast2obj_expr(o->v.Raise.type);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "type", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_expr(o->v.Raise.inst);
2194 if (!value) goto failed;
2195 if (PyObject_SetAttrString(result, "inst", value) == -1)
2196 goto failed;
2197 Py_DECREF(value);
2198 value = ast2obj_expr(o->v.Raise.tback);
2199 if (!value) goto failed;
2200 if (PyObject_SetAttrString(result, "tback", value) == -1)
2201 goto failed;
2202 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002203 break;
2204 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002205 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2206 if (!result) goto failed;
2207 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2208 if (!value) goto failed;
2209 if (PyObject_SetAttrString(result, "body", value) == -1)
2210 goto failed;
2211 Py_DECREF(value);
2212 value = ast2obj_list(o->v.TryExcept.handlers,
2213 ast2obj_excepthandler);
2214 if (!value) goto failed;
2215 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2216 goto failed;
2217 Py_DECREF(value);
2218 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2219 if (!value) goto failed;
2220 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2221 goto failed;
2222 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002223 break;
2224 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002225 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2226 if (!result) goto failed;
2227 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "body", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
2232 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2233 if (!value) goto failed;
2234 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2235 goto failed;
2236 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002237 break;
2238 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002239 result = PyType_GenericNew(Assert_type, NULL, NULL);
2240 if (!result) goto failed;
2241 value = ast2obj_expr(o->v.Assert.test);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "test", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
2246 value = ast2obj_expr(o->v.Assert.msg);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "msg", value) == -1)
2249 goto failed;
2250 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002251 break;
2252 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002253 result = PyType_GenericNew(Import_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "names", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002260 break;
2261 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002262 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2263 if (!result) goto failed;
2264 value = ast2obj_identifier(o->v.ImportFrom.module);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "module", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
2269 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "names", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002274 value = ast2obj_int(o->v.ImportFrom.level);
2275 if (!value) goto failed;
2276 if (PyObject_SetAttrString(result, "level", value) == -1)
2277 goto failed;
2278 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002279 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002280 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002281 result = PyType_GenericNew(Global_type, NULL, NULL);
2282 if (!result) goto failed;
2283 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "names", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288 break;
2289 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002290 result = PyType_GenericNew(Expr_type, NULL, NULL);
2291 if (!result) goto failed;
2292 value = ast2obj_expr(o->v.Expr.value);
2293 if (!value) goto failed;
2294 if (PyObject_SetAttrString(result, "value", value) == -1)
2295 goto failed;
2296 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002297 break;
2298 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002299 result = PyType_GenericNew(Pass_type, NULL, NULL);
2300 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002301 break;
2302 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002303 result = PyType_GenericNew(Break_type, NULL, NULL);
2304 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002305 break;
2306 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002307 result = PyType_GenericNew(Continue_type, NULL, NULL);
2308 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002309 break;
2310 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002311 value = ast2obj_int(o->lineno);
2312 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002313 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2314 goto failed;
2315 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002316 value = ast2obj_int(o->col_offset);
2317 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002318 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2319 goto failed;
2320 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002321 return result;
2322failed:
2323 Py_XDECREF(value);
2324 Py_XDECREF(result);
2325 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002326}
2327
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002328PyObject*
2329ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002330{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002331 expr_ty o = (expr_ty)_o;
2332 PyObject *result = NULL, *value = NULL;
2333 if (!o) {
2334 Py_INCREF(Py_None);
2335 return Py_None;
2336 }
2337
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002338 switch (o->kind) {
2339 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002340 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2341 if (!result) goto failed;
2342 value = ast2obj_boolop(o->v.BoolOp.op);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "op", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
2347 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "values", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002352 break;
2353 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_expr(o->v.BinOp.left);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "left", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_operator(o->v.BinOp.op);
2362 if (!value) goto failed;
2363 if (PyObject_SetAttrString(result, "op", value) == -1)
2364 goto failed;
2365 Py_DECREF(value);
2366 value = ast2obj_expr(o->v.BinOp.right);
2367 if (!value) goto failed;
2368 if (PyObject_SetAttrString(result, "right", value) == -1)
2369 goto failed;
2370 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002371 break;
2372 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002373 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2374 if (!result) goto failed;
2375 value = ast2obj_unaryop(o->v.UnaryOp.op);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "op", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_expr(o->v.UnaryOp.operand);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "operand", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002385 break;
2386 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002387 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_arguments(o->v.Lambda.args);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "args", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
2394 value = ast2obj_expr(o->v.Lambda.body);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "body", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002400 case IfExp_kind:
2401 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2402 if (!result) goto failed;
2403 value = ast2obj_expr(o->v.IfExp.test);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "test", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
2408 value = ast2obj_expr(o->v.IfExp.body);
2409 if (!value) goto failed;
2410 if (PyObject_SetAttrString(result, "body", value) == -1)
2411 goto failed;
2412 Py_DECREF(value);
2413 value = ast2obj_expr(o->v.IfExp.orelse);
2414 if (!value) goto failed;
2415 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2416 goto failed;
2417 Py_DECREF(value);
2418 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002419 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002420 result = PyType_GenericNew(Dict_type, NULL, NULL);
2421 if (!result) goto failed;
2422 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2423 if (!value) goto failed;
2424 if (PyObject_SetAttrString(result, "keys", value) == -1)
2425 goto failed;
2426 Py_DECREF(value);
2427 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "values", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002432 break;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002433 case Set_kind:
2434 result = PyType_GenericNew(Set_type, NULL, NULL);
2435 if (!result) goto failed;
2436 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "elts", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
2441 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002443 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2444 if (!result) goto failed;
2445 value = ast2obj_expr(o->v.ListComp.elt);
2446 if (!value) goto failed;
2447 if (PyObject_SetAttrString(result, "elt", value) == -1)
2448 goto failed;
2449 Py_DECREF(value);
2450 value = ast2obj_list(o->v.ListComp.generators,
2451 ast2obj_comprehension);
2452 if (!value) goto failed;
2453 if (PyObject_SetAttrString(result, "generators", value) == -1)
2454 goto failed;
2455 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002456 break;
2457 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002458 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2459 if (!result) goto failed;
2460 value = ast2obj_expr(o->v.GeneratorExp.elt);
2461 if (!value) goto failed;
2462 if (PyObject_SetAttrString(result, "elt", value) == -1)
2463 goto failed;
2464 Py_DECREF(value);
2465 value = ast2obj_list(o->v.GeneratorExp.generators,
2466 ast2obj_comprehension);
2467 if (!value) goto failed;
2468 if (PyObject_SetAttrString(result, "generators", value) == -1)
2469 goto failed;
2470 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471 break;
2472 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002473 result = PyType_GenericNew(Yield_type, NULL, NULL);
2474 if (!result) goto failed;
2475 value = ast2obj_expr(o->v.Yield.value);
2476 if (!value) goto failed;
2477 if (PyObject_SetAttrString(result, "value", value) == -1)
2478 goto failed;
2479 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002480 break;
2481 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002482 result = PyType_GenericNew(Compare_type, NULL, NULL);
2483 if (!result) goto failed;
2484 value = ast2obj_expr(o->v.Compare.left);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "left", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002489 {
2490 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2491 value = PyList_New(n);
2492 if (!value) goto failed;
2493 for(i = 0; i < n; i++)
2494 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2495 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002496 if (!value) goto failed;
2497 if (PyObject_SetAttrString(result, "ops", value) == -1)
2498 goto failed;
2499 Py_DECREF(value);
2500 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505 break;
2506 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Call_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_expr(o->v.Call.func);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "func", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
2514 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "args", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
2524 value = ast2obj_expr(o->v.Call.starargs);
2525 if (!value) goto failed;
2526 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2527 goto failed;
2528 Py_DECREF(value);
2529 value = ast2obj_expr(o->v.Call.kwargs);
2530 if (!value) goto failed;
2531 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2532 goto failed;
2533 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002534 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002535 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002536 result = PyType_GenericNew(Num_type, NULL, NULL);
2537 if (!result) goto failed;
2538 value = ast2obj_object(o->v.Num.n);
2539 if (!value) goto failed;
2540 if (PyObject_SetAttrString(result, "n", value) == -1)
2541 goto failed;
2542 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002543 break;
2544 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002545 result = PyType_GenericNew(Str_type, NULL, NULL);
2546 if (!result) goto failed;
2547 value = ast2obj_string(o->v.Str.s);
2548 if (!value) goto failed;
2549 if (PyObject_SetAttrString(result, "s", value) == -1)
2550 goto failed;
2551 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002552 break;
Georg Brandl52318d62006-09-06 07:06:08 +00002553 case Ellipsis_kind:
2554 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2555 if (!result) goto failed;
2556 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002558 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2559 if (!result) goto failed;
2560 value = ast2obj_expr(o->v.Attribute.value);
2561 if (!value) goto failed;
2562 if (PyObject_SetAttrString(result, "value", value) == -1)
2563 goto failed;
2564 Py_DECREF(value);
2565 value = ast2obj_identifier(o->v.Attribute.attr);
2566 if (!value) goto failed;
2567 if (PyObject_SetAttrString(result, "attr", value) == -1)
2568 goto failed;
2569 Py_DECREF(value);
2570 value = ast2obj_expr_context(o->v.Attribute.ctx);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002575 break;
2576 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002577 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2578 if (!result) goto failed;
2579 value = ast2obj_expr(o->v.Subscript.value);
2580 if (!value) goto failed;
2581 if (PyObject_SetAttrString(result, "value", value) == -1)
2582 goto failed;
2583 Py_DECREF(value);
2584 value = ast2obj_slice(o->v.Subscript.slice);
2585 if (!value) goto failed;
2586 if (PyObject_SetAttrString(result, "slice", value) == -1)
2587 goto failed;
2588 Py_DECREF(value);
2589 value = ast2obj_expr_context(o->v.Subscript.ctx);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002594 break;
2595 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002596 result = PyType_GenericNew(Name_type, NULL, NULL);
2597 if (!result) goto failed;
2598 value = ast2obj_identifier(o->v.Name.id);
2599 if (!value) goto failed;
2600 if (PyObject_SetAttrString(result, "id", value) == -1)
2601 goto failed;
2602 Py_DECREF(value);
2603 value = ast2obj_expr_context(o->v.Name.ctx);
2604 if (!value) goto failed;
2605 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2606 goto failed;
2607 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002608 break;
2609 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002610 result = PyType_GenericNew(List_type, NULL, NULL);
2611 if (!result) goto failed;
2612 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2613 if (!value) goto failed;
2614 if (PyObject_SetAttrString(result, "elts", value) == -1)
2615 goto failed;
2616 Py_DECREF(value);
2617 value = ast2obj_expr_context(o->v.List.ctx);
2618 if (!value) goto failed;
2619 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2620 goto failed;
2621 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002622 break;
2623 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002624 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2625 if (!result) goto failed;
2626 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "elts", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
2631 value = ast2obj_expr_context(o->v.Tuple.ctx);
2632 if (!value) goto failed;
2633 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2634 goto failed;
2635 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002636 break;
2637 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002638 value = ast2obj_int(o->lineno);
2639 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002640 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2641 goto failed;
2642 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002643 value = ast2obj_int(o->col_offset);
2644 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002645 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2646 goto failed;
2647 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648 return result;
2649failed:
2650 Py_XDECREF(value);
2651 Py_XDECREF(result);
2652 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002653}
2654
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002655PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002657 switch(o) {
2658 case Load:
2659 Py_INCREF(Load_singleton);
2660 return Load_singleton;
2661 case Store:
2662 Py_INCREF(Store_singleton);
2663 return Store_singleton;
2664 case Del:
2665 Py_INCREF(Del_singleton);
2666 return Del_singleton;
2667 case AugLoad:
2668 Py_INCREF(AugLoad_singleton);
2669 return AugLoad_singleton;
2670 case AugStore:
2671 Py_INCREF(AugStore_singleton);
2672 return AugStore_singleton;
2673 case Param:
2674 Py_INCREF(Param_singleton);
2675 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002676 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002677 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002678}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002679PyObject*
2680ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002681{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002682 slice_ty o = (slice_ty)_o;
2683 PyObject *result = NULL, *value = NULL;
2684 if (!o) {
2685 Py_INCREF(Py_None);
2686 return Py_None;
2687 }
2688
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002689 switch (o->kind) {
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691 result = PyType_GenericNew(Slice_type, NULL, NULL);
2692 if (!result) goto failed;
2693 value = ast2obj_expr(o->v.Slice.lower);
2694 if (!value) goto failed;
2695 if (PyObject_SetAttrString(result, "lower", value) == -1)
2696 goto failed;
2697 Py_DECREF(value);
2698 value = ast2obj_expr(o->v.Slice.upper);
2699 if (!value) goto failed;
2700 if (PyObject_SetAttrString(result, "upper", value) == -1)
2701 goto failed;
2702 Py_DECREF(value);
2703 value = ast2obj_expr(o->v.Slice.step);
2704 if (!value) goto failed;
2705 if (PyObject_SetAttrString(result, "step", value) == -1)
2706 goto failed;
2707 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002708 break;
2709 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002710 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2711 if (!result) goto failed;
2712 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "dims", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717 break;
2718 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002719 result = PyType_GenericNew(Index_type, NULL, NULL);
2720 if (!result) goto failed;
2721 value = ast2obj_expr(o->v.Index.value);
2722 if (!value) goto failed;
2723 if (PyObject_SetAttrString(result, "value", value) == -1)
2724 goto failed;
2725 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002726 break;
2727 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002728 return result;
2729failed:
2730 Py_XDECREF(value);
2731 Py_XDECREF(result);
2732 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002733}
2734
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002735PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002736{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002737 switch(o) {
2738 case And:
2739 Py_INCREF(And_singleton);
2740 return And_singleton;
2741 case Or:
2742 Py_INCREF(Or_singleton);
2743 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002744 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002745 return NULL; /* cannot happen */
2746}
2747PyObject* ast2obj_operator(operator_ty o)
2748{
2749 switch(o) {
2750 case Add:
2751 Py_INCREF(Add_singleton);
2752 return Add_singleton;
2753 case Sub:
2754 Py_INCREF(Sub_singleton);
2755 return Sub_singleton;
2756 case Mult:
2757 Py_INCREF(Mult_singleton);
2758 return Mult_singleton;
2759 case Div:
2760 Py_INCREF(Div_singleton);
2761 return Div_singleton;
2762 case Mod:
2763 Py_INCREF(Mod_singleton);
2764 return Mod_singleton;
2765 case Pow:
2766 Py_INCREF(Pow_singleton);
2767 return Pow_singleton;
2768 case LShift:
2769 Py_INCREF(LShift_singleton);
2770 return LShift_singleton;
2771 case RShift:
2772 Py_INCREF(RShift_singleton);
2773 return RShift_singleton;
2774 case BitOr:
2775 Py_INCREF(BitOr_singleton);
2776 return BitOr_singleton;
2777 case BitXor:
2778 Py_INCREF(BitXor_singleton);
2779 return BitXor_singleton;
2780 case BitAnd:
2781 Py_INCREF(BitAnd_singleton);
2782 return BitAnd_singleton;
2783 case FloorDiv:
2784 Py_INCREF(FloorDiv_singleton);
2785 return FloorDiv_singleton;
2786 }
2787 return NULL; /* cannot happen */
2788}
2789PyObject* ast2obj_unaryop(unaryop_ty o)
2790{
2791 switch(o) {
2792 case Invert:
2793 Py_INCREF(Invert_singleton);
2794 return Invert_singleton;
2795 case Not:
2796 Py_INCREF(Not_singleton);
2797 return Not_singleton;
2798 case UAdd:
2799 Py_INCREF(UAdd_singleton);
2800 return UAdd_singleton;
2801 case USub:
2802 Py_INCREF(USub_singleton);
2803 return USub_singleton;
2804 }
2805 return NULL; /* cannot happen */
2806}
2807PyObject* ast2obj_cmpop(cmpop_ty o)
2808{
2809 switch(o) {
2810 case Eq:
2811 Py_INCREF(Eq_singleton);
2812 return Eq_singleton;
2813 case NotEq:
2814 Py_INCREF(NotEq_singleton);
2815 return NotEq_singleton;
2816 case Lt:
2817 Py_INCREF(Lt_singleton);
2818 return Lt_singleton;
2819 case LtE:
2820 Py_INCREF(LtE_singleton);
2821 return LtE_singleton;
2822 case Gt:
2823 Py_INCREF(Gt_singleton);
2824 return Gt_singleton;
2825 case GtE:
2826 Py_INCREF(GtE_singleton);
2827 return GtE_singleton;
2828 case Is:
2829 Py_INCREF(Is_singleton);
2830 return Is_singleton;
2831 case IsNot:
2832 Py_INCREF(IsNot_singleton);
2833 return IsNot_singleton;
2834 case In:
2835 Py_INCREF(In_singleton);
2836 return In_singleton;
2837 case NotIn:
2838 Py_INCREF(NotIn_singleton);
2839 return NotIn_singleton;
2840 }
2841 return NULL; /* cannot happen */
2842}
2843PyObject*
2844ast2obj_comprehension(void* _o)
2845{
2846 comprehension_ty o = (comprehension_ty)_o;
2847 PyObject *result = NULL, *value = NULL;
2848 if (!o) {
2849 Py_INCREF(Py_None);
2850 return Py_None;
2851 }
2852
2853 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2854 if (!result) return NULL;
2855 value = ast2obj_expr(o->target);
2856 if (!value) goto failed;
2857 if (PyObject_SetAttrString(result, "target", value) == -1)
2858 goto failed;
2859 Py_DECREF(value);
2860 value = ast2obj_expr(o->iter);
2861 if (!value) goto failed;
2862 if (PyObject_SetAttrString(result, "iter", value) == -1)
2863 goto failed;
2864 Py_DECREF(value);
2865 value = ast2obj_list(o->ifs, ast2obj_expr);
2866 if (!value) goto failed;
2867 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2868 goto failed;
2869 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002870 return result;
2871failed:
2872 Py_XDECREF(value);
2873 Py_XDECREF(result);
2874 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002875}
2876
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002877PyObject*
2878ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002879{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002880 excepthandler_ty o = (excepthandler_ty)_o;
2881 PyObject *result = NULL, *value = NULL;
2882 if (!o) {
2883 Py_INCREF(Py_None);
2884 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002885 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002886
2887 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2888 if (!result) return NULL;
2889 value = ast2obj_expr(o->type);
2890 if (!value) goto failed;
2891 if (PyObject_SetAttrString(result, "type", value) == -1)
2892 goto failed;
2893 Py_DECREF(value);
Guido van Rossum16be03e2007-01-10 18:51:35 +00002894 value = ast2obj_identifier(o->name);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002895 if (!value) goto failed;
2896 if (PyObject_SetAttrString(result, "name", value) == -1)
2897 goto failed;
2898 Py_DECREF(value);
2899 value = ast2obj_list(o->body, ast2obj_stmt);
2900 if (!value) goto failed;
2901 if (PyObject_SetAttrString(result, "body", value) == -1)
2902 goto failed;
2903 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002904 value = ast2obj_int(o->lineno);
2905 if (!value) goto failed;
2906 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2907 goto failed;
2908 Py_DECREF(value);
2909 value = ast2obj_int(o->col_offset);
2910 if (!value) goto failed;
2911 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2912 goto failed;
2913 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002914 return result;
2915failed:
2916 Py_XDECREF(value);
2917 Py_XDECREF(result);
2918 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002919}
2920
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002921PyObject*
2922ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002924 arguments_ty o = (arguments_ty)_o;
2925 PyObject *result = NULL, *value = NULL;
2926 if (!o) {
2927 Py_INCREF(Py_None);
2928 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002929 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002930
2931 result = PyType_GenericNew(arguments_type, NULL, NULL);
2932 if (!result) return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00002933 value = ast2obj_list(o->args, ast2obj_arg);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934 if (!value) goto failed;
2935 if (PyObject_SetAttrString(result, "args", value) == -1)
2936 goto failed;
2937 Py_DECREF(value);
2938 value = ast2obj_identifier(o->vararg);
2939 if (!value) goto failed;
2940 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2941 goto failed;
2942 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002943 value = ast2obj_expr(o->varargannotation);
2944 if (!value) goto failed;
2945 if (PyObject_SetAttrString(result, "varargannotation", value) == -1)
2946 goto failed;
2947 Py_DECREF(value);
2948 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002949 if (!value) goto failed;
2950 if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1)
2951 goto failed;
2952 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002953 value = ast2obj_identifier(o->kwarg);
2954 if (!value) goto failed;
2955 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2956 goto failed;
2957 Py_DECREF(value);
Neal Norwitzc1505362006-12-28 06:47:50 +00002958 value = ast2obj_expr(o->kwargannotation);
2959 if (!value) goto failed;
2960 if (PyObject_SetAttrString(result, "kwargannotation", value) == -1)
2961 goto failed;
2962 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002963 value = ast2obj_list(o->defaults, ast2obj_expr);
2964 if (!value) goto failed;
2965 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2966 goto failed;
2967 Py_DECREF(value);
Guido van Rossum4f72a782006-10-27 23:31:49 +00002968 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
2969 if (!value) goto failed;
2970 if (PyObject_SetAttrString(result, "kw_defaults", value) == -1)
2971 goto failed;
2972 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002973 return result;
2974failed:
2975 Py_XDECREF(value);
2976 Py_XDECREF(result);
2977 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002978}
2979
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002980PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00002981ast2obj_arg(void* _o)
2982{
2983 arg_ty o = (arg_ty)_o;
2984 PyObject *result = NULL, *value = NULL;
2985 if (!o) {
2986 Py_INCREF(Py_None);
2987 return Py_None;
2988 }
2989
2990 switch (o->kind) {
2991 case SimpleArg_kind:
2992 result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
2993 if (!result) goto failed;
2994 value = ast2obj_identifier(o->v.SimpleArg.arg);
2995 if (!value) goto failed;
2996 if (PyObject_SetAttrString(result, "arg", value) == -1)
2997 goto failed;
2998 Py_DECREF(value);
2999 value = ast2obj_expr(o->v.SimpleArg.annotation);
3000 if (!value) goto failed;
3001 if (PyObject_SetAttrString(result, "annotation", value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
3004 break;
3005 case NestedArgs_kind:
3006 result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
3007 if (!result) goto failed;
3008 value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
3009 if (!value) goto failed;
3010 if (PyObject_SetAttrString(result, "args", value) == -1)
3011 goto failed;
3012 Py_DECREF(value);
3013 break;
3014 }
3015 return result;
3016failed:
3017 Py_XDECREF(value);
3018 Py_XDECREF(result);
3019 return NULL;
3020}
3021
3022PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003023ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003024{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003025 keyword_ty o = (keyword_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(keyword_type, NULL, NULL);
3033 if (!result) return NULL;
3034 value = ast2obj_identifier(o->arg);
3035 if (!value) goto failed;
3036 if (PyObject_SetAttrString(result, "arg", value) == -1)
3037 goto failed;
3038 Py_DECREF(value);
3039 value = ast2obj_expr(o->value);
3040 if (!value) goto failed;
3041 if (PyObject_SetAttrString(result, "value", 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
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003051PyObject*
3052ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003053{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003054 alias_ty o = (alias_ty)_o;
3055 PyObject *result = NULL, *value = NULL;
3056 if (!o) {
3057 Py_INCREF(Py_None);
3058 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003059 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003060
3061 result = PyType_GenericNew(alias_type, NULL, NULL);
3062 if (!result) return NULL;
3063 value = ast2obj_identifier(o->name);
3064 if (!value) goto failed;
3065 if (PyObject_SetAttrString(result, "name", value) == -1)
3066 goto failed;
3067 Py_DECREF(value);
3068 value = ast2obj_identifier(o->asname);
3069 if (!value) goto failed;
3070 if (PyObject_SetAttrString(result, "asname", value) == -1)
3071 goto failed;
3072 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003073 return result;
3074failed:
3075 Py_XDECREF(value);
3076 Py_XDECREF(result);
3077 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003078}
3079
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003080
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003081PyMODINIT_FUNC
3082init_ast(void)
3083{
3084 PyObject *m, *d;
3085 if (!init_types()) return;
3086 m = Py_InitModule3("_ast", NULL, NULL);
3087 if (!m) return;
3088 d = PyModule_GetDict(m);
3089 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3090 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3091 return;
Thomas Wouterscf297e42007-02-23 15:07:44 +00003092 if (PyModule_AddStringConstant(m, "__version__", "53731") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003093 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003094 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3095 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3096 return;
3097 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3098 < 0) return;
3099 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3100 0) return;
3101 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3102 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3103 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3104 < 0) return;
3105 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3106 return;
3107 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3108 return;
3109 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3110 return;
3111 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3114 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003115 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3116 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3117 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3118 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3119 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3120 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3121 0) return;
3122 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3123 0) return;
3124 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3125 return;
3126 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3127 return;
3128 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3129 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003130 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3131 return;
3132 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3133 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3134 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3135 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3136 return;
3137 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3138 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3139 return;
3140 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3141 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3142 return;
3143 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3144 return;
3145 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3146 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
Guido van Rossum86e58e22006-08-28 15:27:34 +00003147 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003148 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3149 return;
3150 if (PyDict_SetItemString(d, "GeneratorExp",
3151 (PyObject*)GeneratorExp_type) < 0) return;
3152 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3153 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3154 return;
3155 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003156 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3157 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
Georg Brandl52318d62006-09-06 07:06:08 +00003158 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3159 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003160 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3161 0) return;
3162 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3163 0) return;
3164 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3165 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3166 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3167 if (PyDict_SetItemString(d, "expr_context",
3168 (PyObject*)expr_context_type) < 0) return;
3169 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3170 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3171 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3172 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3173 return;
3174 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3175 return;
3176 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3177 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003178 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3179 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3180 return;
3181 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3182 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3183 return;
3184 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3185 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3186 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3187 return;
3188 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3189 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3190 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3191 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3192 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3193 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3194 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3195 return;
3196 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3197 return;
3198 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3199 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3200 return;
3201 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3202 return;
3203 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3204 return;
3205 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3206 return;
3207 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3208 return;
3209 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3210 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3211 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3212 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3213 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3214 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3215 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3216 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3217 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3218 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3219 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3220 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3221 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3222 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3223 if (PyDict_SetItemString(d, "comprehension",
3224 (PyObject*)comprehension_type) < 0) return;
3225 if (PyDict_SetItemString(d, "excepthandler",
3226 (PyObject*)excepthandler_type) < 0) return;
3227 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3228 0) return;
Neal Norwitzc1505362006-12-28 06:47:50 +00003229 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
3230 if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
3231 0) return;
3232 if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
3233 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003234 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3235 return;
3236 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003237}
3238
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003239
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003240PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003241{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003242 init_types();
3243 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003244}
3245
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003246