blob: 46a1817dd7acd941ad4fef297b8e377406e035b2 [file] [log] [blame]
Brett Cannon0db62aa2007-02-12 03:51:02 +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",
46};
Neal Norwitz53d960c2006-02-28 22:47:29 +000047static PyTypeObject *ClassDef_type;
48static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000049 "name",
50 "bases",
51 "body",
52};
Neal Norwitz53d960c2006-02-28 22:47:29 +000053static PyTypeObject *Return_type;
54static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000055 "value",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *Delete_type;
58static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "targets",
60};
Neal Norwitz53d960c2006-02-28 22:47:29 +000061static PyTypeObject *Assign_type;
62static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000063 "targets",
64 "value",
65};
Neal Norwitz53d960c2006-02-28 22:47:29 +000066static PyTypeObject *AugAssign_type;
67static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000068 "target",
69 "op",
70 "value",
71};
Neal Norwitz53d960c2006-02-28 22:47:29 +000072static PyTypeObject *Print_type;
73static char *Print_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000074 "dest",
75 "values",
76 "nl",
77};
Neal Norwitz53d960c2006-02-28 22:47:29 +000078static PyTypeObject *For_type;
79static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000080 "target",
81 "iter",
82 "body",
83 "orelse",
84};
Neal Norwitz53d960c2006-02-28 22:47:29 +000085static PyTypeObject *While_type;
86static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000087 "test",
88 "body",
89 "orelse",
90};
Neal Norwitz53d960c2006-02-28 22:47:29 +000091static PyTypeObject *If_type;
92static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000093 "test",
94 "body",
95 "orelse",
96};
Neal Norwitz53d960c2006-02-28 22:47:29 +000097static PyTypeObject *With_type;
98static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000099 "context_expr",
100 "optional_vars",
101 "body",
102};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000103static PyTypeObject *Raise_type;
104static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000105 "type",
106 "inst",
107 "tback",
108};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000109static PyTypeObject *TryExcept_type;
110static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000111 "body",
112 "handlers",
113 "orelse",
114};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000115static PyTypeObject *TryFinally_type;
116static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000117 "body",
118 "finalbody",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *Assert_type;
121static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "test",
123 "msg",
124};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000125static PyTypeObject *Import_type;
126static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000127 "names",
128};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000129static PyTypeObject *ImportFrom_type;
130static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000131 "module",
132 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000133 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000134};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000135static PyTypeObject *Exec_type;
136static char *Exec_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000137 "body",
138 "globals",
139 "locals",
140};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000141static PyTypeObject *Global_type;
142static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000143 "names",
144};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000145static PyTypeObject *Expr_type;
146static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000147 "value",
148};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *Pass_type;
150static PyTypeObject *Break_type;
151static PyTypeObject *Continue_type;
152static PyTypeObject *expr_type;
153static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000154 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000155 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000156};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000157static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000158static PyTypeObject *BoolOp_type;
159static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000160 "op",
161 "values",
162};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000163static PyTypeObject *BinOp_type;
164static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000165 "left",
166 "op",
167 "right",
168};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000169static PyTypeObject *UnaryOp_type;
170static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000171 "op",
172 "operand",
173};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000174static PyTypeObject *Lambda_type;
175static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000176 "args",
177 "body",
178};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000179static PyTypeObject *IfExp_type;
180static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000181 "test",
182 "body",
183 "orelse",
184};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000185static PyTypeObject *Dict_type;
186static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000187 "keys",
188 "values",
189};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000190static PyTypeObject *ListComp_type;
191static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000192 "elt",
193 "generators",
194};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000195static PyTypeObject *GeneratorExp_type;
196static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000197 "elt",
198 "generators",
199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *Yield_type;
201static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000202 "value",
203};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000204static PyTypeObject *Compare_type;
205static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000206 "left",
207 "ops",
208 "comparators",
209};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000210static PyTypeObject *Call_type;
211static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000212 "func",
213 "args",
214 "keywords",
215 "starargs",
216 "kwargs",
217};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000218static PyTypeObject *Repr_type;
219static char *Repr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000220 "value",
221};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000222static PyTypeObject *Num_type;
223static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000224 "n",
225};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000226static PyTypeObject *Str_type;
227static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000228 "s",
229};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000230static PyTypeObject *Attribute_type;
231static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000232 "value",
233 "attr",
234 "ctx",
235};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000236static PyTypeObject *Subscript_type;
237static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000238 "value",
239 "slice",
240 "ctx",
241};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000242static PyTypeObject *Name_type;
243static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244 "id",
245 "ctx",
246};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000247static PyTypeObject *List_type;
248static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249 "elts",
250 "ctx",
251};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000252static PyTypeObject *Tuple_type;
253static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000254 "elts",
255 "ctx",
256};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000257static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000258static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
259*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
260static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000261static PyTypeObject *Load_type;
262static PyTypeObject *Store_type;
263static PyTypeObject *Del_type;
264static PyTypeObject *AugLoad_type;
265static PyTypeObject *AugStore_type;
266static PyTypeObject *Param_type;
267static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000268static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000269static PyTypeObject *Ellipsis_type;
270static PyTypeObject *Slice_type;
271static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000272 "lower",
273 "upper",
274 "step",
275};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000276static PyTypeObject *ExtSlice_type;
277static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000278 "dims",
279};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *Index_type;
281static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000282 "value",
283};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000284static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000285static PyObject *And_singleton, *Or_singleton;
286static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000287static PyTypeObject *And_type;
288static PyTypeObject *Or_type;
289static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000290static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
291*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
292*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
293*FloorDiv_singleton;
294static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000295static PyTypeObject *Add_type;
296static PyTypeObject *Sub_type;
297static PyTypeObject *Mult_type;
298static PyTypeObject *Div_type;
299static PyTypeObject *Mod_type;
300static PyTypeObject *Pow_type;
301static PyTypeObject *LShift_type;
302static PyTypeObject *RShift_type;
303static PyTypeObject *BitOr_type;
304static PyTypeObject *BitXor_type;
305static PyTypeObject *BitAnd_type;
306static PyTypeObject *FloorDiv_type;
307static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000308static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
309*USub_singleton;
310static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Invert_type;
312static PyTypeObject *Not_type;
313static PyTypeObject *UAdd_type;
314static PyTypeObject *USub_type;
315static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000316static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
317*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
318*NotIn_singleton;
319static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000320static PyTypeObject *Eq_type;
321static PyTypeObject *NotEq_type;
322static PyTypeObject *Lt_type;
323static PyTypeObject *LtE_type;
324static PyTypeObject *Gt_type;
325static PyTypeObject *GtE_type;
326static PyTypeObject *Is_type;
327static PyTypeObject *IsNot_type;
328static PyTypeObject *In_type;
329static PyTypeObject *NotIn_type;
330static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000332static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000333 "target",
334 "iter",
335 "ifs",
336};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000339static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000340 "type",
341 "name",
342 "body",
Jeremy Hylton2f327c12006-04-04 04:00:23 +0000343 "lineno",
344 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000345};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000346static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000347static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000348static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000349 "args",
350 "vararg",
351 "kwarg",
352 "defaults",
353};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000354static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000355static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000356static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000357 "arg",
358 "value",
359};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000360static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000361static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000362static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000363 "name",
364 "asname",
365};
366
367
368static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
369{
370 PyObject *fnames, *result;
371 int i;
372 if (num_fields) {
373 fnames = PyTuple_New(num_fields);
374 if (!fnames) return NULL;
375 } else {
376 fnames = Py_None;
377 Py_INCREF(Py_None);
378 }
379 for(i=0; i < num_fields; i++) {
380 PyObject *field = PyString_FromString(fields[i]);
381 if (!field) {
382 Py_DECREF(fnames);
383 return NULL;
384 }
385 PyTuple_SET_ITEM(fnames, i, field);
386 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000387 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000388 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000389 Py_DECREF(fnames);
390 return (PyTypeObject*)result;
391}
392
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000393static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
394{
Neal Norwitz19379f12006-04-03 04:50:58 +0000395 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000396 PyObject *s, *l = PyList_New(num_fields);
397 if (!l) return 0;
Neal Norwitz19379f12006-04-03 04:50:58 +0000398 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000399 s = PyString_FromString(attrs[i]);
400 if (!s) {
401 Py_DECREF(l);
402 return 0;
403 }
404 PyList_SET_ITEM(l, i, s);
405 }
Neal Norwitz19379f12006-04-03 04:50:58 +0000406 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
407 Py_DECREF(l);
408 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000409}
410
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000411static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
412{
413 int i, n = asdl_seq_LEN(seq);
414 PyObject *result = PyList_New(n);
415 PyObject *value;
416 if (!result)
417 return NULL;
418 for (i = 0; i < n; i++) {
419 value = func(asdl_seq_GET(seq, i));
420 if (!value) {
421 Py_DECREF(result);
422 return NULL;
423 }
424 PyList_SET_ITEM(result, i, value);
425 }
426 return result;
427}
428
429static PyObject* ast2obj_object(void *o)
430{
431 if (!o)
432 o = Py_None;
433 Py_INCREF((PyObject*)o);
434 return (PyObject*)o;
435}
436#define ast2obj_identifier ast2obj_object
437#define ast2obj_string ast2obj_object
438static PyObject* ast2obj_bool(bool b)
439{
440 return PyBool_FromLong(b);
441}
442
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000443static PyObject* ast2obj_int(bool b)
444{
445 return PyInt_FromLong(b);
446}
447
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000448static int init_types(void)
449{
Neal Norwitz19379f12006-04-03 04:50:58 +0000450 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000451 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
453 mod_type = make_type("mod", AST_type, NULL, 0);
454 if (!mod_type) return 0;
455 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000457 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000458 Interactive_type = make_type("Interactive", mod_type,
459 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Expression_type = make_type("Expression", mod_type, Expression_fields,
462 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000463 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000465 if (!Suite_type) return 0;
466 stmt_type = make_type("stmt", AST_type, NULL, 0);
467 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000468 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 FunctionDef_type = make_type("FunctionDef", stmt_type,
470 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000471 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000473 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000474 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000475 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000476 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000477 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000478 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000479 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000480 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000490 With_type = make_type("With", stmt_type, With_fields, 3);
491 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000494 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000495 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
497 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000504 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000505 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!Exec_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;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 GeneratorExp_type = make_type("GeneratorExp", expr_type,
536 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000537 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000538 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000539 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000540 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000541 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000542 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000543 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000544 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000545 if (!Repr_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;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Tuple_type) return 0;
560 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
561 if (!expr_context_type) return 0;
562 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000563 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000564 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000565 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000566 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000567 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000568 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000569 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000570 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000571 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000572 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000573 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000574 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000575 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000579 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000583 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Param_singleton) return 0;
587 slice_type = make_type("slice", AST_type, NULL, 0);
588 if (!slice_type) return 0;
589 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Ellipsis_type) 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,
Jeremy Hylton2f327c12006-04-04 04:00:23 +0000726 excepthandler_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000727 if (!excepthandler_type) return 0;
728 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
729 if (!arguments_type) return 0;
730 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
731 if (!keyword_type) return 0;
732 alias_type = make_type("alias", AST_type, alias_fields, 2);
733 if (!alias_type) return 0;
734 initialized = 1;
735 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000736}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000737
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000738mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000739Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000740{
741 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000742 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000743 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000744 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000745 return NULL;
746 }
747 p->kind = Module_kind;
748 p->v.Module.body = body;
749 return p;
750}
751
752mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000753Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000754{
755 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000756 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000757 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000758 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000759 return NULL;
760 }
761 p->kind = Interactive_kind;
762 p->v.Interactive.body = body;
763 return p;
764}
765
766mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000767Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000768{
769 mod_ty p;
770 if (!body) {
771 PyErr_SetString(PyExc_ValueError,
772 "field body is required for Expression");
773 return NULL;
774 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000775 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000776 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000777 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778 return NULL;
779 }
780 p->kind = Expression_kind;
781 p->v.Expression.body = body;
782 return p;
783}
784
785mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000786Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787{
788 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000789 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000790 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000791 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000792 return NULL;
793 }
794 p->kind = Suite_kind;
795 p->v.Suite.body = body;
796 return p;
797}
798
799stmt_ty
800FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000801 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802{
803 stmt_ty p;
804 if (!name) {
805 PyErr_SetString(PyExc_ValueError,
806 "field name is required for FunctionDef");
807 return NULL;
808 }
809 if (!args) {
810 PyErr_SetString(PyExc_ValueError,
811 "field args is required for FunctionDef");
812 return NULL;
813 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000814 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000815 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000816 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817 return NULL;
818 }
819 p->kind = FunctionDef_kind;
820 p->v.FunctionDef.name = name;
821 p->v.FunctionDef.args = args;
822 p->v.FunctionDef.body = body;
823 p->v.FunctionDef.decorators = decorators;
824 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000825 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826 return p;
827}
828
829stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000830ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
831 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832{
833 stmt_ty p;
834 if (!name) {
835 PyErr_SetString(PyExc_ValueError,
836 "field name is required for ClassDef");
837 return NULL;
838 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000839 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000841 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842 return NULL;
843 }
844 p->kind = ClassDef_kind;
845 p->v.ClassDef.name = name;
846 p->v.ClassDef.bases = bases;
847 p->v.ClassDef.body = body;
848 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000849 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000850 return p;
851}
852
853stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000854Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000855{
856 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000857 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000859 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860 return NULL;
861 }
862 p->kind = Return_kind;
863 p->v.Return.value = value;
864 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000865 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000866 return p;
867}
868
869stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000870Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871{
872 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000873 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000875 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 return NULL;
877 }
878 p->kind = Delete_kind;
879 p->v.Delete.targets = targets;
880 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000881 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000882 return p;
883}
884
885stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000886Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
887 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000888{
889 stmt_ty p;
890 if (!value) {
891 PyErr_SetString(PyExc_ValueError,
892 "field value is required for Assign");
893 return NULL;
894 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000895 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000897 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898 return NULL;
899 }
900 p->kind = Assign_kind;
901 p->v.Assign.targets = targets;
902 p->v.Assign.value = value;
903 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000904 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000905 return p;
906}
907
908stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000909AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
910 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000911{
912 stmt_ty p;
913 if (!target) {
914 PyErr_SetString(PyExc_ValueError,
915 "field target is required for AugAssign");
916 return NULL;
917 }
918 if (!op) {
919 PyErr_SetString(PyExc_ValueError,
920 "field op is required for AugAssign");
921 return NULL;
922 }
923 if (!value) {
924 PyErr_SetString(PyExc_ValueError,
925 "field value is required for AugAssign");
926 return NULL;
927 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000928 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000929 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000930 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931 return NULL;
932 }
933 p->kind = AugAssign_kind;
934 p->v.AugAssign.target = target;
935 p->v.AugAssign.op = op;
936 p->v.AugAssign.value = value;
937 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000938 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000939 return p;
940}
941
942stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000943Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
944 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000945{
946 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000947 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000948 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000949 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000950 return NULL;
951 }
952 p->kind = Print_kind;
953 p->v.Print.dest = dest;
954 p->v.Print.values = values;
955 p->v.Print.nl = nl;
956 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000957 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000958 return p;
959}
960
961stmt_ty
962For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000963 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964{
965 stmt_ty p;
966 if (!target) {
967 PyErr_SetString(PyExc_ValueError,
968 "field target is required for For");
969 return NULL;
970 }
971 if (!iter) {
972 PyErr_SetString(PyExc_ValueError,
973 "field iter is required for For");
974 return NULL;
975 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000976 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000978 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 return NULL;
980 }
981 p->kind = For_kind;
982 p->v.For.target = target;
983 p->v.For.iter = iter;
984 p->v.For.body = body;
985 p->v.For.orelse = orelse;
986 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000987 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000988 return p;
989}
990
991stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000992While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
993 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000994{
995 stmt_ty p;
996 if (!test) {
997 PyErr_SetString(PyExc_ValueError,
998 "field test is required for While");
999 return NULL;
1000 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001001 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001002 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001003 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001004 return NULL;
1005 }
1006 p->kind = While_kind;
1007 p->v.While.test = test;
1008 p->v.While.body = body;
1009 p->v.While.orelse = orelse;
1010 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001011 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001012 return p;
1013}
1014
1015stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001016If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1017 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001018{
1019 stmt_ty p;
1020 if (!test) {
1021 PyErr_SetString(PyExc_ValueError,
1022 "field test is required for If");
1023 return NULL;
1024 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001025 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001026 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001027 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001028 return NULL;
1029 }
1030 p->kind = If_kind;
1031 p->v.If.test = test;
1032 p->v.If.body = body;
1033 p->v.If.orelse = orelse;
1034 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001035 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001036 return p;
1037}
1038
1039stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001040With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001041 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001042{
1043 stmt_ty p;
1044 if (!context_expr) {
1045 PyErr_SetString(PyExc_ValueError,
1046 "field context_expr is required for With");
1047 return NULL;
1048 }
1049 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1050 if (!p) {
1051 PyErr_NoMemory();
1052 return NULL;
1053 }
1054 p->kind = With_kind;
1055 p->v.With.context_expr = context_expr;
1056 p->v.With.optional_vars = optional_vars;
1057 p->v.With.body = body;
1058 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001059 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001060 return p;
1061}
1062
1063stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001064Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1065 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001066{
1067 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001068 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001069 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001070 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071 return NULL;
1072 }
1073 p->kind = Raise_kind;
1074 p->v.Raise.type = type;
1075 p->v.Raise.inst = inst;
1076 p->v.Raise.tback = tback;
1077 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001078 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 return p;
1080}
1081
1082stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001083TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001084 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085{
1086 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001087 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001088 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001089 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001090 return NULL;
1091 }
1092 p->kind = TryExcept_kind;
1093 p->v.TryExcept.body = body;
1094 p->v.TryExcept.handlers = handlers;
1095 p->v.TryExcept.orelse = orelse;
1096 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001097 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 return p;
1099}
1100
1101stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001102TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1103 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104{
1105 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001106 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001107 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001108 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001109 return NULL;
1110 }
1111 p->kind = TryFinally_kind;
1112 p->v.TryFinally.body = body;
1113 p->v.TryFinally.finalbody = finalbody;
1114 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001115 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 return p;
1117}
1118
1119stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001120Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001121{
1122 stmt_ty p;
1123 if (!test) {
1124 PyErr_SetString(PyExc_ValueError,
1125 "field test is required for Assert");
1126 return NULL;
1127 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001128 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001129 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001130 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 return NULL;
1132 }
1133 p->kind = Assert_kind;
1134 p->v.Assert.test = test;
1135 p->v.Assert.msg = msg;
1136 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001137 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001138 return p;
1139}
1140
1141stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001142Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001143{
1144 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001145 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001146 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001147 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001148 return NULL;
1149 }
1150 p->kind = Import_kind;
1151 p->v.Import.names = names;
1152 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001153 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154 return p;
1155}
1156
1157stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001158ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1159 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001160{
1161 stmt_ty p;
1162 if (!module) {
1163 PyErr_SetString(PyExc_ValueError,
1164 "field module is required for ImportFrom");
1165 return NULL;
1166 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001167 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001169 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001170 return NULL;
1171 }
1172 p->kind = ImportFrom_kind;
1173 p->v.ImportFrom.module = module;
1174 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001175 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001176 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001177 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001178 return p;
1179}
1180
1181stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001182Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1183 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001184{
1185 stmt_ty p;
1186 if (!body) {
1187 PyErr_SetString(PyExc_ValueError,
1188 "field body is required for Exec");
1189 return NULL;
1190 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001191 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001193 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194 return NULL;
1195 }
1196 p->kind = Exec_kind;
1197 p->v.Exec.body = body;
1198 p->v.Exec.globals = globals;
1199 p->v.Exec.locals = locals;
1200 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001201 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001202 return p;
1203}
1204
1205stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001206Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207{
1208 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001209 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001211 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001212 return NULL;
1213 }
1214 p->kind = Global_kind;
1215 p->v.Global.names = names;
1216 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001217 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return p;
1219}
1220
1221stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001222Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223{
1224 stmt_ty p;
1225 if (!value) {
1226 PyErr_SetString(PyExc_ValueError,
1227 "field value is required for Expr");
1228 return NULL;
1229 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001230 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001232 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001233 return NULL;
1234 }
1235 p->kind = Expr_kind;
1236 p->v.Expr.value = value;
1237 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001238 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239 return p;
1240}
1241
1242stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001243Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244{
1245 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001246 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001247 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001248 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 return NULL;
1250 }
1251 p->kind = Pass_kind;
1252 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001253 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001254 return p;
1255}
1256
1257stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001258Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259{
1260 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001261 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001262 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001263 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264 return NULL;
1265 }
1266 p->kind = Break_kind;
1267 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001268 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001269 return p;
1270}
1271
1272stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001273Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001274{
1275 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001276 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001277 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001278 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001279 return NULL;
1280 }
1281 p->kind = Continue_kind;
1282 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001283 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001284 return p;
1285}
1286
1287expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001288BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1289 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290{
1291 expr_ty p;
1292 if (!op) {
1293 PyErr_SetString(PyExc_ValueError,
1294 "field op is required for BoolOp");
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 = BoolOp_kind;
1303 p->v.BoolOp.op = op;
1304 p->v.BoolOp.values = values;
1305 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001306 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001307 return p;
1308}
1309
1310expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001311BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1312 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001313{
1314 expr_ty p;
1315 if (!left) {
1316 PyErr_SetString(PyExc_ValueError,
1317 "field left is required for BinOp");
1318 return NULL;
1319 }
1320 if (!op) {
1321 PyErr_SetString(PyExc_ValueError,
1322 "field op is required for BinOp");
1323 return NULL;
1324 }
1325 if (!right) {
1326 PyErr_SetString(PyExc_ValueError,
1327 "field right is required for BinOp");
1328 return NULL;
1329 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001330 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001331 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001332 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001333 return NULL;
1334 }
1335 p->kind = BinOp_kind;
1336 p->v.BinOp.left = left;
1337 p->v.BinOp.op = op;
1338 p->v.BinOp.right = right;
1339 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001340 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001341 return p;
1342}
1343
1344expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001345UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1346 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001347{
1348 expr_ty p;
1349 if (!op) {
1350 PyErr_SetString(PyExc_ValueError,
1351 "field op is required for UnaryOp");
1352 return NULL;
1353 }
1354 if (!operand) {
1355 PyErr_SetString(PyExc_ValueError,
1356 "field operand is required for UnaryOp");
1357 return NULL;
1358 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001359 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001360 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001361 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001362 return NULL;
1363 }
1364 p->kind = UnaryOp_kind;
1365 p->v.UnaryOp.op = op;
1366 p->v.UnaryOp.operand = operand;
1367 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001368 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001369 return p;
1370}
1371
1372expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001373Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1374 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001375{
1376 expr_ty p;
1377 if (!args) {
1378 PyErr_SetString(PyExc_ValueError,
1379 "field args is required for Lambda");
1380 return NULL;
1381 }
1382 if (!body) {
1383 PyErr_SetString(PyExc_ValueError,
1384 "field body is required for Lambda");
1385 return NULL;
1386 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001387 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001388 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001389 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001390 return NULL;
1391 }
1392 p->kind = Lambda_kind;
1393 p->v.Lambda.args = args;
1394 p->v.Lambda.body = body;
1395 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001396 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001397 return p;
1398}
1399
1400expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001401IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1402 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001403{
1404 expr_ty p;
1405 if (!test) {
1406 PyErr_SetString(PyExc_ValueError,
1407 "field test is required for IfExp");
1408 return NULL;
1409 }
1410 if (!body) {
1411 PyErr_SetString(PyExc_ValueError,
1412 "field body is required for IfExp");
1413 return NULL;
1414 }
1415 if (!orelse) {
1416 PyErr_SetString(PyExc_ValueError,
1417 "field orelse is required for IfExp");
1418 return NULL;
1419 }
1420 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1421 if (!p) {
1422 PyErr_NoMemory();
1423 return NULL;
1424 }
1425 p->kind = IfExp_kind;
1426 p->v.IfExp.test = test;
1427 p->v.IfExp.body = body;
1428 p->v.IfExp.orelse = orelse;
1429 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001430 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001431 return p;
1432}
1433
1434expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001435Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1436 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001437{
1438 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001439 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001441 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001442 return NULL;
1443 }
1444 p->kind = Dict_kind;
1445 p->v.Dict.keys = keys;
1446 p->v.Dict.values = values;
1447 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001448 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001449 return p;
1450}
1451
1452expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001453ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1454 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001455{
1456 expr_ty p;
1457 if (!elt) {
1458 PyErr_SetString(PyExc_ValueError,
1459 "field elt is required for ListComp");
1460 return NULL;
1461 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001462 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001464 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001465 return NULL;
1466 }
1467 p->kind = ListComp_kind;
1468 p->v.ListComp.elt = elt;
1469 p->v.ListComp.generators = generators;
1470 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001471 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001472 return p;
1473}
1474
1475expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001476GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1477 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001478{
1479 expr_ty p;
1480 if (!elt) {
1481 PyErr_SetString(PyExc_ValueError,
1482 "field elt is required for GeneratorExp");
1483 return NULL;
1484 }
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 = GeneratorExp_kind;
1491 p->v.GeneratorExp.elt = elt;
1492 p->v.GeneratorExp.generators = generators;
1493 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001494 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001495 return p;
1496}
1497
1498expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001499Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500{
1501 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001502 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001503 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001504 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001505 return NULL;
1506 }
1507 p->kind = Yield_kind;
1508 p->v.Yield.value = value;
1509 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001510 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001511 return p;
1512}
1513
1514expr_ty
Martin v. Löwis0cc56e52006-04-13 12:29:43 +00001515Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1516 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001517{
1518 expr_ty p;
1519 if (!left) {
1520 PyErr_SetString(PyExc_ValueError,
1521 "field left is required for Compare");
1522 return NULL;
1523 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001524 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001525 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001526 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001527 return NULL;
1528 }
1529 p->kind = Compare_kind;
1530 p->v.Compare.left = left;
1531 p->v.Compare.ops = ops;
1532 p->v.Compare.comparators = comparators;
1533 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001534 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001535 return p;
1536}
1537
1538expr_ty
1539Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001540 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001541{
1542 expr_ty p;
1543 if (!func) {
1544 PyErr_SetString(PyExc_ValueError,
1545 "field func is required for Call");
1546 return NULL;
1547 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001548 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001550 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551 return NULL;
1552 }
1553 p->kind = Call_kind;
1554 p->v.Call.func = func;
1555 p->v.Call.args = args;
1556 p->v.Call.keywords = keywords;
1557 p->v.Call.starargs = starargs;
1558 p->v.Call.kwargs = kwargs;
1559 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001560 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561 return p;
1562}
1563
1564expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001565Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001566{
1567 expr_ty p;
1568 if (!value) {
1569 PyErr_SetString(PyExc_ValueError,
1570 "field value is required for Repr");
1571 return NULL;
1572 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001573 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001574 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001575 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001576 return NULL;
1577 }
1578 p->kind = Repr_kind;
1579 p->v.Repr.value = value;
1580 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001581 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001582 return p;
1583}
1584
1585expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001586Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001587{
1588 expr_ty p;
1589 if (!n) {
1590 PyErr_SetString(PyExc_ValueError,
1591 "field n is required for Num");
1592 return NULL;
1593 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001594 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001595 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001596 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001597 return NULL;
1598 }
1599 p->kind = Num_kind;
1600 p->v.Num.n = n;
1601 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001602 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001603 return p;
1604}
1605
1606expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001607Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001608{
1609 expr_ty p;
1610 if (!s) {
1611 PyErr_SetString(PyExc_ValueError,
1612 "field s is required for Str");
1613 return NULL;
1614 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001615 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001616 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001617 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001618 return NULL;
1619 }
1620 p->kind = Str_kind;
1621 p->v.Str.s = s;
1622 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001623 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001624 return p;
1625}
1626
1627expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001628Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1629 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001630{
1631 expr_ty p;
1632 if (!value) {
1633 PyErr_SetString(PyExc_ValueError,
1634 "field value is required for Attribute");
1635 return NULL;
1636 }
1637 if (!attr) {
1638 PyErr_SetString(PyExc_ValueError,
1639 "field attr is required for Attribute");
1640 return NULL;
1641 }
1642 if (!ctx) {
1643 PyErr_SetString(PyExc_ValueError,
1644 "field ctx is required for Attribute");
1645 return NULL;
1646 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001647 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001648 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001649 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001650 return NULL;
1651 }
1652 p->kind = Attribute_kind;
1653 p->v.Attribute.value = value;
1654 p->v.Attribute.attr = attr;
1655 p->v.Attribute.ctx = ctx;
1656 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001657 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001658 return p;
1659}
1660
1661expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001662Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1663 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001664{
1665 expr_ty p;
1666 if (!value) {
1667 PyErr_SetString(PyExc_ValueError,
1668 "field value is required for Subscript");
1669 return NULL;
1670 }
1671 if (!slice) {
1672 PyErr_SetString(PyExc_ValueError,
1673 "field slice is required for Subscript");
1674 return NULL;
1675 }
1676 if (!ctx) {
1677 PyErr_SetString(PyExc_ValueError,
1678 "field ctx is required for Subscript");
1679 return NULL;
1680 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001681 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001682 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001683 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 return NULL;
1685 }
1686 p->kind = Subscript_kind;
1687 p->v.Subscript.value = value;
1688 p->v.Subscript.slice = slice;
1689 p->v.Subscript.ctx = ctx;
1690 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001691 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001692 return p;
1693}
1694
1695expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001696Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1697 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001698{
1699 expr_ty p;
1700 if (!id) {
1701 PyErr_SetString(PyExc_ValueError,
1702 "field id is required for Name");
1703 return NULL;
1704 }
1705 if (!ctx) {
1706 PyErr_SetString(PyExc_ValueError,
1707 "field ctx is required for Name");
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 = Name_kind;
1716 p->v.Name.id = id;
1717 p->v.Name.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 +00001724List(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 List");
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 = List_kind;
1739 p->v.List.elts = elts;
1740 p->v.List.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
1746expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001747Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1748 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001749{
1750 expr_ty p;
1751 if (!ctx) {
1752 PyErr_SetString(PyExc_ValueError,
1753 "field ctx is required for Tuple");
1754 return NULL;
1755 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001756 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001757 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001758 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001759 return NULL;
1760 }
1761 p->kind = Tuple_kind;
1762 p->v.Tuple.elts = elts;
1763 p->v.Tuple.ctx = ctx;
1764 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001765 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001766 return p;
1767}
1768
1769slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001770Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771{
1772 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001773 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001774 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001775 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 return NULL;
1777 }
1778 p->kind = Ellipsis_kind;
1779 return p;
1780}
1781
1782slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001783Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001784{
1785 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001786 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001788 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001789 return NULL;
1790 }
1791 p->kind = Slice_kind;
1792 p->v.Slice.lower = lower;
1793 p->v.Slice.upper = upper;
1794 p->v.Slice.step = step;
1795 return p;
1796}
1797
1798slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001799ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001800{
1801 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001802 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001804 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805 return NULL;
1806 }
1807 p->kind = ExtSlice_kind;
1808 p->v.ExtSlice.dims = dims;
1809 return p;
1810}
1811
1812slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001813Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001814{
1815 slice_ty p;
1816 if (!value) {
1817 PyErr_SetString(PyExc_ValueError,
1818 "field value is required for Index");
1819 return NULL;
1820 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001821 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001822 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001823 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001824 return NULL;
1825 }
1826 p->kind = Index_kind;
1827 p->v.Index.value = value;
1828 return p;
1829}
1830
1831comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001832comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833{
1834 comprehension_ty p;
1835 if (!target) {
1836 PyErr_SetString(PyExc_ValueError,
1837 "field target is required for comprehension");
1838 return NULL;
1839 }
1840 if (!iter) {
1841 PyErr_SetString(PyExc_ValueError,
1842 "field iter is required for comprehension");
1843 return NULL;
1844 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001845 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001847 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 return NULL;
1849 }
1850 p->target = target;
1851 p->iter = iter;
1852 p->ifs = ifs;
1853 return p;
1854}
1855
1856excepthandler_ty
Jeremy Hylton2f327c12006-04-04 04:00:23 +00001857excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1858 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001859{
1860 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001861 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001862 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001863 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864 return NULL;
1865 }
1866 p->type = type;
1867 p->name = name;
1868 p->body = body;
Jeremy Hylton2f327c12006-04-04 04:00:23 +00001869 p->lineno = lineno;
1870 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001871 return p;
1872}
1873
1874arguments_ty
1875arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001876 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877{
1878 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001879 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001880 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001881 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882 return NULL;
1883 }
1884 p->args = args;
1885 p->vararg = vararg;
1886 p->kwarg = kwarg;
1887 p->defaults = defaults;
1888 return p;
1889}
1890
1891keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001892keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001893{
1894 keyword_ty p;
1895 if (!arg) {
1896 PyErr_SetString(PyExc_ValueError,
1897 "field arg is required for keyword");
1898 return NULL;
1899 }
1900 if (!value) {
1901 PyErr_SetString(PyExc_ValueError,
1902 "field value is required for keyword");
1903 return NULL;
1904 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001905 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001907 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001908 return NULL;
1909 }
1910 p->arg = arg;
1911 p->value = value;
1912 return p;
1913}
1914
1915alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001916alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001917{
1918 alias_ty p;
1919 if (!name) {
1920 PyErr_SetString(PyExc_ValueError,
1921 "field name is required for alias");
1922 return NULL;
1923 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001924 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001925 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001926 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001927 return NULL;
1928 }
1929 p->name = name;
1930 p->asname = asname;
1931 return p;
1932}
1933
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001934
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001935PyObject*
1936ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001937{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001938 mod_ty o = (mod_ty)_o;
1939 PyObject *result = NULL, *value = NULL;
1940 if (!o) {
1941 Py_INCREF(Py_None);
1942 return Py_None;
1943 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001944
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001945 switch (o->kind) {
1946 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001947 result = PyType_GenericNew(Module_type, NULL, NULL);
1948 if (!result) goto failed;
1949 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1950 if (!value) goto failed;
1951 if (PyObject_SetAttrString(result, "body", value) == -1)
1952 goto failed;
1953 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001954 break;
1955 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001956 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1957 if (!result) goto failed;
1958 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1959 if (!value) goto failed;
1960 if (PyObject_SetAttrString(result, "body", value) == -1)
1961 goto failed;
1962 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001963 break;
1964 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001965 result = PyType_GenericNew(Expression_type, NULL, NULL);
1966 if (!result) goto failed;
1967 value = ast2obj_expr(o->v.Expression.body);
1968 if (!value) goto failed;
1969 if (PyObject_SetAttrString(result, "body", value) == -1)
1970 goto failed;
1971 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001972 break;
1973 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001974 result = PyType_GenericNew(Suite_type, NULL, NULL);
1975 if (!result) goto failed;
1976 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1977 if (!value) goto failed;
1978 if (PyObject_SetAttrString(result, "body", value) == -1)
1979 goto failed;
1980 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001981 break;
1982 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001983 return result;
1984failed:
1985 Py_XDECREF(value);
1986 Py_XDECREF(result);
1987 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001988}
1989
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001990PyObject*
1991ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001992{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001993 stmt_ty o = (stmt_ty)_o;
1994 PyObject *result = NULL, *value = NULL;
1995 if (!o) {
1996 Py_INCREF(Py_None);
1997 return Py_None;
1998 }
1999
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002000 switch (o->kind) {
2001 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002002 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2003 if (!result) goto failed;
2004 value = ast2obj_identifier(o->v.FunctionDef.name);
2005 if (!value) goto failed;
2006 if (PyObject_SetAttrString(result, "name", value) == -1)
2007 goto failed;
2008 Py_DECREF(value);
2009 value = ast2obj_arguments(o->v.FunctionDef.args);
2010 if (!value) goto failed;
2011 if (PyObject_SetAttrString(result, "args", value) == -1)
2012 goto failed;
2013 Py_DECREF(value);
2014 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2015 if (!value) goto failed;
2016 if (PyObject_SetAttrString(result, "body", value) == -1)
2017 goto failed;
2018 Py_DECREF(value);
2019 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002024 break;
2025 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002026 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2027 if (!result) goto failed;
2028 value = ast2obj_identifier(o->v.ClassDef.name);
2029 if (!value) goto failed;
2030 if (PyObject_SetAttrString(result, "name", value) == -1)
2031 goto failed;
2032 Py_DECREF(value);
2033 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2034 if (!value) goto failed;
2035 if (PyObject_SetAttrString(result, "bases", value) == -1)
2036 goto failed;
2037 Py_DECREF(value);
2038 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2039 if (!value) goto failed;
2040 if (PyObject_SetAttrString(result, "body", value) == -1)
2041 goto failed;
2042 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002043 break;
2044 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002045 result = PyType_GenericNew(Return_type, NULL, NULL);
2046 if (!result) goto failed;
2047 value = ast2obj_expr(o->v.Return.value);
2048 if (!value) goto failed;
2049 if (PyObject_SetAttrString(result, "value", value) == -1)
2050 goto failed;
2051 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002052 break;
2053 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002054 result = PyType_GenericNew(Delete_type, NULL, NULL);
2055 if (!result) goto failed;
2056 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2057 if (!value) goto failed;
2058 if (PyObject_SetAttrString(result, "targets", value) == -1)
2059 goto failed;
2060 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061 break;
2062 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002063 result = PyType_GenericNew(Assign_type, NULL, NULL);
2064 if (!result) goto failed;
2065 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "targets", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
2070 value = ast2obj_expr(o->v.Assign.value);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "value", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002075 break;
2076 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002077 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2078 if (!result) goto failed;
2079 value = ast2obj_expr(o->v.AugAssign.target);
2080 if (!value) goto failed;
2081 if (PyObject_SetAttrString(result, "target", value) == -1)
2082 goto failed;
2083 Py_DECREF(value);
2084 value = ast2obj_operator(o->v.AugAssign.op);
2085 if (!value) goto failed;
2086 if (PyObject_SetAttrString(result, "op", value) == -1)
2087 goto failed;
2088 Py_DECREF(value);
2089 value = ast2obj_expr(o->v.AugAssign.value);
2090 if (!value) goto failed;
2091 if (PyObject_SetAttrString(result, "value", value) == -1)
2092 goto failed;
2093 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002094 break;
2095 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002096 result = PyType_GenericNew(Print_type, NULL, NULL);
2097 if (!result) goto failed;
2098 value = ast2obj_expr(o->v.Print.dest);
2099 if (!value) goto failed;
2100 if (PyObject_SetAttrString(result, "dest", value) == -1)
2101 goto failed;
2102 Py_DECREF(value);
2103 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2104 if (!value) goto failed;
2105 if (PyObject_SetAttrString(result, "values", value) == -1)
2106 goto failed;
2107 Py_DECREF(value);
2108 value = ast2obj_bool(o->v.Print.nl);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "nl", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002113 break;
2114 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002115 result = PyType_GenericNew(For_type, NULL, NULL);
2116 if (!result) goto failed;
2117 value = ast2obj_expr(o->v.For.target);
2118 if (!value) goto failed;
2119 if (PyObject_SetAttrString(result, "target", value) == -1)
2120 goto failed;
2121 Py_DECREF(value);
2122 value = ast2obj_expr(o->v.For.iter);
2123 if (!value) goto failed;
2124 if (PyObject_SetAttrString(result, "iter", value) == -1)
2125 goto failed;
2126 Py_DECREF(value);
2127 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2128 if (!value) goto failed;
2129 if (PyObject_SetAttrString(result, "body", value) == -1)
2130 goto failed;
2131 Py_DECREF(value);
2132 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002137 break;
2138 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002139 result = PyType_GenericNew(While_type, NULL, NULL);
2140 if (!result) goto failed;
2141 value = ast2obj_expr(o->v.While.test);
2142 if (!value) goto failed;
2143 if (PyObject_SetAttrString(result, "test", value) == -1)
2144 goto failed;
2145 Py_DECREF(value);
2146 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2147 if (!value) goto failed;
2148 if (PyObject_SetAttrString(result, "body", value) == -1)
2149 goto failed;
2150 Py_DECREF(value);
2151 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2152 if (!value) goto failed;
2153 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2154 goto failed;
2155 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002156 break;
2157 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002158 result = PyType_GenericNew(If_type, NULL, NULL);
2159 if (!result) goto failed;
2160 value = ast2obj_expr(o->v.If.test);
2161 if (!value) goto failed;
2162 if (PyObject_SetAttrString(result, "test", value) == -1)
2163 goto failed;
2164 Py_DECREF(value);
2165 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2166 if (!value) goto failed;
2167 if (PyObject_SetAttrString(result, "body", value) == -1)
2168 goto failed;
2169 Py_DECREF(value);
2170 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2173 goto failed;
2174 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002175 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002176 case With_kind:
2177 result = PyType_GenericNew(With_type, NULL, NULL);
2178 if (!result) goto failed;
2179 value = ast2obj_expr(o->v.With.context_expr);
2180 if (!value) goto failed;
2181 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2182 goto failed;
2183 Py_DECREF(value);
2184 value = ast2obj_expr(o->v.With.optional_vars);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2187 -1)
2188 goto failed;
2189 Py_DECREF(value);
2190 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "body", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002196 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002197 result = PyType_GenericNew(Raise_type, NULL, NULL);
2198 if (!result) goto failed;
2199 value = ast2obj_expr(o->v.Raise.type);
2200 if (!value) goto failed;
2201 if (PyObject_SetAttrString(result, "type", value) == -1)
2202 goto failed;
2203 Py_DECREF(value);
2204 value = ast2obj_expr(o->v.Raise.inst);
2205 if (!value) goto failed;
2206 if (PyObject_SetAttrString(result, "inst", value) == -1)
2207 goto failed;
2208 Py_DECREF(value);
2209 value = ast2obj_expr(o->v.Raise.tback);
2210 if (!value) goto failed;
2211 if (PyObject_SetAttrString(result, "tback", value) == -1)
2212 goto failed;
2213 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002214 break;
2215 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002216 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2217 if (!result) goto failed;
2218 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2219 if (!value) goto failed;
2220 if (PyObject_SetAttrString(result, "body", value) == -1)
2221 goto failed;
2222 Py_DECREF(value);
2223 value = ast2obj_list(o->v.TryExcept.handlers,
2224 ast2obj_excepthandler);
2225 if (!value) goto failed;
2226 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2227 goto failed;
2228 Py_DECREF(value);
2229 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002234 break;
2235 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002236 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2237 if (!result) goto failed;
2238 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2239 if (!value) goto failed;
2240 if (PyObject_SetAttrString(result, "body", value) == -1)
2241 goto failed;
2242 Py_DECREF(value);
2243 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002248 break;
2249 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002250 result = PyType_GenericNew(Assert_type, NULL, NULL);
2251 if (!result) goto failed;
2252 value = ast2obj_expr(o->v.Assert.test);
2253 if (!value) goto failed;
2254 if (PyObject_SetAttrString(result, "test", value) == -1)
2255 goto failed;
2256 Py_DECREF(value);
2257 value = ast2obj_expr(o->v.Assert.msg);
2258 if (!value) goto failed;
2259 if (PyObject_SetAttrString(result, "msg", value) == -1)
2260 goto failed;
2261 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262 break;
2263 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002264 result = PyType_GenericNew(Import_type, NULL, NULL);
2265 if (!result) goto failed;
2266 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2267 if (!value) goto failed;
2268 if (PyObject_SetAttrString(result, "names", value) == -1)
2269 goto failed;
2270 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002271 break;
2272 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002273 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2274 if (!result) goto failed;
2275 value = ast2obj_identifier(o->v.ImportFrom.module);
2276 if (!value) goto failed;
2277 if (PyObject_SetAttrString(result, "module", value) == -1)
2278 goto failed;
2279 Py_DECREF(value);
2280 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2281 if (!value) goto failed;
2282 if (PyObject_SetAttrString(result, "names", value) == -1)
2283 goto failed;
2284 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002285 value = ast2obj_int(o->v.ImportFrom.level);
2286 if (!value) goto failed;
2287 if (PyObject_SetAttrString(result, "level", value) == -1)
2288 goto failed;
2289 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002290 break;
2291 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002292 result = PyType_GenericNew(Exec_type, NULL, NULL);
2293 if (!result) goto failed;
2294 value = ast2obj_expr(o->v.Exec.body);
2295 if (!value) goto failed;
2296 if (PyObject_SetAttrString(result, "body", value) == -1)
2297 goto failed;
2298 Py_DECREF(value);
2299 value = ast2obj_expr(o->v.Exec.globals);
2300 if (!value) goto failed;
2301 if (PyObject_SetAttrString(result, "globals", value) == -1)
2302 goto failed;
2303 Py_DECREF(value);
2304 value = ast2obj_expr(o->v.Exec.locals);
2305 if (!value) goto failed;
2306 if (PyObject_SetAttrString(result, "locals", value) == -1)
2307 goto failed;
2308 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002309 break;
2310 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002311 result = PyType_GenericNew(Global_type, NULL, NULL);
2312 if (!result) goto failed;
2313 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2314 if (!value) goto failed;
2315 if (PyObject_SetAttrString(result, "names", value) == -1)
2316 goto failed;
2317 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002318 break;
2319 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002320 result = PyType_GenericNew(Expr_type, NULL, NULL);
2321 if (!result) goto failed;
2322 value = ast2obj_expr(o->v.Expr.value);
2323 if (!value) goto failed;
2324 if (PyObject_SetAttrString(result, "value", value) == -1)
2325 goto failed;
2326 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002327 break;
2328 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002329 result = PyType_GenericNew(Pass_type, NULL, NULL);
2330 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002331 break;
2332 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002333 result = PyType_GenericNew(Break_type, NULL, NULL);
2334 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002335 break;
2336 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002337 result = PyType_GenericNew(Continue_type, NULL, NULL);
2338 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002339 break;
2340 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002341 value = ast2obj_int(o->lineno);
2342 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002343 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2344 goto failed;
2345 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002346 value = ast2obj_int(o->col_offset);
2347 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002348 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2349 goto failed;
2350 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002351 return result;
2352failed:
2353 Py_XDECREF(value);
2354 Py_XDECREF(result);
2355 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002356}
2357
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002358PyObject*
2359ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002360{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002361 expr_ty o = (expr_ty)_o;
2362 PyObject *result = NULL, *value = NULL;
2363 if (!o) {
2364 Py_INCREF(Py_None);
2365 return Py_None;
2366 }
2367
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002368 switch (o->kind) {
2369 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002370 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2371 if (!result) goto failed;
2372 value = ast2obj_boolop(o->v.BoolOp.op);
2373 if (!value) goto failed;
2374 if (PyObject_SetAttrString(result, "op", value) == -1)
2375 goto failed;
2376 Py_DECREF(value);
2377 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "values", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002382 break;
2383 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002384 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2385 if (!result) goto failed;
2386 value = ast2obj_expr(o->v.BinOp.left);
2387 if (!value) goto failed;
2388 if (PyObject_SetAttrString(result, "left", value) == -1)
2389 goto failed;
2390 Py_DECREF(value);
2391 value = ast2obj_operator(o->v.BinOp.op);
2392 if (!value) goto failed;
2393 if (PyObject_SetAttrString(result, "op", value) == -1)
2394 goto failed;
2395 Py_DECREF(value);
2396 value = ast2obj_expr(o->v.BinOp.right);
2397 if (!value) goto failed;
2398 if (PyObject_SetAttrString(result, "right", value) == -1)
2399 goto failed;
2400 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002401 break;
2402 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002403 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2404 if (!result) goto failed;
2405 value = ast2obj_unaryop(o->v.UnaryOp.op);
2406 if (!value) goto failed;
2407 if (PyObject_SetAttrString(result, "op", value) == -1)
2408 goto failed;
2409 Py_DECREF(value);
2410 value = ast2obj_expr(o->v.UnaryOp.operand);
2411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "operand", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002415 break;
2416 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002417 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2418 if (!result) goto failed;
2419 value = ast2obj_arguments(o->v.Lambda.args);
2420 if (!value) goto failed;
2421 if (PyObject_SetAttrString(result, "args", value) == -1)
2422 goto failed;
2423 Py_DECREF(value);
2424 value = ast2obj_expr(o->v.Lambda.body);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "body", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002429 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002430 case IfExp_kind:
2431 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2432 if (!result) goto failed;
2433 value = ast2obj_expr(o->v.IfExp.test);
2434 if (!value) goto failed;
2435 if (PyObject_SetAttrString(result, "test", value) == -1)
2436 goto failed;
2437 Py_DECREF(value);
2438 value = ast2obj_expr(o->v.IfExp.body);
2439 if (!value) goto failed;
2440 if (PyObject_SetAttrString(result, "body", value) == -1)
2441 goto failed;
2442 Py_DECREF(value);
2443 value = ast2obj_expr(o->v.IfExp.orelse);
2444 if (!value) goto failed;
2445 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2446 goto failed;
2447 Py_DECREF(value);
2448 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002449 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002450 result = PyType_GenericNew(Dict_type, NULL, NULL);
2451 if (!result) goto failed;
2452 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2453 if (!value) goto failed;
2454 if (PyObject_SetAttrString(result, "keys", value) == -1)
2455 goto failed;
2456 Py_DECREF(value);
2457 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2458 if (!value) goto failed;
2459 if (PyObject_SetAttrString(result, "values", value) == -1)
2460 goto failed;
2461 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002462 break;
2463 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002464 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2465 if (!result) goto failed;
2466 value = ast2obj_expr(o->v.ListComp.elt);
2467 if (!value) goto failed;
2468 if (PyObject_SetAttrString(result, "elt", value) == -1)
2469 goto failed;
2470 Py_DECREF(value);
2471 value = ast2obj_list(o->v.ListComp.generators,
2472 ast2obj_comprehension);
2473 if (!value) goto failed;
2474 if (PyObject_SetAttrString(result, "generators", value) == -1)
2475 goto failed;
2476 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477 break;
2478 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002479 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2480 if (!result) goto failed;
2481 value = ast2obj_expr(o->v.GeneratorExp.elt);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "elt", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 value = ast2obj_list(o->v.GeneratorExp.generators,
2487 ast2obj_comprehension);
2488 if (!value) goto failed;
2489 if (PyObject_SetAttrString(result, "generators", value) == -1)
2490 goto failed;
2491 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002492 break;
2493 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002494 result = PyType_GenericNew(Yield_type, NULL, NULL);
2495 if (!result) goto failed;
2496 value = ast2obj_expr(o->v.Yield.value);
2497 if (!value) goto failed;
2498 if (PyObject_SetAttrString(result, "value", value) == -1)
2499 goto failed;
2500 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002501 break;
2502 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002503 result = PyType_GenericNew(Compare_type, NULL, NULL);
2504 if (!result) goto failed;
2505 value = ast2obj_expr(o->v.Compare.left);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "left", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002510 {
2511 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2512 value = PyList_New(n);
2513 if (!value) goto failed;
2514 for(i = 0; i < n; i++)
Martin v. Löwis0cc56e52006-04-13 12:29:43 +00002515 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002516 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002517 if (!value) goto failed;
2518 if (PyObject_SetAttrString(result, "ops", value) == -1)
2519 goto failed;
2520 Py_DECREF(value);
2521 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002526 break;
2527 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002528 result = PyType_GenericNew(Call_type, NULL, NULL);
2529 if (!result) goto failed;
2530 value = ast2obj_expr(o->v.Call.func);
2531 if (!value) goto failed;
2532 if (PyObject_SetAttrString(result, "func", value) == -1)
2533 goto failed;
2534 Py_DECREF(value);
2535 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2536 if (!value) goto failed;
2537 if (PyObject_SetAttrString(result, "args", value) == -1)
2538 goto failed;
2539 Py_DECREF(value);
2540 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2541 if (!value) goto failed;
2542 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2543 goto failed;
2544 Py_DECREF(value);
2545 value = ast2obj_expr(o->v.Call.starargs);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
2550 value = ast2obj_expr(o->v.Call.kwargs);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002555 break;
2556 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002557 result = PyType_GenericNew(Repr_type, NULL, NULL);
2558 if (!result) goto failed;
2559 value = ast2obj_expr(o->v.Repr.value);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "value", value) == -1)
2562 goto failed;
2563 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002564 break;
2565 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002566 result = PyType_GenericNew(Num_type, NULL, NULL);
2567 if (!result) goto failed;
2568 value = ast2obj_object(o->v.Num.n);
2569 if (!value) goto failed;
2570 if (PyObject_SetAttrString(result, "n", value) == -1)
2571 goto failed;
2572 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002573 break;
2574 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002575 result = PyType_GenericNew(Str_type, NULL, NULL);
2576 if (!result) goto failed;
2577 value = ast2obj_string(o->v.Str.s);
2578 if (!value) goto failed;
2579 if (PyObject_SetAttrString(result, "s", value) == -1)
2580 goto failed;
2581 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002582 break;
2583 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002584 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2585 if (!result) goto failed;
2586 value = ast2obj_expr(o->v.Attribute.value);
2587 if (!value) goto failed;
2588 if (PyObject_SetAttrString(result, "value", value) == -1)
2589 goto failed;
2590 Py_DECREF(value);
2591 value = ast2obj_identifier(o->v.Attribute.attr);
2592 if (!value) goto failed;
2593 if (PyObject_SetAttrString(result, "attr", value) == -1)
2594 goto failed;
2595 Py_DECREF(value);
2596 value = ast2obj_expr_context(o->v.Attribute.ctx);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002601 break;
2602 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002603 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2604 if (!result) goto failed;
2605 value = ast2obj_expr(o->v.Subscript.value);
2606 if (!value) goto failed;
2607 if (PyObject_SetAttrString(result, "value", value) == -1)
2608 goto failed;
2609 Py_DECREF(value);
2610 value = ast2obj_slice(o->v.Subscript.slice);
2611 if (!value) goto failed;
2612 if (PyObject_SetAttrString(result, "slice", value) == -1)
2613 goto failed;
2614 Py_DECREF(value);
2615 value = ast2obj_expr_context(o->v.Subscript.ctx);
2616 if (!value) goto failed;
2617 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2618 goto failed;
2619 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002620 break;
2621 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002622 result = PyType_GenericNew(Name_type, NULL, NULL);
2623 if (!result) goto failed;
2624 value = ast2obj_identifier(o->v.Name.id);
2625 if (!value) goto failed;
2626 if (PyObject_SetAttrString(result, "id", value) == -1)
2627 goto failed;
2628 Py_DECREF(value);
2629 value = ast2obj_expr_context(o->v.Name.ctx);
2630 if (!value) goto failed;
2631 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2632 goto failed;
2633 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002634 break;
2635 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002636 result = PyType_GenericNew(List_type, NULL, NULL);
2637 if (!result) goto failed;
2638 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2639 if (!value) goto failed;
2640 if (PyObject_SetAttrString(result, "elts", value) == -1)
2641 goto failed;
2642 Py_DECREF(value);
2643 value = ast2obj_expr_context(o->v.List.ctx);
2644 if (!value) goto failed;
2645 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2646 goto failed;
2647 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002648 break;
2649 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002650 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2651 if (!result) goto failed;
2652 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2653 if (!value) goto failed;
2654 if (PyObject_SetAttrString(result, "elts", value) == -1)
2655 goto failed;
2656 Py_DECREF(value);
2657 value = ast2obj_expr_context(o->v.Tuple.ctx);
2658 if (!value) goto failed;
2659 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2660 goto failed;
2661 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002662 break;
2663 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002664 value = ast2obj_int(o->lineno);
2665 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002666 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2667 goto failed;
2668 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002669 value = ast2obj_int(o->col_offset);
2670 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002671 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2672 goto failed;
2673 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002674 return result;
2675failed:
2676 Py_XDECREF(value);
2677 Py_XDECREF(result);
2678 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002679}
2680
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002681PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002683 switch(o) {
2684 case Load:
2685 Py_INCREF(Load_singleton);
2686 return Load_singleton;
2687 case Store:
2688 Py_INCREF(Store_singleton);
2689 return Store_singleton;
2690 case Del:
2691 Py_INCREF(Del_singleton);
2692 return Del_singleton;
2693 case AugLoad:
2694 Py_INCREF(AugLoad_singleton);
2695 return AugLoad_singleton;
2696 case AugStore:
2697 Py_INCREF(AugStore_singleton);
2698 return AugStore_singleton;
2699 case Param:
2700 Py_INCREF(Param_singleton);
2701 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002702 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002703 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002704}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002705PyObject*
2706ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002707{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002708 slice_ty o = (slice_ty)_o;
2709 PyObject *result = NULL, *value = NULL;
2710 if (!o) {
2711 Py_INCREF(Py_None);
2712 return Py_None;
2713 }
2714
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715 switch (o->kind) {
2716 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002717 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2718 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002719 break;
2720 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002721 result = PyType_GenericNew(Slice_type, NULL, NULL);
2722 if (!result) goto failed;
2723 value = ast2obj_expr(o->v.Slice.lower);
2724 if (!value) goto failed;
2725 if (PyObject_SetAttrString(result, "lower", value) == -1)
2726 goto failed;
2727 Py_DECREF(value);
2728 value = ast2obj_expr(o->v.Slice.upper);
2729 if (!value) goto failed;
2730 if (PyObject_SetAttrString(result, "upper", value) == -1)
2731 goto failed;
2732 Py_DECREF(value);
2733 value = ast2obj_expr(o->v.Slice.step);
2734 if (!value) goto failed;
2735 if (PyObject_SetAttrString(result, "step", value) == -1)
2736 goto failed;
2737 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002738 break;
2739 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002740 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2741 if (!result) goto failed;
2742 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2743 if (!value) goto failed;
2744 if (PyObject_SetAttrString(result, "dims", value) == -1)
2745 goto failed;
2746 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002747 break;
2748 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002749 result = PyType_GenericNew(Index_type, NULL, NULL);
2750 if (!result) goto failed;
2751 value = ast2obj_expr(o->v.Index.value);
2752 if (!value) goto failed;
2753 if (PyObject_SetAttrString(result, "value", value) == -1)
2754 goto failed;
2755 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002756 break;
2757 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002758 return result;
2759failed:
2760 Py_XDECREF(value);
2761 Py_XDECREF(result);
2762 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002763}
2764
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002765PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002766{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002767 switch(o) {
2768 case And:
2769 Py_INCREF(And_singleton);
2770 return And_singleton;
2771 case Or:
2772 Py_INCREF(Or_singleton);
2773 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002774 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002775 return NULL; /* cannot happen */
2776}
2777PyObject* ast2obj_operator(operator_ty o)
2778{
2779 switch(o) {
2780 case Add:
2781 Py_INCREF(Add_singleton);
2782 return Add_singleton;
2783 case Sub:
2784 Py_INCREF(Sub_singleton);
2785 return Sub_singleton;
2786 case Mult:
2787 Py_INCREF(Mult_singleton);
2788 return Mult_singleton;
2789 case Div:
2790 Py_INCREF(Div_singleton);
2791 return Div_singleton;
2792 case Mod:
2793 Py_INCREF(Mod_singleton);
2794 return Mod_singleton;
2795 case Pow:
2796 Py_INCREF(Pow_singleton);
2797 return Pow_singleton;
2798 case LShift:
2799 Py_INCREF(LShift_singleton);
2800 return LShift_singleton;
2801 case RShift:
2802 Py_INCREF(RShift_singleton);
2803 return RShift_singleton;
2804 case BitOr:
2805 Py_INCREF(BitOr_singleton);
2806 return BitOr_singleton;
2807 case BitXor:
2808 Py_INCREF(BitXor_singleton);
2809 return BitXor_singleton;
2810 case BitAnd:
2811 Py_INCREF(BitAnd_singleton);
2812 return BitAnd_singleton;
2813 case FloorDiv:
2814 Py_INCREF(FloorDiv_singleton);
2815 return FloorDiv_singleton;
2816 }
2817 return NULL; /* cannot happen */
2818}
2819PyObject* ast2obj_unaryop(unaryop_ty o)
2820{
2821 switch(o) {
2822 case Invert:
2823 Py_INCREF(Invert_singleton);
2824 return Invert_singleton;
2825 case Not:
2826 Py_INCREF(Not_singleton);
2827 return Not_singleton;
2828 case UAdd:
2829 Py_INCREF(UAdd_singleton);
2830 return UAdd_singleton;
2831 case USub:
2832 Py_INCREF(USub_singleton);
2833 return USub_singleton;
2834 }
2835 return NULL; /* cannot happen */
2836}
2837PyObject* ast2obj_cmpop(cmpop_ty o)
2838{
2839 switch(o) {
2840 case Eq:
2841 Py_INCREF(Eq_singleton);
2842 return Eq_singleton;
2843 case NotEq:
2844 Py_INCREF(NotEq_singleton);
2845 return NotEq_singleton;
2846 case Lt:
2847 Py_INCREF(Lt_singleton);
2848 return Lt_singleton;
2849 case LtE:
2850 Py_INCREF(LtE_singleton);
2851 return LtE_singleton;
2852 case Gt:
2853 Py_INCREF(Gt_singleton);
2854 return Gt_singleton;
2855 case GtE:
2856 Py_INCREF(GtE_singleton);
2857 return GtE_singleton;
2858 case Is:
2859 Py_INCREF(Is_singleton);
2860 return Is_singleton;
2861 case IsNot:
2862 Py_INCREF(IsNot_singleton);
2863 return IsNot_singleton;
2864 case In:
2865 Py_INCREF(In_singleton);
2866 return In_singleton;
2867 case NotIn:
2868 Py_INCREF(NotIn_singleton);
2869 return NotIn_singleton;
2870 }
2871 return NULL; /* cannot happen */
2872}
2873PyObject*
2874ast2obj_comprehension(void* _o)
2875{
2876 comprehension_ty o = (comprehension_ty)_o;
2877 PyObject *result = NULL, *value = NULL;
2878 if (!o) {
2879 Py_INCREF(Py_None);
2880 return Py_None;
2881 }
2882
2883 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2884 if (!result) return NULL;
2885 value = ast2obj_expr(o->target);
2886 if (!value) goto failed;
2887 if (PyObject_SetAttrString(result, "target", value) == -1)
2888 goto failed;
2889 Py_DECREF(value);
2890 value = ast2obj_expr(o->iter);
2891 if (!value) goto failed;
2892 if (PyObject_SetAttrString(result, "iter", value) == -1)
2893 goto failed;
2894 Py_DECREF(value);
2895 value = ast2obj_list(o->ifs, ast2obj_expr);
2896 if (!value) goto failed;
2897 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2898 goto failed;
2899 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002900 return result;
2901failed:
2902 Py_XDECREF(value);
2903 Py_XDECREF(result);
2904 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002905}
2906
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002907PyObject*
2908ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002909{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002910 excepthandler_ty o = (excepthandler_ty)_o;
2911 PyObject *result = NULL, *value = NULL;
2912 if (!o) {
2913 Py_INCREF(Py_None);
2914 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002915 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002916
2917 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2918 if (!result) return NULL;
2919 value = ast2obj_expr(o->type);
2920 if (!value) goto failed;
2921 if (PyObject_SetAttrString(result, "type", value) == -1)
2922 goto failed;
2923 Py_DECREF(value);
2924 value = ast2obj_expr(o->name);
2925 if (!value) goto failed;
2926 if (PyObject_SetAttrString(result, "name", value) == -1)
2927 goto failed;
2928 Py_DECREF(value);
2929 value = ast2obj_list(o->body, ast2obj_stmt);
2930 if (!value) goto failed;
2931 if (PyObject_SetAttrString(result, "body", value) == -1)
2932 goto failed;
2933 Py_DECREF(value);
Jeremy Hylton2f327c12006-04-04 04:00:23 +00002934 value = ast2obj_int(o->lineno);
2935 if (!value) goto failed;
2936 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2937 goto failed;
2938 Py_DECREF(value);
2939 value = ast2obj_int(o->col_offset);
2940 if (!value) goto failed;
2941 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2942 goto failed;
2943 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002944 return result;
2945failed:
2946 Py_XDECREF(value);
2947 Py_XDECREF(result);
2948 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002949}
2950
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002951PyObject*
2952ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002953{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002954 arguments_ty o = (arguments_ty)_o;
2955 PyObject *result = NULL, *value = NULL;
2956 if (!o) {
2957 Py_INCREF(Py_None);
2958 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002959 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002960
2961 result = PyType_GenericNew(arguments_type, NULL, NULL);
2962 if (!result) return NULL;
2963 value = ast2obj_list(o->args, ast2obj_expr);
2964 if (!value) goto failed;
2965 if (PyObject_SetAttrString(result, "args", value) == -1)
2966 goto failed;
2967 Py_DECREF(value);
2968 value = ast2obj_identifier(o->vararg);
2969 if (!value) goto failed;
2970 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2971 goto failed;
2972 Py_DECREF(value);
2973 value = ast2obj_identifier(o->kwarg);
2974 if (!value) goto failed;
2975 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2976 goto failed;
2977 Py_DECREF(value);
2978 value = ast2obj_list(o->defaults, ast2obj_expr);
2979 if (!value) goto failed;
2980 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2981 goto failed;
2982 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002983 return result;
2984failed:
2985 Py_XDECREF(value);
2986 Py_XDECREF(result);
2987 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002988}
2989
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002990PyObject*
2991ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002992{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002993 keyword_ty o = (keyword_ty)_o;
2994 PyObject *result = NULL, *value = NULL;
2995 if (!o) {
2996 Py_INCREF(Py_None);
2997 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002998 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002999
3000 result = PyType_GenericNew(keyword_type, NULL, NULL);
3001 if (!result) return NULL;
3002 value = ast2obj_identifier(o->arg);
3003 if (!value) goto failed;
3004 if (PyObject_SetAttrString(result, "arg", value) == -1)
3005 goto failed;
3006 Py_DECREF(value);
3007 value = ast2obj_expr(o->value);
3008 if (!value) goto failed;
3009 if (PyObject_SetAttrString(result, "value", value) == -1)
3010 goto failed;
3011 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003012 return result;
3013failed:
3014 Py_XDECREF(value);
3015 Py_XDECREF(result);
3016 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003017}
3018
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003019PyObject*
3020ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003021{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003022 alias_ty o = (alias_ty)_o;
3023 PyObject *result = NULL, *value = NULL;
3024 if (!o) {
3025 Py_INCREF(Py_None);
3026 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003027 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003028
3029 result = PyType_GenericNew(alias_type, NULL, NULL);
3030 if (!result) return NULL;
3031 value = ast2obj_identifier(o->name);
3032 if (!value) goto failed;
3033 if (PyObject_SetAttrString(result, "name", value) == -1)
3034 goto failed;
3035 Py_DECREF(value);
3036 value = ast2obj_identifier(o->asname);
3037 if (!value) goto failed;
3038 if (PyObject_SetAttrString(result, "asname", value) == -1)
3039 goto failed;
3040 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003041 return result;
3042failed:
3043 Py_XDECREF(value);
3044 Py_XDECREF(result);
3045 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003046}
3047
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003048
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003049PyMODINIT_FUNC
3050init_ast(void)
3051{
3052 PyObject *m, *d;
3053 if (!init_types()) return;
3054 m = Py_InitModule3("_ast", NULL, NULL);
3055 if (!m) return;
3056 d = PyModule_GetDict(m);
3057 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3058 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3059 return;
Brett Cannond080d4b2007-02-11 19:44:41 +00003060 if (PyModule_AddStringConstant(m, "__version__", "53731") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003061 return;
Neal Norwitz19379f12006-04-03 04:50:58 +00003062 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3063 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3066 < 0) return;
3067 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3068 0) return;
3069 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3070 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3071 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3072 < 0) return;
3073 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3074 return;
3075 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3076 return;
3077 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3078 return;
3079 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3080 return;
3081 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3082 0) return;
3083 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3084 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3085 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3086 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3087 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3088 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3089 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3090 0) return;
3091 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3092 0) return;
3093 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3094 return;
3095 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3096 return;
3097 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3098 0) return;
3099 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3100 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3103 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3104 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3105 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3106 return;
3107 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3108 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3109 return;
3110 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3111 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3112 return;
3113 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3114 return;
3115 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3116 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3117 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3118 return;
3119 if (PyDict_SetItemString(d, "GeneratorExp",
3120 (PyObject*)GeneratorExp_type) < 0) return;
3121 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3122 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3123 return;
3124 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3125 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3126 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3127 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3128 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3129 0) return;
3130 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3131 0) return;
3132 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3133 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3134 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3135 if (PyDict_SetItemString(d, "expr_context",
3136 (PyObject*)expr_context_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3138 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3139 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3140 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3141 return;
3142 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3143 return;
3144 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3145 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3146 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3147 return;
3148 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3149 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3150 return;
3151 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3152 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3153 return;
3154 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3155 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3156 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3157 return;
3158 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3159 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3160 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3161 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3162 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3163 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3164 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3165 return;
3166 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3167 return;
3168 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3169 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3170 return;
3171 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3172 return;
3173 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3174 return;
3175 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3176 return;
3177 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3178 return;
3179 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3180 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3181 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3182 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3183 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3184 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3185 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3186 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3187 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3188 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3189 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3190 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3191 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3192 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3193 if (PyDict_SetItemString(d, "comprehension",
3194 (PyObject*)comprehension_type) < 0) return;
3195 if (PyDict_SetItemString(d, "excepthandler",
3196 (PyObject*)excepthandler_type) < 0) return;
3197 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3198 0) return;
3199 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3200 return;
3201 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003202}
3203
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003204
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003205PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003206{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003207 init_types();
3208 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003209}
3210
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003211