blob: f3b40535156920fe608be5444bd32fdc1efd3807 [file] [log] [blame]
Neal Norwitz897ff812005-12-11 21:18:22 +00001/* File automatically generated by Parser/asdl_c.py */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
3#include "Python.h"
4#include "Python-ast.h"
5
Martin v. Löwis577b5b92006-02-27 15:23:19 +00006PyTypeObject* AST_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00007PyTypeObject *mod_type;
8static PyObject* ast2obj_mod(void*);
9PyTypeObject *Module_type;
10char *Module_fields[]={
11 "body",
12};
13PyTypeObject *Interactive_type;
14char *Interactive_fields[]={
15 "body",
16};
17PyTypeObject *Expression_type;
18char *Expression_fields[]={
19 "body",
20};
21PyTypeObject *Suite_type;
22char *Suite_fields[]={
23 "body",
24};
25PyTypeObject *stmt_type;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000026char *stmt_attributes[] = {
27 "lineno",
28};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000029static PyObject* ast2obj_stmt(void*);
30PyTypeObject *FunctionDef_type;
31char *FunctionDef_fields[]={
32 "name",
33 "args",
34 "body",
35 "decorators",
36};
37PyTypeObject *ClassDef_type;
38char *ClassDef_fields[]={
39 "name",
40 "bases",
41 "body",
42};
43PyTypeObject *Return_type;
44char *Return_fields[]={
45 "value",
46};
47PyTypeObject *Delete_type;
48char *Delete_fields[]={
49 "targets",
50};
51PyTypeObject *Assign_type;
52char *Assign_fields[]={
53 "targets",
54 "value",
55};
56PyTypeObject *AugAssign_type;
57char *AugAssign_fields[]={
58 "target",
59 "op",
60 "value",
61};
62PyTypeObject *Print_type;
63char *Print_fields[]={
64 "dest",
65 "values",
66 "nl",
67};
68PyTypeObject *For_type;
69char *For_fields[]={
70 "target",
71 "iter",
72 "body",
73 "orelse",
74};
75PyTypeObject *While_type;
76char *While_fields[]={
77 "test",
78 "body",
79 "orelse",
80};
81PyTypeObject *If_type;
82char *If_fields[]={
83 "test",
84 "body",
85 "orelse",
86};
87PyTypeObject *Raise_type;
88char *Raise_fields[]={
89 "type",
90 "inst",
91 "tback",
92};
93PyTypeObject *TryExcept_type;
94char *TryExcept_fields[]={
95 "body",
96 "handlers",
97 "orelse",
98};
99PyTypeObject *TryFinally_type;
100char *TryFinally_fields[]={
101 "body",
102 "finalbody",
103};
104PyTypeObject *Assert_type;
105char *Assert_fields[]={
106 "test",
107 "msg",
108};
109PyTypeObject *Import_type;
110char *Import_fields[]={
111 "names",
112};
113PyTypeObject *ImportFrom_type;
114char *ImportFrom_fields[]={
115 "module",
116 "names",
117};
118PyTypeObject *Exec_type;
119char *Exec_fields[]={
120 "body",
121 "globals",
122 "locals",
123};
124PyTypeObject *Global_type;
125char *Global_fields[]={
126 "names",
127};
128PyTypeObject *Expr_type;
129char *Expr_fields[]={
130 "value",
131};
132PyTypeObject *Pass_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000133PyTypeObject *Break_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000134PyTypeObject *Continue_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000135PyTypeObject *expr_type;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000136char *expr_attributes[] = {
137 "lineno",
138};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000139static PyObject* ast2obj_expr(void*);
140PyTypeObject *BoolOp_type;
141char *BoolOp_fields[]={
142 "op",
143 "values",
144};
145PyTypeObject *BinOp_type;
146char *BinOp_fields[]={
147 "left",
148 "op",
149 "right",
150};
151PyTypeObject *UnaryOp_type;
152char *UnaryOp_fields[]={
153 "op",
154 "operand",
155};
156PyTypeObject *Lambda_type;
157char *Lambda_fields[]={
158 "args",
159 "body",
160};
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000161PyTypeObject *IfExp_type;
162char *IfExp_fields[]={
163 "test",
164 "body",
165 "orelse",
166};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167PyTypeObject *Dict_type;
168char *Dict_fields[]={
169 "keys",
170 "values",
171};
172PyTypeObject *ListComp_type;
173char *ListComp_fields[]={
174 "elt",
175 "generators",
176};
177PyTypeObject *GeneratorExp_type;
178char *GeneratorExp_fields[]={
179 "elt",
180 "generators",
181};
182PyTypeObject *Yield_type;
183char *Yield_fields[]={
184 "value",
185};
186PyTypeObject *Compare_type;
187char *Compare_fields[]={
188 "left",
189 "ops",
190 "comparators",
191};
192PyTypeObject *Call_type;
193char *Call_fields[]={
194 "func",
195 "args",
196 "keywords",
197 "starargs",
198 "kwargs",
199};
200PyTypeObject *Repr_type;
201char *Repr_fields[]={
202 "value",
203};
204PyTypeObject *Num_type;
205char *Num_fields[]={
206 "n",
207};
208PyTypeObject *Str_type;
209char *Str_fields[]={
210 "s",
211};
212PyTypeObject *Attribute_type;
213char *Attribute_fields[]={
214 "value",
215 "attr",
216 "ctx",
217};
218PyTypeObject *Subscript_type;
219char *Subscript_fields[]={
220 "value",
221 "slice",
222 "ctx",
223};
224PyTypeObject *Name_type;
225char *Name_fields[]={
226 "id",
227 "ctx",
228};
229PyTypeObject *List_type;
230char *List_fields[]={
231 "elts",
232 "ctx",
233};
234PyTypeObject *Tuple_type;
235char *Tuple_fields[]={
236 "elts",
237 "ctx",
238};
239PyTypeObject *expr_context_type;
240static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
241*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
242static PyObject* ast2obj_expr_context(expr_context_ty);
243PyTypeObject *Load_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000244PyTypeObject *Store_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245PyTypeObject *Del_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000246PyTypeObject *AugLoad_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000247PyTypeObject *AugStore_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000248PyTypeObject *Param_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249PyTypeObject *slice_type;
250static PyObject* ast2obj_slice(void*);
251PyTypeObject *Ellipsis_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000252PyTypeObject *Slice_type;
253char *Slice_fields[]={
254 "lower",
255 "upper",
256 "step",
257};
258PyTypeObject *ExtSlice_type;
259char *ExtSlice_fields[]={
260 "dims",
261};
262PyTypeObject *Index_type;
263char *Index_fields[]={
264 "value",
265};
266PyTypeObject *boolop_type;
267static PyObject *And_singleton, *Or_singleton;
268static PyObject* ast2obj_boolop(boolop_ty);
269PyTypeObject *And_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000270PyTypeObject *Or_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271PyTypeObject *operator_type;
272static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
273*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
274*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
275*FloorDiv_singleton;
276static PyObject* ast2obj_operator(operator_ty);
277PyTypeObject *Add_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000278PyTypeObject *Sub_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000279PyTypeObject *Mult_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000280PyTypeObject *Div_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000281PyTypeObject *Mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000282PyTypeObject *Pow_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000283PyTypeObject *LShift_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000284PyTypeObject *RShift_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000285PyTypeObject *BitOr_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000286PyTypeObject *BitXor_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000287PyTypeObject *BitAnd_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000288PyTypeObject *FloorDiv_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000289PyTypeObject *unaryop_type;
290static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
291*USub_singleton;
292static PyObject* ast2obj_unaryop(unaryop_ty);
293PyTypeObject *Invert_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000294PyTypeObject *Not_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295PyTypeObject *UAdd_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000296PyTypeObject *USub_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000297PyTypeObject *cmpop_type;
298static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
299*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
300*NotIn_singleton;
301static PyObject* ast2obj_cmpop(cmpop_ty);
302PyTypeObject *Eq_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000303PyTypeObject *NotEq_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000304PyTypeObject *Lt_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000305PyTypeObject *LtE_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000306PyTypeObject *Gt_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000307PyTypeObject *GtE_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000308PyTypeObject *Is_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000309PyTypeObject *IsNot_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000310PyTypeObject *In_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000311PyTypeObject *NotIn_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000312PyTypeObject *comprehension_type;
313static PyObject* ast2obj_comprehension(void*);
314char *comprehension_fields[]={
315 "target",
316 "iter",
317 "ifs",
318};
319PyTypeObject *excepthandler_type;
320static PyObject* ast2obj_excepthandler(void*);
321char *excepthandler_fields[]={
322 "type",
323 "name",
324 "body",
325};
326PyTypeObject *arguments_type;
327static PyObject* ast2obj_arguments(void*);
328char *arguments_fields[]={
329 "args",
330 "vararg",
331 "kwarg",
332 "defaults",
333};
334PyTypeObject *keyword_type;
335static PyObject* ast2obj_keyword(void*);
336char *keyword_fields[]={
337 "arg",
338 "value",
339};
340PyTypeObject *alias_type;
341static PyObject* ast2obj_alias(void*);
342char *alias_fields[]={
343 "name",
344 "asname",
345};
346
347
348static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
349{
350 PyObject *fnames, *result;
351 int i;
352 if (num_fields) {
353 fnames = PyTuple_New(num_fields);
354 if (!fnames) return NULL;
355 } else {
356 fnames = Py_None;
357 Py_INCREF(Py_None);
358 }
359 for(i=0; i < num_fields; i++) {
360 PyObject *field = PyString_FromString(fields[i]);
361 if (!field) {
362 Py_DECREF(fnames);
363 return NULL;
364 }
365 PyTuple_SET_ITEM(fnames, i, field);
366 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000367 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
368 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000369 Py_DECREF(fnames);
370 return (PyTypeObject*)result;
371}
372
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000373static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
374{
375 int i;
376 PyObject *s, *l = PyList_New(num_fields);
377 if (!l) return 0;
378 for(i=0; i < num_fields; i++) {
379 s = PyString_FromString(attrs[i]);
380 if (!s) {
381 Py_DECREF(l);
382 return 0;
383 }
384 PyList_SET_ITEM(l, i, s);
385 }
386 return PyObject_SetAttrString((PyObject*)type, "_attributes", l) >=0;
387}
388
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000389static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
390{
391 int i, n = asdl_seq_LEN(seq);
392 PyObject *result = PyList_New(n);
393 PyObject *value;
394 if (!result)
395 return NULL;
396 for (i = 0; i < n; i++) {
397 value = func(asdl_seq_GET(seq, i));
398 if (!value) {
399 Py_DECREF(result);
400 return NULL;
401 }
402 PyList_SET_ITEM(result, i, value);
403 }
404 return result;
405}
406
407static PyObject* ast2obj_object(void *o)
408{
409 if (!o)
410 o = Py_None;
411 Py_INCREF((PyObject*)o);
412 return (PyObject*)o;
413}
414#define ast2obj_identifier ast2obj_object
415#define ast2obj_string ast2obj_object
416static PyObject* ast2obj_bool(bool b)
417{
418 return PyBool_FromLong(b);
419}
420
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000421static PyObject* ast2obj_int(bool b)
422{
423 return PyInt_FromLong(b);
424}
425
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000426static int initialized;
427static int init_types(void)
428{
429 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000430 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
431 mod_type = make_type("mod", AST_type, NULL, 0);
432 if (!mod_type) return 0;
433 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000434 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000435 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000436 Interactive_type = make_type("Interactive", mod_type,
437 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000438 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000439 Expression_type = make_type("Expression", mod_type, Expression_fields,
440 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000441 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000442 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000443 if (!Suite_type) return 0;
444 stmt_type = make_type("stmt", AST_type, NULL, 0);
445 if (!stmt_type) return 0;
446 if (!add_attributes(stmt_type, stmt_attributes, 1)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000447 FunctionDef_type = make_type("FunctionDef", stmt_type,
448 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000449 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000450 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000451 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000452 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000453 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000454 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000455 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000457 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000458 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000459 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000460 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000461 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000462 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000463 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000465 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000466 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000467 if (!If_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000468 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000469 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000470 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000471 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
473 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
480 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000481 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000488 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000490 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000492 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000493 if (!Continue_type) return 0;
494 expr_type = make_type("expr", AST_type, NULL, 0);
495 if (!expr_type) return 0;
496 if (!add_attributes(expr_type, expr_attributes, 1)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000501 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000505 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000507 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000508 if (!Dict_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000510 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000511 GeneratorExp_type = make_type("GeneratorExp", expr_type,
512 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Repr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000525 if (!Str_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000526 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000527 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000528 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000529 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000530 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000531 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000532 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000533 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000534 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000535 if (!Tuple_type) return 0;
536 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
537 if (!expr_context_type) return 0;
538 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000539 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000543 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000547 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000549 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000550 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000551 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000552 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000554 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000555 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000556 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000557 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000558 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000559 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000560 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000561 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000562 if (!Param_singleton) return 0;
563 slice_type = make_type("slice", AST_type, NULL, 0);
564 if (!slice_type) return 0;
565 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000566 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Index_type) return 0;
574 boolop_type = make_type("boolop", AST_type, NULL, 0);
575 if (!boolop_type) return 0;
576 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000577 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000581 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Or_singleton) return 0;
585 operator_type = make_type("operator", AST_type, NULL, 0);
586 if (!operator_type) return 0;
587 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000588 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000590 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000592 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000596 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000598 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000599 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000600 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000601 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000602 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000603 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000604 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000605 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000606 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000607 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000608 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000609 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000610 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000611 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000612 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000613 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000614 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000615 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000616 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000617 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000618 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000619 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000620 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000621 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000622 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000623 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000624 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000625 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000626 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000627 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000628 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000629 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000630 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000631 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000632 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000633 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000634 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000635 if (!FloorDiv_singleton) return 0;
636 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
637 if (!unaryop_type) return 0;
638 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000647 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000649 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000650 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000651 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000652 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000653 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000654 if (!USub_singleton) return 0;
655 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
656 if (!cmpop_type) return 0;
657 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000666 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000669 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000670 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000671 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000672 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000673 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000674 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000676 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000677 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000678 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000679 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000680 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000681 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000682 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000683 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000684 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000685 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000686 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000687 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000688 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000690 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000691 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000692 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000693 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000694 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000695 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000696 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000697 if (!NotIn_singleton) return 0;
698 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!comprehension_type) return 0;
701 excepthandler_type = make_type("excepthandler", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702 excepthandler_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000703 if (!excepthandler_type) return 0;
704 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
705 if (!arguments_type) return 0;
706 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
707 if (!keyword_type) return 0;
708 alias_type = make_type("alias", AST_type, alias_fields, 2);
709 if (!alias_type) return 0;
710 initialized = 1;
711 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000713
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000714mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000715Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000716{
717 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000718 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000719 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000720 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000721 return NULL;
722 }
723 p->kind = Module_kind;
724 p->v.Module.body = body;
725 return p;
726}
727
728mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000729Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000730{
731 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000732 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000733 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000734 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000735 return NULL;
736 }
737 p->kind = Interactive_kind;
738 p->v.Interactive.body = body;
739 return p;
740}
741
742mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000743Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000744{
745 mod_ty p;
746 if (!body) {
747 PyErr_SetString(PyExc_ValueError,
748 "field body is required for Expression");
749 return NULL;
750 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000751 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000752 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000753 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000754 return NULL;
755 }
756 p->kind = Expression_kind;
757 p->v.Expression.body = body;
758 return p;
759}
760
761mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000762Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763{
764 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000765 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000766 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000767 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000768 return NULL;
769 }
770 p->kind = Suite_kind;
771 p->v.Suite.body = body;
772 return p;
773}
774
775stmt_ty
776FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000777 decorators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000778{
779 stmt_ty p;
780 if (!name) {
781 PyErr_SetString(PyExc_ValueError,
782 "field name is required for FunctionDef");
783 return NULL;
784 }
785 if (!args) {
786 PyErr_SetString(PyExc_ValueError,
787 "field args is required for FunctionDef");
788 return NULL;
789 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000790 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000791 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000792 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000793 return NULL;
794 }
795 p->kind = FunctionDef_kind;
796 p->v.FunctionDef.name = name;
797 p->v.FunctionDef.args = args;
798 p->v.FunctionDef.body = body;
799 p->v.FunctionDef.decorators = decorators;
800 p->lineno = lineno;
801 return p;
802}
803
804stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000805ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno,
806 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000807{
808 stmt_ty p;
809 if (!name) {
810 PyErr_SetString(PyExc_ValueError,
811 "field name is required for ClassDef");
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 = ClassDef_kind;
820 p->v.ClassDef.name = name;
821 p->v.ClassDef.bases = bases;
822 p->v.ClassDef.body = body;
823 p->lineno = lineno;
824 return p;
825}
826
827stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000828Return(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000829{
830 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000831 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000832 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000833 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000834 return NULL;
835 }
836 p->kind = Return_kind;
837 p->v.Return.value = value;
838 p->lineno = lineno;
839 return p;
840}
841
842stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000843Delete(asdl_seq * targets, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000844{
845 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000846 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000848 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 return NULL;
850 }
851 p->kind = Delete_kind;
852 p->v.Delete.targets = targets;
853 p->lineno = lineno;
854 return p;
855}
856
857stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000858Assign(asdl_seq * targets, expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859{
860 stmt_ty p;
861 if (!value) {
862 PyErr_SetString(PyExc_ValueError,
863 "field value is required for Assign");
864 return NULL;
865 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000866 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000868 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000869 return NULL;
870 }
871 p->kind = Assign_kind;
872 p->v.Assign.targets = targets;
873 p->v.Assign.value = value;
874 p->lineno = lineno;
875 return p;
876}
877
878stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000879AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, PyArena
880 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881{
882 stmt_ty p;
883 if (!target) {
884 PyErr_SetString(PyExc_ValueError,
885 "field target is required for AugAssign");
886 return NULL;
887 }
888 if (!op) {
889 PyErr_SetString(PyExc_ValueError,
890 "field op is required for AugAssign");
891 return NULL;
892 }
893 if (!value) {
894 PyErr_SetString(PyExc_ValueError,
895 "field value is required for AugAssign");
896 return NULL;
897 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000898 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000899 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000900 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000901 return NULL;
902 }
903 p->kind = AugAssign_kind;
904 p->v.AugAssign.target = target;
905 p->v.AugAssign.op = op;
906 p->v.AugAssign.value = value;
907 p->lineno = lineno;
908 return p;
909}
910
911stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000912Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000913{
914 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000915 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000916 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000917 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000918 return NULL;
919 }
920 p->kind = Print_kind;
921 p->v.Print.dest = dest;
922 p->v.Print.values = values;
923 p->v.Print.nl = nl;
924 p->lineno = lineno;
925 return p;
926}
927
928stmt_ty
929For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000930 lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931{
932 stmt_ty p;
933 if (!target) {
934 PyErr_SetString(PyExc_ValueError,
935 "field target is required for For");
936 return NULL;
937 }
938 if (!iter) {
939 PyErr_SetString(PyExc_ValueError,
940 "field iter is required for For");
941 return NULL;
942 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000943 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000944 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000945 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000946 return NULL;
947 }
948 p->kind = For_kind;
949 p->v.For.target = target;
950 p->v.For.iter = iter;
951 p->v.For.body = body;
952 p->v.For.orelse = orelse;
953 p->lineno = lineno;
954 return p;
955}
956
957stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000958While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena
959 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000960{
961 stmt_ty p;
962 if (!test) {
963 PyErr_SetString(PyExc_ValueError,
964 "field test is required for While");
965 return NULL;
966 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000967 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000968 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000969 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000970 return NULL;
971 }
972 p->kind = While_kind;
973 p->v.While.test = test;
974 p->v.While.body = body;
975 p->v.While.orelse = orelse;
976 p->lineno = lineno;
977 return p;
978}
979
980stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000981If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000982{
983 stmt_ty p;
984 if (!test) {
985 PyErr_SetString(PyExc_ValueError,
986 "field test is required for If");
987 return NULL;
988 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000989 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000990 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000991 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000992 return NULL;
993 }
994 p->kind = If_kind;
995 p->v.If.test = test;
996 p->v.If.body = body;
997 p->v.If.orelse = orelse;
998 p->lineno = lineno;
999 return p;
1000}
1001
1002stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001003Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001004{
1005 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001006 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001007 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001008 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001009 return NULL;
1010 }
1011 p->kind = Raise_kind;
1012 p->v.Raise.type = type;
1013 p->v.Raise.inst = inst;
1014 p->v.Raise.tback = tback;
1015 p->lineno = lineno;
1016 return p;
1017}
1018
1019stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001020TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1021 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001022{
1023 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001024 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001025 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001026 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001027 return NULL;
1028 }
1029 p->kind = TryExcept_kind;
1030 p->v.TryExcept.body = body;
1031 p->v.TryExcept.handlers = handlers;
1032 p->v.TryExcept.orelse = orelse;
1033 p->lineno = lineno;
1034 return p;
1035}
1036
1037stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001038TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001039{
1040 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001041 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001042 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001043 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001044 return NULL;
1045 }
1046 p->kind = TryFinally_kind;
1047 p->v.TryFinally.body = body;
1048 p->v.TryFinally.finalbody = finalbody;
1049 p->lineno = lineno;
1050 return p;
1051}
1052
1053stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001054Assert(expr_ty test, expr_ty msg, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001055{
1056 stmt_ty p;
1057 if (!test) {
1058 PyErr_SetString(PyExc_ValueError,
1059 "field test is required for Assert");
1060 return NULL;
1061 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001062 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001064 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001065 return NULL;
1066 }
1067 p->kind = Assert_kind;
1068 p->v.Assert.test = test;
1069 p->v.Assert.msg = msg;
1070 p->lineno = lineno;
1071 return p;
1072}
1073
1074stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001075Import(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076{
1077 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001078 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001080 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001081 return NULL;
1082 }
1083 p->kind = Import_kind;
1084 p->v.Import.names = names;
1085 p->lineno = lineno;
1086 return p;
1087}
1088
1089stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001090ImportFrom(identifier module, asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001091{
1092 stmt_ty p;
1093 if (!module) {
1094 PyErr_SetString(PyExc_ValueError,
1095 "field module is required for ImportFrom");
1096 return NULL;
1097 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001098 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001099 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001100 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101 return NULL;
1102 }
1103 p->kind = ImportFrom_kind;
1104 p->v.ImportFrom.module = module;
1105 p->v.ImportFrom.names = names;
1106 p->lineno = lineno;
1107 return p;
1108}
1109
1110stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001111Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001112{
1113 stmt_ty p;
1114 if (!body) {
1115 PyErr_SetString(PyExc_ValueError,
1116 "field body is required for Exec");
1117 return NULL;
1118 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001119 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001121 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001122 return NULL;
1123 }
1124 p->kind = Exec_kind;
1125 p->v.Exec.body = body;
1126 p->v.Exec.globals = globals;
1127 p->v.Exec.locals = locals;
1128 p->lineno = lineno;
1129 return p;
1130}
1131
1132stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001133Global(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001134{
1135 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001136 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001138 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001139 return NULL;
1140 }
1141 p->kind = Global_kind;
1142 p->v.Global.names = names;
1143 p->lineno = lineno;
1144 return p;
1145}
1146
1147stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001148Expr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149{
1150 stmt_ty p;
1151 if (!value) {
1152 PyErr_SetString(PyExc_ValueError,
1153 "field value is required for Expr");
1154 return NULL;
1155 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001156 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001158 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 return NULL;
1160 }
1161 p->kind = Expr_kind;
1162 p->v.Expr.value = value;
1163 p->lineno = lineno;
1164 return p;
1165}
1166
1167stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001168Pass(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169{
1170 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001171 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001172 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001173 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001174 return NULL;
1175 }
1176 p->kind = Pass_kind;
1177 p->lineno = lineno;
1178 return p;
1179}
1180
1181stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001182Break(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183{
1184 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001185 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001186 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001187 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001188 return NULL;
1189 }
1190 p->kind = Break_kind;
1191 p->lineno = lineno;
1192 return p;
1193}
1194
1195stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001196Continue(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197{
1198 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001199 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001200 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001201 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001202 return NULL;
1203 }
1204 p->kind = Continue_kind;
1205 p->lineno = lineno;
1206 return p;
1207}
1208
1209expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001210BoolOp(boolop_ty op, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001211{
1212 expr_ty p;
1213 if (!op) {
1214 PyErr_SetString(PyExc_ValueError,
1215 "field op is required for BoolOp");
1216 return NULL;
1217 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001218 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001219 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001220 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001221 return NULL;
1222 }
1223 p->kind = BoolOp_kind;
1224 p->v.BoolOp.op = op;
1225 p->v.BoolOp.values = values;
1226 p->lineno = lineno;
1227 return p;
1228}
1229
1230expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001231BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232{
1233 expr_ty p;
1234 if (!left) {
1235 PyErr_SetString(PyExc_ValueError,
1236 "field left is required for BinOp");
1237 return NULL;
1238 }
1239 if (!op) {
1240 PyErr_SetString(PyExc_ValueError,
1241 "field op is required for BinOp");
1242 return NULL;
1243 }
1244 if (!right) {
1245 PyErr_SetString(PyExc_ValueError,
1246 "field right is required for BinOp");
1247 return NULL;
1248 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001249 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001250 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001251 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001252 return NULL;
1253 }
1254 p->kind = BinOp_kind;
1255 p->v.BinOp.left = left;
1256 p->v.BinOp.op = op;
1257 p->v.BinOp.right = right;
1258 p->lineno = lineno;
1259 return p;
1260}
1261
1262expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001263UnaryOp(unaryop_ty op, expr_ty operand, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264{
1265 expr_ty p;
1266 if (!op) {
1267 PyErr_SetString(PyExc_ValueError,
1268 "field op is required for UnaryOp");
1269 return NULL;
1270 }
1271 if (!operand) {
1272 PyErr_SetString(PyExc_ValueError,
1273 "field operand is required for UnaryOp");
1274 return NULL;
1275 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001276 p = (expr_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 = UnaryOp_kind;
1282 p->v.UnaryOp.op = op;
1283 p->v.UnaryOp.operand = operand;
1284 p->lineno = lineno;
1285 return p;
1286}
1287
1288expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001289Lambda(arguments_ty args, expr_ty body, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001290{
1291 expr_ty p;
1292 if (!args) {
1293 PyErr_SetString(PyExc_ValueError,
1294 "field args is required for Lambda");
1295 return NULL;
1296 }
1297 if (!body) {
1298 PyErr_SetString(PyExc_ValueError,
1299 "field body is required for Lambda");
1300 return NULL;
1301 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001302 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001303 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001304 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001305 return NULL;
1306 }
1307 p->kind = Lambda_kind;
1308 p->v.Lambda.args = args;
1309 p->v.Lambda.body = body;
1310 p->lineno = lineno;
1311 return p;
1312}
1313
1314expr_ty
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001315IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, PyArena *arena)
1316{
1317 expr_ty p;
1318 if (!test) {
1319 PyErr_SetString(PyExc_ValueError,
1320 "field test is required for IfExp");
1321 return NULL;
1322 }
1323 if (!body) {
1324 PyErr_SetString(PyExc_ValueError,
1325 "field body is required for IfExp");
1326 return NULL;
1327 }
1328 if (!orelse) {
1329 PyErr_SetString(PyExc_ValueError,
1330 "field orelse is required for IfExp");
1331 return NULL;
1332 }
1333 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1334 if (!p) {
1335 PyErr_NoMemory();
1336 return NULL;
1337 }
1338 p->kind = IfExp_kind;
1339 p->v.IfExp.test = test;
1340 p->v.IfExp.body = body;
1341 p->v.IfExp.orelse = orelse;
1342 p->lineno = lineno;
1343 return p;
1344}
1345
1346expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001347Dict(asdl_seq * keys, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001348{
1349 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001350 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001352 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001353 return NULL;
1354 }
1355 p->kind = Dict_kind;
1356 p->v.Dict.keys = keys;
1357 p->v.Dict.values = values;
1358 p->lineno = lineno;
1359 return p;
1360}
1361
1362expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001363ListComp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001364{
1365 expr_ty p;
1366 if (!elt) {
1367 PyErr_SetString(PyExc_ValueError,
1368 "field elt is required for ListComp");
1369 return NULL;
1370 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001371 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001372 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001373 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001374 return NULL;
1375 }
1376 p->kind = ListComp_kind;
1377 p->v.ListComp.elt = elt;
1378 p->v.ListComp.generators = generators;
1379 p->lineno = lineno;
1380 return p;
1381}
1382
1383expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001384GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001385{
1386 expr_ty p;
1387 if (!elt) {
1388 PyErr_SetString(PyExc_ValueError,
1389 "field elt is required for GeneratorExp");
1390 return NULL;
1391 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001392 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001393 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001394 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001395 return NULL;
1396 }
1397 p->kind = GeneratorExp_kind;
1398 p->v.GeneratorExp.elt = elt;
1399 p->v.GeneratorExp.generators = generators;
1400 p->lineno = lineno;
1401 return p;
1402}
1403
1404expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001405Yield(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001406{
1407 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001408 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001409 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001410 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001411 return NULL;
1412 }
1413 p->kind = Yield_kind;
1414 p->v.Yield.value = value;
1415 p->lineno = lineno;
1416 return p;
1417}
1418
1419expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001420Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno,
1421 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422{
1423 expr_ty p;
1424 if (!left) {
1425 PyErr_SetString(PyExc_ValueError,
1426 "field left is required for Compare");
1427 return NULL;
1428 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001429 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001430 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001431 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001432 return NULL;
1433 }
1434 p->kind = Compare_kind;
1435 p->v.Compare.left = left;
1436 p->v.Compare.ops = ops;
1437 p->v.Compare.comparators = comparators;
1438 p->lineno = lineno;
1439 return p;
1440}
1441
1442expr_ty
1443Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001444 expr_ty kwargs, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001445{
1446 expr_ty p;
1447 if (!func) {
1448 PyErr_SetString(PyExc_ValueError,
1449 "field func is required for Call");
1450 return NULL;
1451 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001452 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001453 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001454 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001455 return NULL;
1456 }
1457 p->kind = Call_kind;
1458 p->v.Call.func = func;
1459 p->v.Call.args = args;
1460 p->v.Call.keywords = keywords;
1461 p->v.Call.starargs = starargs;
1462 p->v.Call.kwargs = kwargs;
1463 p->lineno = lineno;
1464 return p;
1465}
1466
1467expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001468Repr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001469{
1470 expr_ty p;
1471 if (!value) {
1472 PyErr_SetString(PyExc_ValueError,
1473 "field value is required for Repr");
1474 return NULL;
1475 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001476 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001478 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479 return NULL;
1480 }
1481 p->kind = Repr_kind;
1482 p->v.Repr.value = value;
1483 p->lineno = lineno;
1484 return p;
1485}
1486
1487expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001488Num(object n, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001489{
1490 expr_ty p;
1491 if (!n) {
1492 PyErr_SetString(PyExc_ValueError,
1493 "field n is required for Num");
1494 return NULL;
1495 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001496 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001497 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001498 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001499 return NULL;
1500 }
1501 p->kind = Num_kind;
1502 p->v.Num.n = n;
1503 p->lineno = lineno;
1504 return p;
1505}
1506
1507expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001508Str(string s, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001509{
1510 expr_ty p;
1511 if (!s) {
1512 PyErr_SetString(PyExc_ValueError,
1513 "field s is required for Str");
1514 return NULL;
1515 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001516 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001517 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001518 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001519 return NULL;
1520 }
1521 p->kind = Str_kind;
1522 p->v.Str.s = s;
1523 p->lineno = lineno;
1524 return p;
1525}
1526
1527expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001528Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno,
1529 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530{
1531 expr_ty p;
1532 if (!value) {
1533 PyErr_SetString(PyExc_ValueError,
1534 "field value is required for Attribute");
1535 return NULL;
1536 }
1537 if (!attr) {
1538 PyErr_SetString(PyExc_ValueError,
1539 "field attr is required for Attribute");
1540 return NULL;
1541 }
1542 if (!ctx) {
1543 PyErr_SetString(PyExc_ValueError,
1544 "field ctx is required for Attribute");
1545 return NULL;
1546 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001547 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001549 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001550 return NULL;
1551 }
1552 p->kind = Attribute_kind;
1553 p->v.Attribute.value = value;
1554 p->v.Attribute.attr = attr;
1555 p->v.Attribute.ctx = ctx;
1556 p->lineno = lineno;
1557 return p;
1558}
1559
1560expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001561Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno,
1562 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001563{
1564 expr_ty p;
1565 if (!value) {
1566 PyErr_SetString(PyExc_ValueError,
1567 "field value is required for Subscript");
1568 return NULL;
1569 }
1570 if (!slice) {
1571 PyErr_SetString(PyExc_ValueError,
1572 "field slice is required for Subscript");
1573 return NULL;
1574 }
1575 if (!ctx) {
1576 PyErr_SetString(PyExc_ValueError,
1577 "field ctx is required for Subscript");
1578 return NULL;
1579 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001580 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001581 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001582 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001583 return NULL;
1584 }
1585 p->kind = Subscript_kind;
1586 p->v.Subscript.value = value;
1587 p->v.Subscript.slice = slice;
1588 p->v.Subscript.ctx = ctx;
1589 p->lineno = lineno;
1590 return p;
1591}
1592
1593expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001594Name(identifier id, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001595{
1596 expr_ty p;
1597 if (!id) {
1598 PyErr_SetString(PyExc_ValueError,
1599 "field id is required for Name");
1600 return NULL;
1601 }
1602 if (!ctx) {
1603 PyErr_SetString(PyExc_ValueError,
1604 "field ctx is required for Name");
1605 return NULL;
1606 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001607 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001608 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001609 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001610 return NULL;
1611 }
1612 p->kind = Name_kind;
1613 p->v.Name.id = id;
1614 p->v.Name.ctx = ctx;
1615 p->lineno = lineno;
1616 return p;
1617}
1618
1619expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001620List(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001621{
1622 expr_ty p;
1623 if (!ctx) {
1624 PyErr_SetString(PyExc_ValueError,
1625 "field ctx is required for List");
1626 return NULL;
1627 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001628 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001629 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001630 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001631 return NULL;
1632 }
1633 p->kind = List_kind;
1634 p->v.List.elts = elts;
1635 p->v.List.ctx = ctx;
1636 p->lineno = lineno;
1637 return p;
1638}
1639
1640expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001641Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001642{
1643 expr_ty p;
1644 if (!ctx) {
1645 PyErr_SetString(PyExc_ValueError,
1646 "field ctx is required for Tuple");
1647 return NULL;
1648 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001649 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001650 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001651 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001652 return NULL;
1653 }
1654 p->kind = Tuple_kind;
1655 p->v.Tuple.elts = elts;
1656 p->v.Tuple.ctx = ctx;
1657 p->lineno = lineno;
1658 return p;
1659}
1660
1661slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001662Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001663{
1664 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001665 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001666 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001667 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001668 return NULL;
1669 }
1670 p->kind = Ellipsis_kind;
1671 return p;
1672}
1673
1674slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001675Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001676{
1677 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001678 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001680 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001681 return NULL;
1682 }
1683 p->kind = Slice_kind;
1684 p->v.Slice.lower = lower;
1685 p->v.Slice.upper = upper;
1686 p->v.Slice.step = step;
1687 return p;
1688}
1689
1690slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001691ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001692{
1693 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001694 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001695 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001696 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697 return NULL;
1698 }
1699 p->kind = ExtSlice_kind;
1700 p->v.ExtSlice.dims = dims;
1701 return p;
1702}
1703
1704slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001705Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706{
1707 slice_ty p;
1708 if (!value) {
1709 PyErr_SetString(PyExc_ValueError,
1710 "field value is required for Index");
1711 return NULL;
1712 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001713 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001714 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001715 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001716 return NULL;
1717 }
1718 p->kind = Index_kind;
1719 p->v.Index.value = value;
1720 return p;
1721}
1722
1723comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001724comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725{
1726 comprehension_ty p;
1727 if (!target) {
1728 PyErr_SetString(PyExc_ValueError,
1729 "field target is required for comprehension");
1730 return NULL;
1731 }
1732 if (!iter) {
1733 PyErr_SetString(PyExc_ValueError,
1734 "field iter is required for comprehension");
1735 return NULL;
1736 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001737 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001739 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740 return NULL;
1741 }
1742 p->target = target;
1743 p->iter = iter;
1744 p->ifs = ifs;
1745 return p;
1746}
1747
1748excepthandler_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001749excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750{
1751 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001752 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001754 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001755 return NULL;
1756 }
1757 p->type = type;
1758 p->name = name;
1759 p->body = body;
1760 return p;
1761}
1762
1763arguments_ty
1764arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001765 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001766{
1767 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001768 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001770 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771 return NULL;
1772 }
1773 p->args = args;
1774 p->vararg = vararg;
1775 p->kwarg = kwarg;
1776 p->defaults = defaults;
1777 return p;
1778}
1779
1780keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001781keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001782{
1783 keyword_ty p;
1784 if (!arg) {
1785 PyErr_SetString(PyExc_ValueError,
1786 "field arg is required for keyword");
1787 return NULL;
1788 }
1789 if (!value) {
1790 PyErr_SetString(PyExc_ValueError,
1791 "field value is required for keyword");
1792 return NULL;
1793 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001794 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001795 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001796 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001797 return NULL;
1798 }
1799 p->arg = arg;
1800 p->value = value;
1801 return p;
1802}
1803
1804alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001805alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001806{
1807 alias_ty p;
1808 if (!name) {
1809 PyErr_SetString(PyExc_ValueError,
1810 "field name is required for alias");
1811 return NULL;
1812 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001813 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001814 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001815 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001816 return NULL;
1817 }
1818 p->name = name;
1819 p->asname = asname;
1820 return p;
1821}
1822
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001823
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001824PyObject*
1825ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001826{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001827 mod_ty o = (mod_ty)_o;
1828 PyObject *result = NULL, *value = NULL;
1829 if (!o) {
1830 Py_INCREF(Py_None);
1831 return Py_None;
1832 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001833
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001834 switch (o->kind) {
1835 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001836 result = PyType_GenericNew(Module_type, NULL, NULL);
1837 if (!result) goto failed;
1838 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1839 if (!value) goto failed;
1840 if (PyObject_SetAttrString(result, "body", value) == -1)
1841 goto failed;
1842 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001843 break;
1844 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001845 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1846 if (!result) goto failed;
1847 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1848 if (!value) goto failed;
1849 if (PyObject_SetAttrString(result, "body", value) == -1)
1850 goto failed;
1851 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001852 break;
1853 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001854 result = PyType_GenericNew(Expression_type, NULL, NULL);
1855 if (!result) goto failed;
1856 value = ast2obj_expr(o->v.Expression.body);
1857 if (!value) goto failed;
1858 if (PyObject_SetAttrString(result, "body", value) == -1)
1859 goto failed;
1860 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001861 break;
1862 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001863 result = PyType_GenericNew(Suite_type, NULL, NULL);
1864 if (!result) goto failed;
1865 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1866 if (!value) goto failed;
1867 if (PyObject_SetAttrString(result, "body", value) == -1)
1868 goto failed;
1869 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870 break;
1871 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001872 return result;
1873failed:
1874 Py_XDECREF(value);
1875 Py_XDECREF(result);
1876 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877}
1878
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001879PyObject*
1880ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001882 stmt_ty o = (stmt_ty)_o;
1883 PyObject *result = NULL, *value = NULL;
1884 if (!o) {
1885 Py_INCREF(Py_None);
1886 return Py_None;
1887 }
1888
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001889 switch (o->kind) {
1890 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001891 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1892 if (!result) goto failed;
1893 value = ast2obj_identifier(o->v.FunctionDef.name);
1894 if (!value) goto failed;
1895 if (PyObject_SetAttrString(result, "name", value) == -1)
1896 goto failed;
1897 Py_DECREF(value);
1898 value = ast2obj_arguments(o->v.FunctionDef.args);
1899 if (!value) goto failed;
1900 if (PyObject_SetAttrString(result, "args", value) == -1)
1901 goto failed;
1902 Py_DECREF(value);
1903 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1904 if (!value) goto failed;
1905 if (PyObject_SetAttrString(result, "body", value) == -1)
1906 goto failed;
1907 Py_DECREF(value);
1908 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1909 if (!value) goto failed;
1910 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1911 goto failed;
1912 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913 break;
1914 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001915 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1916 if (!result) goto failed;
1917 value = ast2obj_identifier(o->v.ClassDef.name);
1918 if (!value) goto failed;
1919 if (PyObject_SetAttrString(result, "name", value) == -1)
1920 goto failed;
1921 Py_DECREF(value);
1922 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1923 if (!value) goto failed;
1924 if (PyObject_SetAttrString(result, "bases", value) == -1)
1925 goto failed;
1926 Py_DECREF(value);
1927 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "body", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001932 break;
1933 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001934 result = PyType_GenericNew(Return_type, NULL, NULL);
1935 if (!result) goto failed;
1936 value = ast2obj_expr(o->v.Return.value);
1937 if (!value) goto failed;
1938 if (PyObject_SetAttrString(result, "value", value) == -1)
1939 goto failed;
1940 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001941 break;
1942 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001943 result = PyType_GenericNew(Delete_type, NULL, NULL);
1944 if (!result) goto failed;
1945 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1946 if (!value) goto failed;
1947 if (PyObject_SetAttrString(result, "targets", value) == -1)
1948 goto failed;
1949 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001950 break;
1951 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001952 result = PyType_GenericNew(Assign_type, NULL, NULL);
1953 if (!result) goto failed;
1954 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1955 if (!value) goto failed;
1956 if (PyObject_SetAttrString(result, "targets", value) == -1)
1957 goto failed;
1958 Py_DECREF(value);
1959 value = ast2obj_expr(o->v.Assign.value);
1960 if (!value) goto failed;
1961 if (PyObject_SetAttrString(result, "value", value) == -1)
1962 goto failed;
1963 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001964 break;
1965 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001966 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
1967 if (!result) goto failed;
1968 value = ast2obj_expr(o->v.AugAssign.target);
1969 if (!value) goto failed;
1970 if (PyObject_SetAttrString(result, "target", value) == -1)
1971 goto failed;
1972 Py_DECREF(value);
1973 value = ast2obj_operator(o->v.AugAssign.op);
1974 if (!value) goto failed;
1975 if (PyObject_SetAttrString(result, "op", value) == -1)
1976 goto failed;
1977 Py_DECREF(value);
1978 value = ast2obj_expr(o->v.AugAssign.value);
1979 if (!value) goto failed;
1980 if (PyObject_SetAttrString(result, "value", value) == -1)
1981 goto failed;
1982 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001983 break;
1984 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001985 result = PyType_GenericNew(Print_type, NULL, NULL);
1986 if (!result) goto failed;
1987 value = ast2obj_expr(o->v.Print.dest);
1988 if (!value) goto failed;
1989 if (PyObject_SetAttrString(result, "dest", value) == -1)
1990 goto failed;
1991 Py_DECREF(value);
1992 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
1993 if (!value) goto failed;
1994 if (PyObject_SetAttrString(result, "values", value) == -1)
1995 goto failed;
1996 Py_DECREF(value);
1997 value = ast2obj_bool(o->v.Print.nl);
1998 if (!value) goto failed;
1999 if (PyObject_SetAttrString(result, "nl", value) == -1)
2000 goto failed;
2001 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002002 break;
2003 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002004 result = PyType_GenericNew(For_type, NULL, NULL);
2005 if (!result) goto failed;
2006 value = ast2obj_expr(o->v.For.target);
2007 if (!value) goto failed;
2008 if (PyObject_SetAttrString(result, "target", value) == -1)
2009 goto failed;
2010 Py_DECREF(value);
2011 value = ast2obj_expr(o->v.For.iter);
2012 if (!value) goto failed;
2013 if (PyObject_SetAttrString(result, "iter", value) == -1)
2014 goto failed;
2015 Py_DECREF(value);
2016 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2017 if (!value) goto failed;
2018 if (PyObject_SetAttrString(result, "body", value) == -1)
2019 goto failed;
2020 Py_DECREF(value);
2021 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002026 break;
2027 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002028 result = PyType_GenericNew(While_type, NULL, NULL);
2029 if (!result) goto failed;
2030 value = ast2obj_expr(o->v.While.test);
2031 if (!value) goto failed;
2032 if (PyObject_SetAttrString(result, "test", value) == -1)
2033 goto failed;
2034 Py_DECREF(value);
2035 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2036 if (!value) goto failed;
2037 if (PyObject_SetAttrString(result, "body", value) == -1)
2038 goto failed;
2039 Py_DECREF(value);
2040 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002045 break;
2046 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002047 result = PyType_GenericNew(If_type, NULL, NULL);
2048 if (!result) goto failed;
2049 value = ast2obj_expr(o->v.If.test);
2050 if (!value) goto failed;
2051 if (PyObject_SetAttrString(result, "test", value) == -1)
2052 goto failed;
2053 Py_DECREF(value);
2054 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "body", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
2059 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002064 break;
2065 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002066 result = PyType_GenericNew(Raise_type, NULL, NULL);
2067 if (!result) goto failed;
2068 value = ast2obj_expr(o->v.Raise.type);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "type", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
2073 value = ast2obj_expr(o->v.Raise.inst);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "inst", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
2078 value = ast2obj_expr(o->v.Raise.tback);
2079 if (!value) goto failed;
2080 if (PyObject_SetAttrString(result, "tback", value) == -1)
2081 goto failed;
2082 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002083 break;
2084 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002085 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2086 if (!result) goto failed;
2087 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "body", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_list(o->v.TryExcept.handlers,
2093 ast2obj_excepthandler);
2094 if (!value) goto failed;
2095 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2096 goto failed;
2097 Py_DECREF(value);
2098 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2099 if (!value) goto failed;
2100 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2101 goto failed;
2102 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002103 break;
2104 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002105 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2106 if (!result) goto failed;
2107 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "body", value) == -1)
2110 goto failed;
2111 Py_DECREF(value);
2112 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2113 if (!value) goto failed;
2114 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2115 goto failed;
2116 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002117 break;
2118 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002119 result = PyType_GenericNew(Assert_type, NULL, NULL);
2120 if (!result) goto failed;
2121 value = ast2obj_expr(o->v.Assert.test);
2122 if (!value) goto failed;
2123 if (PyObject_SetAttrString(result, "test", value) == -1)
2124 goto failed;
2125 Py_DECREF(value);
2126 value = ast2obj_expr(o->v.Assert.msg);
2127 if (!value) goto failed;
2128 if (PyObject_SetAttrString(result, "msg", value) == -1)
2129 goto failed;
2130 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002131 break;
2132 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002133 result = PyType_GenericNew(Import_type, NULL, NULL);
2134 if (!result) goto failed;
2135 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "names", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002140 break;
2141 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002142 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2143 if (!result) goto failed;
2144 value = ast2obj_identifier(o->v.ImportFrom.module);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "module", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "names", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002154 break;
2155 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002156 result = PyType_GenericNew(Exec_type, NULL, NULL);
2157 if (!result) goto failed;
2158 value = ast2obj_expr(o->v.Exec.body);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "body", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
2163 value = ast2obj_expr(o->v.Exec.globals);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "globals", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_expr(o->v.Exec.locals);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "locals", value) == -1)
2171 goto failed;
2172 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002173 break;
2174 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002175 result = PyType_GenericNew(Global_type, NULL, NULL);
2176 if (!result) goto failed;
2177 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2178 if (!value) goto failed;
2179 if (PyObject_SetAttrString(result, "names", value) == -1)
2180 goto failed;
2181 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182 break;
2183 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002184 result = PyType_GenericNew(Expr_type, NULL, NULL);
2185 if (!result) goto failed;
2186 value = ast2obj_expr(o->v.Expr.value);
2187 if (!value) goto failed;
2188 if (PyObject_SetAttrString(result, "value", value) == -1)
2189 goto failed;
2190 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002191 break;
2192 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002193 result = PyType_GenericNew(Pass_type, NULL, NULL);
2194 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002195 break;
2196 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002197 result = PyType_GenericNew(Break_type, NULL, NULL);
2198 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199 break;
2200 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002201 result = PyType_GenericNew(Continue_type, NULL, NULL);
2202 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002203 break;
2204 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002205 value = ast2obj_int(o->lineno);
2206 if (!value) goto failed;
2207 PyObject_SetAttrString(result, "lineno", value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002208 return result;
2209failed:
2210 Py_XDECREF(value);
2211 Py_XDECREF(result);
2212 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002213}
2214
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002215PyObject*
2216ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002217{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002218 expr_ty o = (expr_ty)_o;
2219 PyObject *result = NULL, *value = NULL;
2220 if (!o) {
2221 Py_INCREF(Py_None);
2222 return Py_None;
2223 }
2224
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002225 switch (o->kind) {
2226 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002227 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2228 if (!result) goto failed;
2229 value = ast2obj_boolop(o->v.BoolOp.op);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "op", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
2234 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "values", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002239 break;
2240 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002241 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2242 if (!result) goto failed;
2243 value = ast2obj_expr(o->v.BinOp.left);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "left", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
2248 value = ast2obj_operator(o->v.BinOp.op);
2249 if (!value) goto failed;
2250 if (PyObject_SetAttrString(result, "op", value) == -1)
2251 goto failed;
2252 Py_DECREF(value);
2253 value = ast2obj_expr(o->v.BinOp.right);
2254 if (!value) goto failed;
2255 if (PyObject_SetAttrString(result, "right", value) == -1)
2256 goto failed;
2257 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002258 break;
2259 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002260 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2261 if (!result) goto failed;
2262 value = ast2obj_unaryop(o->v.UnaryOp.op);
2263 if (!value) goto failed;
2264 if (PyObject_SetAttrString(result, "op", value) == -1)
2265 goto failed;
2266 Py_DECREF(value);
2267 value = ast2obj_expr(o->v.UnaryOp.operand);
2268 if (!value) goto failed;
2269 if (PyObject_SetAttrString(result, "operand", value) == -1)
2270 goto failed;
2271 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002272 break;
2273 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002274 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2275 if (!result) goto failed;
2276 value = ast2obj_arguments(o->v.Lambda.args);
2277 if (!value) goto failed;
2278 if (PyObject_SetAttrString(result, "args", value) == -1)
2279 goto failed;
2280 Py_DECREF(value);
2281 value = ast2obj_expr(o->v.Lambda.body);
2282 if (!value) goto failed;
2283 if (PyObject_SetAttrString(result, "body", value) == -1)
2284 goto failed;
2285 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002286 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002287 case IfExp_kind:
2288 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2289 if (!result) goto failed;
2290 value = ast2obj_expr(o->v.IfExp.test);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "test", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
2295 value = ast2obj_expr(o->v.IfExp.body);
2296 if (!value) goto failed;
2297 if (PyObject_SetAttrString(result, "body", value) == -1)
2298 goto failed;
2299 Py_DECREF(value);
2300 value = ast2obj_expr(o->v.IfExp.orelse);
2301 if (!value) goto failed;
2302 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2303 goto failed;
2304 Py_DECREF(value);
2305 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002306 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002307 result = PyType_GenericNew(Dict_type, NULL, NULL);
2308 if (!result) goto failed;
2309 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "keys", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
2314 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2315 if (!value) goto failed;
2316 if (PyObject_SetAttrString(result, "values", value) == -1)
2317 goto failed;
2318 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319 break;
2320 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002321 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2322 if (!result) goto failed;
2323 value = ast2obj_expr(o->v.ListComp.elt);
2324 if (!value) goto failed;
2325 if (PyObject_SetAttrString(result, "elt", value) == -1)
2326 goto failed;
2327 Py_DECREF(value);
2328 value = ast2obj_list(o->v.ListComp.generators,
2329 ast2obj_comprehension);
2330 if (!value) goto failed;
2331 if (PyObject_SetAttrString(result, "generators", value) == -1)
2332 goto failed;
2333 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002334 break;
2335 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002336 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2337 if (!result) goto failed;
2338 value = ast2obj_expr(o->v.GeneratorExp.elt);
2339 if (!value) goto failed;
2340 if (PyObject_SetAttrString(result, "elt", value) == -1)
2341 goto failed;
2342 Py_DECREF(value);
2343 value = ast2obj_list(o->v.GeneratorExp.generators,
2344 ast2obj_comprehension);
2345 if (!value) goto failed;
2346 if (PyObject_SetAttrString(result, "generators", value) == -1)
2347 goto failed;
2348 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002349 break;
2350 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002351 result = PyType_GenericNew(Yield_type, NULL, NULL);
2352 if (!result) goto failed;
2353 value = ast2obj_expr(o->v.Yield.value);
2354 if (!value) goto failed;
2355 if (PyObject_SetAttrString(result, "value", value) == -1)
2356 goto failed;
2357 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002358 break;
2359 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002360 result = PyType_GenericNew(Compare_type, NULL, NULL);
2361 if (!result) goto failed;
2362 value = ast2obj_expr(o->v.Compare.left);
2363 if (!value) goto failed;
2364 if (PyObject_SetAttrString(result, "left", value) == -1)
2365 goto failed;
2366 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002367 {
2368 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2369 value = PyList_New(n);
2370 if (!value) goto failed;
2371 for(i = 0; i < n; i++)
2372 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2373 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002374 if (!value) goto failed;
2375 if (PyObject_SetAttrString(result, "ops", value) == -1)
2376 goto failed;
2377 Py_DECREF(value);
2378 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2379 if (!value) goto failed;
2380 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2381 goto failed;
2382 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002383 break;
2384 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002385 result = PyType_GenericNew(Call_type, NULL, NULL);
2386 if (!result) goto failed;
2387 value = ast2obj_expr(o->v.Call.func);
2388 if (!value) goto failed;
2389 if (PyObject_SetAttrString(result, "func", value) == -1)
2390 goto failed;
2391 Py_DECREF(value);
2392 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2393 if (!value) goto failed;
2394 if (PyObject_SetAttrString(result, "args", value) == -1)
2395 goto failed;
2396 Py_DECREF(value);
2397 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2398 if (!value) goto failed;
2399 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2400 goto failed;
2401 Py_DECREF(value);
2402 value = ast2obj_expr(o->v.Call.starargs);
2403 if (!value) goto failed;
2404 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2405 goto failed;
2406 Py_DECREF(value);
2407 value = ast2obj_expr(o->v.Call.kwargs);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002412 break;
2413 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002414 result = PyType_GenericNew(Repr_type, NULL, NULL);
2415 if (!result) goto failed;
2416 value = ast2obj_expr(o->v.Repr.value);
2417 if (!value) goto failed;
2418 if (PyObject_SetAttrString(result, "value", value) == -1)
2419 goto failed;
2420 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002421 break;
2422 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002423 result = PyType_GenericNew(Num_type, NULL, NULL);
2424 if (!result) goto failed;
2425 value = ast2obj_object(o->v.Num.n);
2426 if (!value) goto failed;
2427 if (PyObject_SetAttrString(result, "n", value) == -1)
2428 goto failed;
2429 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002430 break;
2431 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002432 result = PyType_GenericNew(Str_type, NULL, NULL);
2433 if (!result) goto failed;
2434 value = ast2obj_string(o->v.Str.s);
2435 if (!value) goto failed;
2436 if (PyObject_SetAttrString(result, "s", value) == -1)
2437 goto failed;
2438 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002439 break;
2440 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002441 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2442 if (!result) goto failed;
2443 value = ast2obj_expr(o->v.Attribute.value);
2444 if (!value) goto failed;
2445 if (PyObject_SetAttrString(result, "value", value) == -1)
2446 goto failed;
2447 Py_DECREF(value);
2448 value = ast2obj_identifier(o->v.Attribute.attr);
2449 if (!value) goto failed;
2450 if (PyObject_SetAttrString(result, "attr", value) == -1)
2451 goto failed;
2452 Py_DECREF(value);
2453 value = ast2obj_expr_context(o->v.Attribute.ctx);
2454 if (!value) goto failed;
2455 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2456 goto failed;
2457 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002458 break;
2459 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002460 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2461 if (!result) goto failed;
2462 value = ast2obj_expr(o->v.Subscript.value);
2463 if (!value) goto failed;
2464 if (PyObject_SetAttrString(result, "value", value) == -1)
2465 goto failed;
2466 Py_DECREF(value);
2467 value = ast2obj_slice(o->v.Subscript.slice);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "slice", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
2472 value = ast2obj_expr_context(o->v.Subscript.ctx);
2473 if (!value) goto failed;
2474 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2475 goto failed;
2476 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477 break;
2478 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002479 result = PyType_GenericNew(Name_type, NULL, NULL);
2480 if (!result) goto failed;
2481 value = ast2obj_identifier(o->v.Name.id);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "id", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 value = ast2obj_expr_context(o->v.Name.ctx);
2487 if (!value) goto failed;
2488 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2489 goto failed;
2490 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002491 break;
2492 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002493 result = PyType_GenericNew(List_type, NULL, NULL);
2494 if (!result) goto failed;
2495 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2496 if (!value) goto failed;
2497 if (PyObject_SetAttrString(result, "elts", value) == -1)
2498 goto failed;
2499 Py_DECREF(value);
2500 value = ast2obj_expr_context(o->v.List.ctx);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505 break;
2506 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002507 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2508 if (!result) goto failed;
2509 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "elts", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
2514 value = ast2obj_expr_context(o->v.Tuple.ctx);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002519 break;
2520 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002521 value = ast2obj_int(o->lineno);
2522 if (!value) goto failed;
2523 PyObject_SetAttrString(result, "lineno", value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002524 return result;
2525failed:
2526 Py_XDECREF(value);
2527 Py_XDECREF(result);
2528 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002529}
2530
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002531PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002532{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002533 switch(o) {
2534 case Load:
2535 Py_INCREF(Load_singleton);
2536 return Load_singleton;
2537 case Store:
2538 Py_INCREF(Store_singleton);
2539 return Store_singleton;
2540 case Del:
2541 Py_INCREF(Del_singleton);
2542 return Del_singleton;
2543 case AugLoad:
2544 Py_INCREF(AugLoad_singleton);
2545 return AugLoad_singleton;
2546 case AugStore:
2547 Py_INCREF(AugStore_singleton);
2548 return AugStore_singleton;
2549 case Param:
2550 Py_INCREF(Param_singleton);
2551 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002552 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002553 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002554}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002555PyObject*
2556ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002558 slice_ty o = (slice_ty)_o;
2559 PyObject *result = NULL, *value = NULL;
2560 if (!o) {
2561 Py_INCREF(Py_None);
2562 return Py_None;
2563 }
2564
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002565 switch (o->kind) {
2566 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002567 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2568 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002569 break;
2570 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002571 result = PyType_GenericNew(Slice_type, NULL, NULL);
2572 if (!result) goto failed;
2573 value = ast2obj_expr(o->v.Slice.lower);
2574 if (!value) goto failed;
2575 if (PyObject_SetAttrString(result, "lower", value) == -1)
2576 goto failed;
2577 Py_DECREF(value);
2578 value = ast2obj_expr(o->v.Slice.upper);
2579 if (!value) goto failed;
2580 if (PyObject_SetAttrString(result, "upper", value) == -1)
2581 goto failed;
2582 Py_DECREF(value);
2583 value = ast2obj_expr(o->v.Slice.step);
2584 if (!value) goto failed;
2585 if (PyObject_SetAttrString(result, "step", value) == -1)
2586 goto failed;
2587 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002588 break;
2589 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002590 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2591 if (!result) goto failed;
2592 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2593 if (!value) goto failed;
2594 if (PyObject_SetAttrString(result, "dims", value) == -1)
2595 goto failed;
2596 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002597 break;
2598 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002599 result = PyType_GenericNew(Index_type, NULL, NULL);
2600 if (!result) goto failed;
2601 value = ast2obj_expr(o->v.Index.value);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "value", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606 break;
2607 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002608 return result;
2609failed:
2610 Py_XDECREF(value);
2611 Py_XDECREF(result);
2612 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002613}
2614
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002615PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002616{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002617 switch(o) {
2618 case And:
2619 Py_INCREF(And_singleton);
2620 return And_singleton;
2621 case Or:
2622 Py_INCREF(Or_singleton);
2623 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002624 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002625 return NULL; /* cannot happen */
2626}
2627PyObject* ast2obj_operator(operator_ty o)
2628{
2629 switch(o) {
2630 case Add:
2631 Py_INCREF(Add_singleton);
2632 return Add_singleton;
2633 case Sub:
2634 Py_INCREF(Sub_singleton);
2635 return Sub_singleton;
2636 case Mult:
2637 Py_INCREF(Mult_singleton);
2638 return Mult_singleton;
2639 case Div:
2640 Py_INCREF(Div_singleton);
2641 return Div_singleton;
2642 case Mod:
2643 Py_INCREF(Mod_singleton);
2644 return Mod_singleton;
2645 case Pow:
2646 Py_INCREF(Pow_singleton);
2647 return Pow_singleton;
2648 case LShift:
2649 Py_INCREF(LShift_singleton);
2650 return LShift_singleton;
2651 case RShift:
2652 Py_INCREF(RShift_singleton);
2653 return RShift_singleton;
2654 case BitOr:
2655 Py_INCREF(BitOr_singleton);
2656 return BitOr_singleton;
2657 case BitXor:
2658 Py_INCREF(BitXor_singleton);
2659 return BitXor_singleton;
2660 case BitAnd:
2661 Py_INCREF(BitAnd_singleton);
2662 return BitAnd_singleton;
2663 case FloorDiv:
2664 Py_INCREF(FloorDiv_singleton);
2665 return FloorDiv_singleton;
2666 }
2667 return NULL; /* cannot happen */
2668}
2669PyObject* ast2obj_unaryop(unaryop_ty o)
2670{
2671 switch(o) {
2672 case Invert:
2673 Py_INCREF(Invert_singleton);
2674 return Invert_singleton;
2675 case Not:
2676 Py_INCREF(Not_singleton);
2677 return Not_singleton;
2678 case UAdd:
2679 Py_INCREF(UAdd_singleton);
2680 return UAdd_singleton;
2681 case USub:
2682 Py_INCREF(USub_singleton);
2683 return USub_singleton;
2684 }
2685 return NULL; /* cannot happen */
2686}
2687PyObject* ast2obj_cmpop(cmpop_ty o)
2688{
2689 switch(o) {
2690 case Eq:
2691 Py_INCREF(Eq_singleton);
2692 return Eq_singleton;
2693 case NotEq:
2694 Py_INCREF(NotEq_singleton);
2695 return NotEq_singleton;
2696 case Lt:
2697 Py_INCREF(Lt_singleton);
2698 return Lt_singleton;
2699 case LtE:
2700 Py_INCREF(LtE_singleton);
2701 return LtE_singleton;
2702 case Gt:
2703 Py_INCREF(Gt_singleton);
2704 return Gt_singleton;
2705 case GtE:
2706 Py_INCREF(GtE_singleton);
2707 return GtE_singleton;
2708 case Is:
2709 Py_INCREF(Is_singleton);
2710 return Is_singleton;
2711 case IsNot:
2712 Py_INCREF(IsNot_singleton);
2713 return IsNot_singleton;
2714 case In:
2715 Py_INCREF(In_singleton);
2716 return In_singleton;
2717 case NotIn:
2718 Py_INCREF(NotIn_singleton);
2719 return NotIn_singleton;
2720 }
2721 return NULL; /* cannot happen */
2722}
2723PyObject*
2724ast2obj_comprehension(void* _o)
2725{
2726 comprehension_ty o = (comprehension_ty)_o;
2727 PyObject *result = NULL, *value = NULL;
2728 if (!o) {
2729 Py_INCREF(Py_None);
2730 return Py_None;
2731 }
2732
2733 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2734 if (!result) return NULL;
2735 value = ast2obj_expr(o->target);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "target", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
2740 value = ast2obj_expr(o->iter);
2741 if (!value) goto failed;
2742 if (PyObject_SetAttrString(result, "iter", value) == -1)
2743 goto failed;
2744 Py_DECREF(value);
2745 value = ast2obj_list(o->ifs, ast2obj_expr);
2746 if (!value) goto failed;
2747 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2748 goto failed;
2749 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002750 return result;
2751failed:
2752 Py_XDECREF(value);
2753 Py_XDECREF(result);
2754 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002755}
2756
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002757PyObject*
2758ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002759{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002760 excepthandler_ty o = (excepthandler_ty)_o;
2761 PyObject *result = NULL, *value = NULL;
2762 if (!o) {
2763 Py_INCREF(Py_None);
2764 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002765 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002766
2767 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2768 if (!result) return NULL;
2769 value = ast2obj_expr(o->type);
2770 if (!value) goto failed;
2771 if (PyObject_SetAttrString(result, "type", value) == -1)
2772 goto failed;
2773 Py_DECREF(value);
2774 value = ast2obj_expr(o->name);
2775 if (!value) goto failed;
2776 if (PyObject_SetAttrString(result, "name", value) == -1)
2777 goto failed;
2778 Py_DECREF(value);
2779 value = ast2obj_list(o->body, ast2obj_stmt);
2780 if (!value) goto failed;
2781 if (PyObject_SetAttrString(result, "body", value) == -1)
2782 goto failed;
2783 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002784 return result;
2785failed:
2786 Py_XDECREF(value);
2787 Py_XDECREF(result);
2788 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002789}
2790
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002791PyObject*
2792ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002793{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002794 arguments_ty o = (arguments_ty)_o;
2795 PyObject *result = NULL, *value = NULL;
2796 if (!o) {
2797 Py_INCREF(Py_None);
2798 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002799 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002800
2801 result = PyType_GenericNew(arguments_type, NULL, NULL);
2802 if (!result) return NULL;
2803 value = ast2obj_list(o->args, ast2obj_expr);
2804 if (!value) goto failed;
2805 if (PyObject_SetAttrString(result, "args", value) == -1)
2806 goto failed;
2807 Py_DECREF(value);
2808 value = ast2obj_identifier(o->vararg);
2809 if (!value) goto failed;
2810 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2811 goto failed;
2812 Py_DECREF(value);
2813 value = ast2obj_identifier(o->kwarg);
2814 if (!value) goto failed;
2815 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2816 goto failed;
2817 Py_DECREF(value);
2818 value = ast2obj_list(o->defaults, ast2obj_expr);
2819 if (!value) goto failed;
2820 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2821 goto failed;
2822 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002823 return result;
2824failed:
2825 Py_XDECREF(value);
2826 Py_XDECREF(result);
2827 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002828}
2829
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002830PyObject*
2831ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002832{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002833 keyword_ty o = (keyword_ty)_o;
2834 PyObject *result = NULL, *value = NULL;
2835 if (!o) {
2836 Py_INCREF(Py_None);
2837 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002838 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002839
2840 result = PyType_GenericNew(keyword_type, NULL, NULL);
2841 if (!result) return NULL;
2842 value = ast2obj_identifier(o->arg);
2843 if (!value) goto failed;
2844 if (PyObject_SetAttrString(result, "arg", value) == -1)
2845 goto failed;
2846 Py_DECREF(value);
2847 value = ast2obj_expr(o->value);
2848 if (!value) goto failed;
2849 if (PyObject_SetAttrString(result, "value", value) == -1)
2850 goto failed;
2851 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002852 return result;
2853failed:
2854 Py_XDECREF(value);
2855 Py_XDECREF(result);
2856 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002857}
2858
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002859PyObject*
2860ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002861{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002862 alias_ty o = (alias_ty)_o;
2863 PyObject *result = NULL, *value = NULL;
2864 if (!o) {
2865 Py_INCREF(Py_None);
2866 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002867 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002868
2869 result = PyType_GenericNew(alias_type, NULL, NULL);
2870 if (!result) return NULL;
2871 value = ast2obj_identifier(o->name);
2872 if (!value) goto failed;
2873 if (PyObject_SetAttrString(result, "name", value) == -1)
2874 goto failed;
2875 Py_DECREF(value);
2876 value = ast2obj_identifier(o->asname);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "asname", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002881 return result;
2882failed:
2883 Py_XDECREF(value);
2884 Py_XDECREF(result);
2885 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002886}
2887
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002888
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002889PyMODINIT_FUNC
2890init_ast(void)
2891{
2892 PyObject *m, *d;
2893 if (!init_types()) return;
2894 m = Py_InitModule3("_ast", NULL, NULL);
2895 if (!m) return;
2896 d = PyModule_GetDict(m);
2897 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
2898 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
2899 return;
2900 if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
2901 if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
2902 return;
2903 if(PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
2904 < 0) return;
2905 if(PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
2906 0) return;
2907 if(PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
2908 if(PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
2909 if(PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
2910 < 0) return;
2911 if(PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
2912 return;
2913 if(PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
2914 return;
2915 if(PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
2916 return;
2917 if(PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
2918 return;
2919 if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
2920 return;
2921 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
2922 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
2923 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
2924 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
2925 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
2926 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
2927 return;
2928 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
2929 0) return;
2930 if(PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
2931 return;
2932 if(PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
2933 return;
2934 if(PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
2935 0) return;
2936 if(PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
2937 if(PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
2938 return;
2939 if(PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
2940 if(PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
2941 if(PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
2942 if(PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
2943 return;
2944 if(PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
2945 if(PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
2946 return;
2947 if(PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
2948 if(PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
2949 return;
2950 if(PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
2951 return;
2952 if(PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
2953 if(PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
2954 if(PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
2955 return;
2956 if(PyDict_SetItemString(d, "GeneratorExp",
2957 (PyObject*)GeneratorExp_type) < 0) return;
2958 if(PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
2959 if(PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
2960 return;
2961 if(PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
2962 if(PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
2963 if(PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
2964 if(PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
2965 if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
2966 return;
2967 if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
2968 return;
2969 if(PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
2970 if(PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
2971 if(PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
2972 if(PyDict_SetItemString(d, "expr_context",
2973 (PyObject*)expr_context_type) < 0) return;
2974 if(PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
2975 if(PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
2976 if(PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
2977 if(PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
2978 return;
2979 if(PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
2980 return;
2981 if(PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
2982 if(PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
2983 if(PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
2984 return;
2985 if(PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
2986 if(PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
2987 return;
2988 if(PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
2989 if(PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
2990 return;
2991 if(PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
2992 if(PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
2993 if(PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
2994 return;
2995 if(PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
2996 if(PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
2997 if(PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
2998 if(PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
2999 if(PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3000 if(PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3001 if(PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3002 return;
3003 if(PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3004 return;
3005 if(PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3006 if(PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3007 return;
3008 if(PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3009 return;
3010 if(PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3011 return;
3012 if(PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3013 return;
3014 if(PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3015 return;
3016 if(PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3017 if(PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3018 if(PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3019 if(PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3020 if(PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3021 if(PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3022 if(PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3023 if(PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3024 if(PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3025 if(PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3026 if(PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3027 if(PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3028 if(PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3029 if(PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3030 if(PyDict_SetItemString(d, "comprehension",
3031 (PyObject*)comprehension_type) < 0) return;
3032 if(PyDict_SetItemString(d, "excepthandler",
3033 (PyObject*)excepthandler_type) < 0) return;
3034 if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
3035 return;
3036 if(PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3037 return;
3038 if(PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
3039}
3040
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003041
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003042PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003043{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003044 init_types();
3045 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003046}
3047
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003048