]>
Commit | Line | Data |
---|---|---|
c8042e10 DM |
1 | /* File automatically generated by Parser/asdl_c.py. */\r |
2 | \r | |
3 | \r | |
4 | /*\r | |
5 | __version__ 82160.\r | |
6 | \r | |
7 | This module must be committed separately after each AST grammar change;\r | |
8 | The __version__ number is set to the revision number of the commit\r | |
9 | containing the grammar change.\r | |
10 | */\r | |
11 | \r | |
12 | #include "Python.h"\r | |
13 | #include "Python-ast.h"\r | |
14 | \r | |
15 | static PyTypeObject AST_type;\r | |
16 | static PyTypeObject *mod_type;\r | |
17 | static PyObject* ast2obj_mod(void*);\r | |
18 | static PyTypeObject *Module_type;\r | |
19 | static char *Module_fields[]={\r | |
20 | "body",\r | |
21 | };\r | |
22 | static PyTypeObject *Interactive_type;\r | |
23 | static char *Interactive_fields[]={\r | |
24 | "body",\r | |
25 | };\r | |
26 | static PyTypeObject *Expression_type;\r | |
27 | static char *Expression_fields[]={\r | |
28 | "body",\r | |
29 | };\r | |
30 | static PyTypeObject *Suite_type;\r | |
31 | static char *Suite_fields[]={\r | |
32 | "body",\r | |
33 | };\r | |
34 | static PyTypeObject *stmt_type;\r | |
35 | static char *stmt_attributes[] = {\r | |
36 | "lineno",\r | |
37 | "col_offset",\r | |
38 | };\r | |
39 | static PyObject* ast2obj_stmt(void*);\r | |
40 | static PyTypeObject *FunctionDef_type;\r | |
41 | static char *FunctionDef_fields[]={\r | |
42 | "name",\r | |
43 | "args",\r | |
44 | "body",\r | |
45 | "decorator_list",\r | |
46 | };\r | |
47 | static PyTypeObject *ClassDef_type;\r | |
48 | static char *ClassDef_fields[]={\r | |
49 | "name",\r | |
50 | "bases",\r | |
51 | "body",\r | |
52 | "decorator_list",\r | |
53 | };\r | |
54 | static PyTypeObject *Return_type;\r | |
55 | static char *Return_fields[]={\r | |
56 | "value",\r | |
57 | };\r | |
58 | static PyTypeObject *Delete_type;\r | |
59 | static char *Delete_fields[]={\r | |
60 | "targets",\r | |
61 | };\r | |
62 | static PyTypeObject *Assign_type;\r | |
63 | static char *Assign_fields[]={\r | |
64 | "targets",\r | |
65 | "value",\r | |
66 | };\r | |
67 | static PyTypeObject *AugAssign_type;\r | |
68 | static char *AugAssign_fields[]={\r | |
69 | "target",\r | |
70 | "op",\r | |
71 | "value",\r | |
72 | };\r | |
73 | static PyTypeObject *Print_type;\r | |
74 | static char *Print_fields[]={\r | |
75 | "dest",\r | |
76 | "values",\r | |
77 | "nl",\r | |
78 | };\r | |
79 | static PyTypeObject *For_type;\r | |
80 | static char *For_fields[]={\r | |
81 | "target",\r | |
82 | "iter",\r | |
83 | "body",\r | |
84 | "orelse",\r | |
85 | };\r | |
86 | static PyTypeObject *While_type;\r | |
87 | static char *While_fields[]={\r | |
88 | "test",\r | |
89 | "body",\r | |
90 | "orelse",\r | |
91 | };\r | |
92 | static PyTypeObject *If_type;\r | |
93 | static char *If_fields[]={\r | |
94 | "test",\r | |
95 | "body",\r | |
96 | "orelse",\r | |
97 | };\r | |
98 | static PyTypeObject *With_type;\r | |
99 | static char *With_fields[]={\r | |
100 | "context_expr",\r | |
101 | "optional_vars",\r | |
102 | "body",\r | |
103 | };\r | |
104 | static PyTypeObject *Raise_type;\r | |
105 | static char *Raise_fields[]={\r | |
106 | "type",\r | |
107 | "inst",\r | |
108 | "tback",\r | |
109 | };\r | |
110 | static PyTypeObject *TryExcept_type;\r | |
111 | static char *TryExcept_fields[]={\r | |
112 | "body",\r | |
113 | "handlers",\r | |
114 | "orelse",\r | |
115 | };\r | |
116 | static PyTypeObject *TryFinally_type;\r | |
117 | static char *TryFinally_fields[]={\r | |
118 | "body",\r | |
119 | "finalbody",\r | |
120 | };\r | |
121 | static PyTypeObject *Assert_type;\r | |
122 | static char *Assert_fields[]={\r | |
123 | "test",\r | |
124 | "msg",\r | |
125 | };\r | |
126 | static PyTypeObject *Import_type;\r | |
127 | static char *Import_fields[]={\r | |
128 | "names",\r | |
129 | };\r | |
130 | static PyTypeObject *ImportFrom_type;\r | |
131 | static char *ImportFrom_fields[]={\r | |
132 | "module",\r | |
133 | "names",\r | |
134 | "level",\r | |
135 | };\r | |
136 | static PyTypeObject *Exec_type;\r | |
137 | static char *Exec_fields[]={\r | |
138 | "body",\r | |
139 | "globals",\r | |
140 | "locals",\r | |
141 | };\r | |
142 | static PyTypeObject *Global_type;\r | |
143 | static char *Global_fields[]={\r | |
144 | "names",\r | |
145 | };\r | |
146 | static PyTypeObject *Expr_type;\r | |
147 | static char *Expr_fields[]={\r | |
148 | "value",\r | |
149 | };\r | |
150 | static PyTypeObject *Pass_type;\r | |
151 | static PyTypeObject *Break_type;\r | |
152 | static PyTypeObject *Continue_type;\r | |
153 | static PyTypeObject *expr_type;\r | |
154 | static char *expr_attributes[] = {\r | |
155 | "lineno",\r | |
156 | "col_offset",\r | |
157 | };\r | |
158 | static PyObject* ast2obj_expr(void*);\r | |
159 | static PyTypeObject *BoolOp_type;\r | |
160 | static char *BoolOp_fields[]={\r | |
161 | "op",\r | |
162 | "values",\r | |
163 | };\r | |
164 | static PyTypeObject *BinOp_type;\r | |
165 | static char *BinOp_fields[]={\r | |
166 | "left",\r | |
167 | "op",\r | |
168 | "right",\r | |
169 | };\r | |
170 | static PyTypeObject *UnaryOp_type;\r | |
171 | static char *UnaryOp_fields[]={\r | |
172 | "op",\r | |
173 | "operand",\r | |
174 | };\r | |
175 | static PyTypeObject *Lambda_type;\r | |
176 | static char *Lambda_fields[]={\r | |
177 | "args",\r | |
178 | "body",\r | |
179 | };\r | |
180 | static PyTypeObject *IfExp_type;\r | |
181 | static char *IfExp_fields[]={\r | |
182 | "test",\r | |
183 | "body",\r | |
184 | "orelse",\r | |
185 | };\r | |
186 | static PyTypeObject *Dict_type;\r | |
187 | static char *Dict_fields[]={\r | |
188 | "keys",\r | |
189 | "values",\r | |
190 | };\r | |
191 | static PyTypeObject *Set_type;\r | |
192 | static char *Set_fields[]={\r | |
193 | "elts",\r | |
194 | };\r | |
195 | static PyTypeObject *ListComp_type;\r | |
196 | static char *ListComp_fields[]={\r | |
197 | "elt",\r | |
198 | "generators",\r | |
199 | };\r | |
200 | static PyTypeObject *SetComp_type;\r | |
201 | static char *SetComp_fields[]={\r | |
202 | "elt",\r | |
203 | "generators",\r | |
204 | };\r | |
205 | static PyTypeObject *DictComp_type;\r | |
206 | static char *DictComp_fields[]={\r | |
207 | "key",\r | |
208 | "value",\r | |
209 | "generators",\r | |
210 | };\r | |
211 | static PyTypeObject *GeneratorExp_type;\r | |
212 | static char *GeneratorExp_fields[]={\r | |
213 | "elt",\r | |
214 | "generators",\r | |
215 | };\r | |
216 | static PyTypeObject *Yield_type;\r | |
217 | static char *Yield_fields[]={\r | |
218 | "value",\r | |
219 | };\r | |
220 | static PyTypeObject *Compare_type;\r | |
221 | static char *Compare_fields[]={\r | |
222 | "left",\r | |
223 | "ops",\r | |
224 | "comparators",\r | |
225 | };\r | |
226 | static PyTypeObject *Call_type;\r | |
227 | static char *Call_fields[]={\r | |
228 | "func",\r | |
229 | "args",\r | |
230 | "keywords",\r | |
231 | "starargs",\r | |
232 | "kwargs",\r | |
233 | };\r | |
234 | static PyTypeObject *Repr_type;\r | |
235 | static char *Repr_fields[]={\r | |
236 | "value",\r | |
237 | };\r | |
238 | static PyTypeObject *Num_type;\r | |
239 | static char *Num_fields[]={\r | |
240 | "n",\r | |
241 | };\r | |
242 | static PyTypeObject *Str_type;\r | |
243 | static char *Str_fields[]={\r | |
244 | "s",\r | |
245 | };\r | |
246 | static PyTypeObject *Attribute_type;\r | |
247 | static char *Attribute_fields[]={\r | |
248 | "value",\r | |
249 | "attr",\r | |
250 | "ctx",\r | |
251 | };\r | |
252 | static PyTypeObject *Subscript_type;\r | |
253 | static char *Subscript_fields[]={\r | |
254 | "value",\r | |
255 | "slice",\r | |
256 | "ctx",\r | |
257 | };\r | |
258 | static PyTypeObject *Name_type;\r | |
259 | static char *Name_fields[]={\r | |
260 | "id",\r | |
261 | "ctx",\r | |
262 | };\r | |
263 | static PyTypeObject *List_type;\r | |
264 | static char *List_fields[]={\r | |
265 | "elts",\r | |
266 | "ctx",\r | |
267 | };\r | |
268 | static PyTypeObject *Tuple_type;\r | |
269 | static char *Tuple_fields[]={\r | |
270 | "elts",\r | |
271 | "ctx",\r | |
272 | };\r | |
273 | static PyTypeObject *expr_context_type;\r | |
274 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton,\r | |
275 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton;\r | |
276 | static PyObject* ast2obj_expr_context(expr_context_ty);\r | |
277 | static PyTypeObject *Load_type;\r | |
278 | static PyTypeObject *Store_type;\r | |
279 | static PyTypeObject *Del_type;\r | |
280 | static PyTypeObject *AugLoad_type;\r | |
281 | static PyTypeObject *AugStore_type;\r | |
282 | static PyTypeObject *Param_type;\r | |
283 | static PyTypeObject *slice_type;\r | |
284 | static PyObject* ast2obj_slice(void*);\r | |
285 | static PyTypeObject *Ellipsis_type;\r | |
286 | static PyTypeObject *Slice_type;\r | |
287 | static char *Slice_fields[]={\r | |
288 | "lower",\r | |
289 | "upper",\r | |
290 | "step",\r | |
291 | };\r | |
292 | static PyTypeObject *ExtSlice_type;\r | |
293 | static char *ExtSlice_fields[]={\r | |
294 | "dims",\r | |
295 | };\r | |
296 | static PyTypeObject *Index_type;\r | |
297 | static char *Index_fields[]={\r | |
298 | "value",\r | |
299 | };\r | |
300 | static PyTypeObject *boolop_type;\r | |
301 | static PyObject *And_singleton, *Or_singleton;\r | |
302 | static PyObject* ast2obj_boolop(boolop_ty);\r | |
303 | static PyTypeObject *And_type;\r | |
304 | static PyTypeObject *Or_type;\r | |
305 | static PyTypeObject *operator_type;\r | |
306 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,\r | |
307 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,\r | |
308 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,\r | |
309 | *FloorDiv_singleton;\r | |
310 | static PyObject* ast2obj_operator(operator_ty);\r | |
311 | static PyTypeObject *Add_type;\r | |
312 | static PyTypeObject *Sub_type;\r | |
313 | static PyTypeObject *Mult_type;\r | |
314 | static PyTypeObject *Div_type;\r | |
315 | static PyTypeObject *Mod_type;\r | |
316 | static PyTypeObject *Pow_type;\r | |
317 | static PyTypeObject *LShift_type;\r | |
318 | static PyTypeObject *RShift_type;\r | |
319 | static PyTypeObject *BitOr_type;\r | |
320 | static PyTypeObject *BitXor_type;\r | |
321 | static PyTypeObject *BitAnd_type;\r | |
322 | static PyTypeObject *FloorDiv_type;\r | |
323 | static PyTypeObject *unaryop_type;\r | |
324 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,\r | |
325 | *USub_singleton;\r | |
326 | static PyObject* ast2obj_unaryop(unaryop_ty);\r | |
327 | static PyTypeObject *Invert_type;\r | |
328 | static PyTypeObject *Not_type;\r | |
329 | static PyTypeObject *UAdd_type;\r | |
330 | static PyTypeObject *USub_type;\r | |
331 | static PyTypeObject *cmpop_type;\r | |
332 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,\r | |
333 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,\r | |
334 | *NotIn_singleton;\r | |
335 | static PyObject* ast2obj_cmpop(cmpop_ty);\r | |
336 | static PyTypeObject *Eq_type;\r | |
337 | static PyTypeObject *NotEq_type;\r | |
338 | static PyTypeObject *Lt_type;\r | |
339 | static PyTypeObject *LtE_type;\r | |
340 | static PyTypeObject *Gt_type;\r | |
341 | static PyTypeObject *GtE_type;\r | |
342 | static PyTypeObject *Is_type;\r | |
343 | static PyTypeObject *IsNot_type;\r | |
344 | static PyTypeObject *In_type;\r | |
345 | static PyTypeObject *NotIn_type;\r | |
346 | static PyTypeObject *comprehension_type;\r | |
347 | static PyObject* ast2obj_comprehension(void*);\r | |
348 | static char *comprehension_fields[]={\r | |
349 | "target",\r | |
350 | "iter",\r | |
351 | "ifs",\r | |
352 | };\r | |
353 | static PyTypeObject *excepthandler_type;\r | |
354 | static char *excepthandler_attributes[] = {\r | |
355 | "lineno",\r | |
356 | "col_offset",\r | |
357 | };\r | |
358 | static PyObject* ast2obj_excepthandler(void*);\r | |
359 | static PyTypeObject *ExceptHandler_type;\r | |
360 | static char *ExceptHandler_fields[]={\r | |
361 | "type",\r | |
362 | "name",\r | |
363 | "body",\r | |
364 | };\r | |
365 | static PyTypeObject *arguments_type;\r | |
366 | static PyObject* ast2obj_arguments(void*);\r | |
367 | static char *arguments_fields[]={\r | |
368 | "args",\r | |
369 | "vararg",\r | |
370 | "kwarg",\r | |
371 | "defaults",\r | |
372 | };\r | |
373 | static PyTypeObject *keyword_type;\r | |
374 | static PyObject* ast2obj_keyword(void*);\r | |
375 | static char *keyword_fields[]={\r | |
376 | "arg",\r | |
377 | "value",\r | |
378 | };\r | |
379 | static PyTypeObject *alias_type;\r | |
380 | static PyObject* ast2obj_alias(void*);\r | |
381 | static char *alias_fields[]={\r | |
382 | "name",\r | |
383 | "asname",\r | |
384 | };\r | |
385 | \r | |
386 | \r | |
387 | static int\r | |
388 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw)\r | |
389 | {\r | |
390 | Py_ssize_t i, numfields = 0;\r | |
391 | int res = -1;\r | |
392 | PyObject *key, *value, *fields;\r | |
393 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");\r | |
394 | if (!fields)\r | |
395 | PyErr_Clear();\r | |
396 | if (fields) {\r | |
397 | numfields = PySequence_Size(fields);\r | |
398 | if (numfields == -1)\r | |
399 | goto cleanup;\r | |
400 | }\r | |
401 | res = 0; /* if no error occurs, this stays 0 to the end */\r | |
402 | if (PyTuple_GET_SIZE(args) > 0) {\r | |
403 | if (numfields != PyTuple_GET_SIZE(args)) {\r | |
404 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"\r | |
405 | "%zd positional argument%s",\r | |
406 | Py_TYPE(self)->tp_name,\r | |
407 | numfields == 0 ? "" : "either 0 or ",\r | |
408 | numfields, numfields == 1 ? "" : "s");\r | |
409 | res = -1;\r | |
410 | goto cleanup;\r | |
411 | }\r | |
412 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) {\r | |
413 | /* cannot be reached when fields is NULL */\r | |
414 | PyObject *name = PySequence_GetItem(fields, i);\r | |
415 | if (!name) {\r | |
416 | res = -1;\r | |
417 | goto cleanup;\r | |
418 | }\r | |
419 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));\r | |
420 | Py_DECREF(name);\r | |
421 | if (res < 0)\r | |
422 | goto cleanup;\r | |
423 | }\r | |
424 | }\r | |
425 | if (kw) {\r | |
426 | i = 0; /* needed by PyDict_Next */\r | |
427 | while (PyDict_Next(kw, &i, &key, &value)) {\r | |
428 | res = PyObject_SetAttr(self, key, value);\r | |
429 | if (res < 0)\r | |
430 | goto cleanup;\r | |
431 | }\r | |
432 | }\r | |
433 | cleanup:\r | |
434 | Py_XDECREF(fields);\r | |
435 | return res;\r | |
436 | }\r | |
437 | \r | |
438 | /* Pickling support */\r | |
439 | static PyObject *\r | |
440 | ast_type_reduce(PyObject *self, PyObject *unused)\r | |
441 | {\r | |
442 | PyObject *res;\r | |
443 | PyObject *dict = PyObject_GetAttrString(self, "__dict__");\r | |
444 | if (dict == NULL) {\r | |
445 | if (PyErr_ExceptionMatches(PyExc_AttributeError))\r | |
446 | PyErr_Clear();\r | |
447 | else\r | |
448 | return NULL;\r | |
449 | }\r | |
450 | if (dict) {\r | |
451 | res = Py_BuildValue("O()O", Py_TYPE(self), dict);\r | |
452 | Py_DECREF(dict);\r | |
453 | return res;\r | |
454 | }\r | |
455 | return Py_BuildValue("O()", Py_TYPE(self));\r | |
456 | }\r | |
457 | \r | |
458 | static PyMethodDef ast_type_methods[] = {\r | |
459 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},\r | |
460 | {NULL}\r | |
461 | };\r | |
462 | \r | |
463 | static PyTypeObject AST_type = {\r | |
464 | PyVarObject_HEAD_INIT(&PyType_Type, 0)\r | |
465 | "_ast.AST",\r | |
466 | sizeof(PyObject),\r | |
467 | 0,\r | |
468 | 0, /* tp_dealloc */\r | |
469 | 0, /* tp_print */\r | |
470 | 0, /* tp_getattr */\r | |
471 | 0, /* tp_setattr */\r | |
472 | 0, /* tp_compare */\r | |
473 | 0, /* tp_repr */\r | |
474 | 0, /* tp_as_number */\r | |
475 | 0, /* tp_as_sequence */\r | |
476 | 0, /* tp_as_mapping */\r | |
477 | 0, /* tp_hash */\r | |
478 | 0, /* tp_call */\r | |
479 | 0, /* tp_str */\r | |
480 | PyObject_GenericGetAttr, /* tp_getattro */\r | |
481 | PyObject_GenericSetAttr, /* tp_setattro */\r | |
482 | 0, /* tp_as_buffer */\r | |
483 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */\r | |
484 | 0, /* tp_doc */\r | |
485 | 0, /* tp_traverse */\r | |
486 | 0, /* tp_clear */\r | |
487 | 0, /* tp_richcompare */\r | |
488 | 0, /* tp_weaklistoffset */\r | |
489 | 0, /* tp_iter */\r | |
490 | 0, /* tp_iternext */\r | |
491 | ast_type_methods, /* tp_methods */\r | |
492 | 0, /* tp_members */\r | |
493 | 0, /* tp_getset */\r | |
494 | 0, /* tp_base */\r | |
495 | 0, /* tp_dict */\r | |
496 | 0, /* tp_descr_get */\r | |
497 | 0, /* tp_descr_set */\r | |
498 | 0, /* tp_dictoffset */\r | |
499 | (initproc)ast_type_init, /* tp_init */\r | |
500 | PyType_GenericAlloc, /* tp_alloc */\r | |
501 | PyType_GenericNew, /* tp_new */\r | |
502 | PyObject_Del, /* tp_free */\r | |
503 | };\r | |
504 | \r | |
505 | \r | |
506 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)\r | |
507 | {\r | |
508 | PyObject *fnames, *result;\r | |
509 | int i;\r | |
510 | fnames = PyTuple_New(num_fields);\r | |
511 | if (!fnames) return NULL;\r | |
512 | for (i = 0; i < num_fields; i++) {\r | |
513 | PyObject *field = PyString_FromString(fields[i]);\r | |
514 | if (!field) {\r | |
515 | Py_DECREF(fnames);\r | |
516 | return NULL;\r | |
517 | }\r | |
518 | PyTuple_SET_ITEM(fnames, i, field);\r | |
519 | }\r | |
520 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",\r | |
521 | type, base, "_fields", fnames, "__module__", "_ast");\r | |
522 | Py_DECREF(fnames);\r | |
523 | return (PyTypeObject*)result;\r | |
524 | }\r | |
525 | \r | |
526 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)\r | |
527 | {\r | |
528 | int i, result;\r | |
529 | PyObject *s, *l = PyTuple_New(num_fields);\r | |
530 | if (!l)\r | |
531 | return 0;\r | |
532 | for (i = 0; i < num_fields; i++) {\r | |
533 | s = PyString_FromString(attrs[i]);\r | |
534 | if (!s) {\r | |
535 | Py_DECREF(l);\r | |
536 | return 0;\r | |
537 | }\r | |
538 | PyTuple_SET_ITEM(l, i, s);\r | |
539 | }\r | |
540 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;\r | |
541 | Py_DECREF(l);\r | |
542 | return result;\r | |
543 | }\r | |
544 | \r | |
545 | /* Conversion AST -> Python */\r | |
546 | \r | |
547 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))\r | |
548 | {\r | |
549 | int i, n = asdl_seq_LEN(seq);\r | |
550 | PyObject *result = PyList_New(n);\r | |
551 | PyObject *value;\r | |
552 | if (!result)\r | |
553 | return NULL;\r | |
554 | for (i = 0; i < n; i++) {\r | |
555 | value = func(asdl_seq_GET(seq, i));\r | |
556 | if (!value) {\r | |
557 | Py_DECREF(result);\r | |
558 | return NULL;\r | |
559 | }\r | |
560 | PyList_SET_ITEM(result, i, value);\r | |
561 | }\r | |
562 | return result;\r | |
563 | }\r | |
564 | \r | |
565 | static PyObject* ast2obj_object(void *o)\r | |
566 | {\r | |
567 | if (!o)\r | |
568 | o = Py_None;\r | |
569 | Py_INCREF((PyObject*)o);\r | |
570 | return (PyObject*)o;\r | |
571 | }\r | |
572 | #define ast2obj_identifier ast2obj_object\r | |
573 | #define ast2obj_string ast2obj_object\r | |
574 | static PyObject* ast2obj_bool(bool b)\r | |
575 | {\r | |
576 | return PyBool_FromLong(b);\r | |
577 | }\r | |
578 | \r | |
579 | static PyObject* ast2obj_int(long b)\r | |
580 | {\r | |
581 | return PyInt_FromLong(b);\r | |
582 | }\r | |
583 | \r | |
584 | /* Conversion Python -> AST */\r | |
585 | \r | |
586 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)\r | |
587 | {\r | |
588 | if (obj == Py_None)\r | |
589 | obj = NULL;\r | |
590 | if (obj)\r | |
591 | PyArena_AddPyObject(arena, obj);\r | |
592 | Py_XINCREF(obj);\r | |
593 | *out = obj;\r | |
594 | return 0;\r | |
595 | }\r | |
596 | \r | |
597 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)\r | |
598 | {\r | |
599 | if (!PyString_CheckExact(obj) && obj != Py_None) {\r | |
600 | PyErr_Format(PyExc_TypeError,\r | |
601 | "AST identifier must be of type str");\r | |
602 | return 1;\r | |
603 | }\r | |
604 | return obj2ast_object(obj, out, arena);\r | |
605 | }\r | |
606 | \r | |
607 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)\r | |
608 | {\r | |
609 | if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {\r | |
610 | PyErr_SetString(PyExc_TypeError,\r | |
611 | "AST string must be of type str or unicode");\r | |
612 | return 1;\r | |
613 | }\r | |
614 | return obj2ast_object(obj, out, arena);\r | |
615 | }\r | |
616 | \r | |
617 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)\r | |
618 | {\r | |
619 | int i;\r | |
620 | if (!PyInt_Check(obj) && !PyLong_Check(obj)) {\r | |
621 | PyObject *s = PyObject_Repr(obj);\r | |
622 | if (s == NULL) return 1;\r | |
623 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",\r | |
624 | PyString_AS_STRING(s));\r | |
625 | Py_DECREF(s);\r | |
626 | return 1;\r | |
627 | }\r | |
628 | \r | |
629 | i = (int)PyLong_AsLong(obj);\r | |
630 | if (i == -1 && PyErr_Occurred())\r | |
631 | return 1;\r | |
632 | *out = i;\r | |
633 | return 0;\r | |
634 | }\r | |
635 | \r | |
636 | static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)\r | |
637 | {\r | |
638 | if (!PyBool_Check(obj)) {\r | |
639 | PyObject *s = PyObject_Repr(obj);\r | |
640 | if (s == NULL) return 1;\r | |
641 | PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",\r | |
642 | PyString_AS_STRING(s));\r | |
643 | Py_DECREF(s);\r | |
644 | return 1;\r | |
645 | }\r | |
646 | \r | |
647 | *out = (obj == Py_True);\r | |
648 | return 0;\r | |
649 | }\r | |
650 | \r | |
651 | static int add_ast_fields(void)\r | |
652 | {\r | |
653 | PyObject *empty_tuple, *d;\r | |
654 | if (PyType_Ready(&AST_type) < 0)\r | |
655 | return -1;\r | |
656 | d = AST_type.tp_dict;\r | |
657 | empty_tuple = PyTuple_New(0);\r | |
658 | if (!empty_tuple ||\r | |
659 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||\r | |
660 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {\r | |
661 | Py_XDECREF(empty_tuple);\r | |
662 | return -1;\r | |
663 | }\r | |
664 | Py_DECREF(empty_tuple);\r | |
665 | return 0;\r | |
666 | }\r | |
667 | \r | |
668 | \r | |
669 | static int init_types(void)\r | |
670 | {\r | |
671 | static int initialized;\r | |
672 | if (initialized) return 1;\r | |
673 | if (add_ast_fields() < 0) return 0;\r | |
674 | mod_type = make_type("mod", &AST_type, NULL, 0);\r | |
675 | if (!mod_type) return 0;\r | |
676 | if (!add_attributes(mod_type, NULL, 0)) return 0;\r | |
677 | Module_type = make_type("Module", mod_type, Module_fields, 1);\r | |
678 | if (!Module_type) return 0;\r | |
679 | Interactive_type = make_type("Interactive", mod_type,\r | |
680 | Interactive_fields, 1);\r | |
681 | if (!Interactive_type) return 0;\r | |
682 | Expression_type = make_type("Expression", mod_type, Expression_fields,\r | |
683 | 1);\r | |
684 | if (!Expression_type) return 0;\r | |
685 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1);\r | |
686 | if (!Suite_type) return 0;\r | |
687 | stmt_type = make_type("stmt", &AST_type, NULL, 0);\r | |
688 | if (!stmt_type) return 0;\r | |
689 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;\r | |
690 | FunctionDef_type = make_type("FunctionDef", stmt_type,\r | |
691 | FunctionDef_fields, 4);\r | |
692 | if (!FunctionDef_type) return 0;\r | |
693 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);\r | |
694 | if (!ClassDef_type) return 0;\r | |
695 | Return_type = make_type("Return", stmt_type, Return_fields, 1);\r | |
696 | if (!Return_type) return 0;\r | |
697 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);\r | |
698 | if (!Delete_type) return 0;\r | |
699 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);\r | |
700 | if (!Assign_type) return 0;\r | |
701 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);\r | |
702 | if (!AugAssign_type) return 0;\r | |
703 | Print_type = make_type("Print", stmt_type, Print_fields, 3);\r | |
704 | if (!Print_type) return 0;\r | |
705 | For_type = make_type("For", stmt_type, For_fields, 4);\r | |
706 | if (!For_type) return 0;\r | |
707 | While_type = make_type("While", stmt_type, While_fields, 3);\r | |
708 | if (!While_type) return 0;\r | |
709 | If_type = make_type("If", stmt_type, If_fields, 3);\r | |
710 | if (!If_type) return 0;\r | |
711 | With_type = make_type("With", stmt_type, With_fields, 3);\r | |
712 | if (!With_type) return 0;\r | |
713 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);\r | |
714 | if (!Raise_type) return 0;\r | |
715 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);\r | |
716 | if (!TryExcept_type) return 0;\r | |
717 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,\r | |
718 | 2);\r | |
719 | if (!TryFinally_type) return 0;\r | |
720 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);\r | |
721 | if (!Assert_type) return 0;\r | |
722 | Import_type = make_type("Import", stmt_type, Import_fields, 1);\r | |
723 | if (!Import_type) return 0;\r | |
724 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,\r | |
725 | 3);\r | |
726 | if (!ImportFrom_type) return 0;\r | |
727 | Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);\r | |
728 | if (!Exec_type) return 0;\r | |
729 | Global_type = make_type("Global", stmt_type, Global_fields, 1);\r | |
730 | if (!Global_type) return 0;\r | |
731 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);\r | |
732 | if (!Expr_type) return 0;\r | |
733 | Pass_type = make_type("Pass", stmt_type, NULL, 0);\r | |
734 | if (!Pass_type) return 0;\r | |
735 | Break_type = make_type("Break", stmt_type, NULL, 0);\r | |
736 | if (!Break_type) return 0;\r | |
737 | Continue_type = make_type("Continue", stmt_type, NULL, 0);\r | |
738 | if (!Continue_type) return 0;\r | |
739 | expr_type = make_type("expr", &AST_type, NULL, 0);\r | |
740 | if (!expr_type) return 0;\r | |
741 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0;\r | |
742 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);\r | |
743 | if (!BoolOp_type) return 0;\r | |
744 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);\r | |
745 | if (!BinOp_type) return 0;\r | |
746 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);\r | |
747 | if (!UnaryOp_type) return 0;\r | |
748 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);\r | |
749 | if (!Lambda_type) return 0;\r | |
750 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);\r | |
751 | if (!IfExp_type) return 0;\r | |
752 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2);\r | |
753 | if (!Dict_type) return 0;\r | |
754 | Set_type = make_type("Set", expr_type, Set_fields, 1);\r | |
755 | if (!Set_type) return 0;\r | |
756 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);\r | |
757 | if (!ListComp_type) return 0;\r | |
758 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);\r | |
759 | if (!SetComp_type) return 0;\r | |
760 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);\r | |
761 | if (!DictComp_type) return 0;\r | |
762 | GeneratorExp_type = make_type("GeneratorExp", expr_type,\r | |
763 | GeneratorExp_fields, 2);\r | |
764 | if (!GeneratorExp_type) return 0;\r | |
765 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1);\r | |
766 | if (!Yield_type) return 0;\r | |
767 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3);\r | |
768 | if (!Compare_type) return 0;\r | |
769 | Call_type = make_type("Call", expr_type, Call_fields, 5);\r | |
770 | if (!Call_type) return 0;\r | |
771 | Repr_type = make_type("Repr", expr_type, Repr_fields, 1);\r | |
772 | if (!Repr_type) return 0;\r | |
773 | Num_type = make_type("Num", expr_type, Num_fields, 1);\r | |
774 | if (!Num_type) return 0;\r | |
775 | Str_type = make_type("Str", expr_type, Str_fields, 1);\r | |
776 | if (!Str_type) return 0;\r | |
777 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);\r | |
778 | if (!Attribute_type) return 0;\r | |
779 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);\r | |
780 | if (!Subscript_type) return 0;\r | |
781 | Name_type = make_type("Name", expr_type, Name_fields, 2);\r | |
782 | if (!Name_type) return 0;\r | |
783 | List_type = make_type("List", expr_type, List_fields, 2);\r | |
784 | if (!List_type) return 0;\r | |
785 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);\r | |
786 | if (!Tuple_type) return 0;\r | |
787 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0);\r | |
788 | if (!expr_context_type) return 0;\r | |
789 | if (!add_attributes(expr_context_type, NULL, 0)) return 0;\r | |
790 | Load_type = make_type("Load", expr_context_type, NULL, 0);\r | |
791 | if (!Load_type) return 0;\r | |
792 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);\r | |
793 | if (!Load_singleton) return 0;\r | |
794 | Store_type = make_type("Store", expr_context_type, NULL, 0);\r | |
795 | if (!Store_type) return 0;\r | |
796 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);\r | |
797 | if (!Store_singleton) return 0;\r | |
798 | Del_type = make_type("Del", expr_context_type, NULL, 0);\r | |
799 | if (!Del_type) return 0;\r | |
800 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);\r | |
801 | if (!Del_singleton) return 0;\r | |
802 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);\r | |
803 | if (!AugLoad_type) return 0;\r | |
804 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);\r | |
805 | if (!AugLoad_singleton) return 0;\r | |
806 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);\r | |
807 | if (!AugStore_type) return 0;\r | |
808 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);\r | |
809 | if (!AugStore_singleton) return 0;\r | |
810 | Param_type = make_type("Param", expr_context_type, NULL, 0);\r | |
811 | if (!Param_type) return 0;\r | |
812 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);\r | |
813 | if (!Param_singleton) return 0;\r | |
814 | slice_type = make_type("slice", &AST_type, NULL, 0);\r | |
815 | if (!slice_type) return 0;\r | |
816 | if (!add_attributes(slice_type, NULL, 0)) return 0;\r | |
817 | Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);\r | |
818 | if (!Ellipsis_type) return 0;\r | |
819 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3);\r | |
820 | if (!Slice_type) return 0;\r | |
821 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);\r | |
822 | if (!ExtSlice_type) return 0;\r | |
823 | Index_type = make_type("Index", slice_type, Index_fields, 1);\r | |
824 | if (!Index_type) return 0;\r | |
825 | boolop_type = make_type("boolop", &AST_type, NULL, 0);\r | |
826 | if (!boolop_type) return 0;\r | |
827 | if (!add_attributes(boolop_type, NULL, 0)) return 0;\r | |
828 | And_type = make_type("And", boolop_type, NULL, 0);\r | |
829 | if (!And_type) return 0;\r | |
830 | And_singleton = PyType_GenericNew(And_type, NULL, NULL);\r | |
831 | if (!And_singleton) return 0;\r | |
832 | Or_type = make_type("Or", boolop_type, NULL, 0);\r | |
833 | if (!Or_type) return 0;\r | |
834 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);\r | |
835 | if (!Or_singleton) return 0;\r | |
836 | operator_type = make_type("operator", &AST_type, NULL, 0);\r | |
837 | if (!operator_type) return 0;\r | |
838 | if (!add_attributes(operator_type, NULL, 0)) return 0;\r | |
839 | Add_type = make_type("Add", operator_type, NULL, 0);\r | |
840 | if (!Add_type) return 0;\r | |
841 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);\r | |
842 | if (!Add_singleton) return 0;\r | |
843 | Sub_type = make_type("Sub", operator_type, NULL, 0);\r | |
844 | if (!Sub_type) return 0;\r | |
845 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);\r | |
846 | if (!Sub_singleton) return 0;\r | |
847 | Mult_type = make_type("Mult", operator_type, NULL, 0);\r | |
848 | if (!Mult_type) return 0;\r | |
849 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);\r | |
850 | if (!Mult_singleton) return 0;\r | |
851 | Div_type = make_type("Div", operator_type, NULL, 0);\r | |
852 | if (!Div_type) return 0;\r | |
853 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);\r | |
854 | if (!Div_singleton) return 0;\r | |
855 | Mod_type = make_type("Mod", operator_type, NULL, 0);\r | |
856 | if (!Mod_type) return 0;\r | |
857 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);\r | |
858 | if (!Mod_singleton) return 0;\r | |
859 | Pow_type = make_type("Pow", operator_type, NULL, 0);\r | |
860 | if (!Pow_type) return 0;\r | |
861 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);\r | |
862 | if (!Pow_singleton) return 0;\r | |
863 | LShift_type = make_type("LShift", operator_type, NULL, 0);\r | |
864 | if (!LShift_type) return 0;\r | |
865 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);\r | |
866 | if (!LShift_singleton) return 0;\r | |
867 | RShift_type = make_type("RShift", operator_type, NULL, 0);\r | |
868 | if (!RShift_type) return 0;\r | |
869 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);\r | |
870 | if (!RShift_singleton) return 0;\r | |
871 | BitOr_type = make_type("BitOr", operator_type, NULL, 0);\r | |
872 | if (!BitOr_type) return 0;\r | |
873 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);\r | |
874 | if (!BitOr_singleton) return 0;\r | |
875 | BitXor_type = make_type("BitXor", operator_type, NULL, 0);\r | |
876 | if (!BitXor_type) return 0;\r | |
877 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);\r | |
878 | if (!BitXor_singleton) return 0;\r | |
879 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);\r | |
880 | if (!BitAnd_type) return 0;\r | |
881 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);\r | |
882 | if (!BitAnd_singleton) return 0;\r | |
883 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);\r | |
884 | if (!FloorDiv_type) return 0;\r | |
885 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);\r | |
886 | if (!FloorDiv_singleton) return 0;\r | |
887 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0);\r | |
888 | if (!unaryop_type) return 0;\r | |
889 | if (!add_attributes(unaryop_type, NULL, 0)) return 0;\r | |
890 | Invert_type = make_type("Invert", unaryop_type, NULL, 0);\r | |
891 | if (!Invert_type) return 0;\r | |
892 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);\r | |
893 | if (!Invert_singleton) return 0;\r | |
894 | Not_type = make_type("Not", unaryop_type, NULL, 0);\r | |
895 | if (!Not_type) return 0;\r | |
896 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);\r | |
897 | if (!Not_singleton) return 0;\r | |
898 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);\r | |
899 | if (!UAdd_type) return 0;\r | |
900 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);\r | |
901 | if (!UAdd_singleton) return 0;\r | |
902 | USub_type = make_type("USub", unaryop_type, NULL, 0);\r | |
903 | if (!USub_type) return 0;\r | |
904 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);\r | |
905 | if (!USub_singleton) return 0;\r | |
906 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0);\r | |
907 | if (!cmpop_type) return 0;\r | |
908 | if (!add_attributes(cmpop_type, NULL, 0)) return 0;\r | |
909 | Eq_type = make_type("Eq", cmpop_type, NULL, 0);\r | |
910 | if (!Eq_type) return 0;\r | |
911 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);\r | |
912 | if (!Eq_singleton) return 0;\r | |
913 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);\r | |
914 | if (!NotEq_type) return 0;\r | |
915 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);\r | |
916 | if (!NotEq_singleton) return 0;\r | |
917 | Lt_type = make_type("Lt", cmpop_type, NULL, 0);\r | |
918 | if (!Lt_type) return 0;\r | |
919 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);\r | |
920 | if (!Lt_singleton) return 0;\r | |
921 | LtE_type = make_type("LtE", cmpop_type, NULL, 0);\r | |
922 | if (!LtE_type) return 0;\r | |
923 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);\r | |
924 | if (!LtE_singleton) return 0;\r | |
925 | Gt_type = make_type("Gt", cmpop_type, NULL, 0);\r | |
926 | if (!Gt_type) return 0;\r | |
927 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);\r | |
928 | if (!Gt_singleton) return 0;\r | |
929 | GtE_type = make_type("GtE", cmpop_type, NULL, 0);\r | |
930 | if (!GtE_type) return 0;\r | |
931 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);\r | |
932 | if (!GtE_singleton) return 0;\r | |
933 | Is_type = make_type("Is", cmpop_type, NULL, 0);\r | |
934 | if (!Is_type) return 0;\r | |
935 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);\r | |
936 | if (!Is_singleton) return 0;\r | |
937 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);\r | |
938 | if (!IsNot_type) return 0;\r | |
939 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);\r | |
940 | if (!IsNot_singleton) return 0;\r | |
941 | In_type = make_type("In", cmpop_type, NULL, 0);\r | |
942 | if (!In_type) return 0;\r | |
943 | In_singleton = PyType_GenericNew(In_type, NULL, NULL);\r | |
944 | if (!In_singleton) return 0;\r | |
945 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);\r | |
946 | if (!NotIn_type) return 0;\r | |
947 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);\r | |
948 | if (!NotIn_singleton) return 0;\r | |
949 | comprehension_type = make_type("comprehension", &AST_type,\r | |
950 | comprehension_fields, 3);\r | |
951 | if (!comprehension_type) return 0;\r | |
952 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);\r | |
953 | if (!excepthandler_type) return 0;\r | |
954 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))\r | |
955 | return 0;\r | |
956 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,\r | |
957 | ExceptHandler_fields, 3);\r | |
958 | if (!ExceptHandler_type) return 0;\r | |
959 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);\r | |
960 | if (!arguments_type) return 0;\r | |
961 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);\r | |
962 | if (!keyword_type) return 0;\r | |
963 | alias_type = make_type("alias", &AST_type, alias_fields, 2);\r | |
964 | if (!alias_type) return 0;\r | |
965 | initialized = 1;\r | |
966 | return 1;\r | |
967 | }\r | |
968 | \r | |
969 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);\r | |
970 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);\r | |
971 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);\r | |
972 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*\r | |
973 | arena);\r | |
974 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);\r | |
975 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);\r | |
976 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);\r | |
977 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);\r | |
978 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);\r | |
979 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*\r | |
980 | arena);\r | |
981 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*\r | |
982 | arena);\r | |
983 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);\r | |
984 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);\r | |
985 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);\r | |
986 | \r | |
987 | mod_ty\r | |
988 | Module(asdl_seq * body, PyArena *arena)\r | |
989 | {\r | |
990 | mod_ty p;\r | |
991 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
992 | if (!p)\r | |
993 | return NULL;\r | |
994 | p->kind = Module_kind;\r | |
995 | p->v.Module.body = body;\r | |
996 | return p;\r | |
997 | }\r | |
998 | \r | |
999 | mod_ty\r | |
1000 | Interactive(asdl_seq * body, PyArena *arena)\r | |
1001 | {\r | |
1002 | mod_ty p;\r | |
1003 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1004 | if (!p)\r | |
1005 | return NULL;\r | |
1006 | p->kind = Interactive_kind;\r | |
1007 | p->v.Interactive.body = body;\r | |
1008 | return p;\r | |
1009 | }\r | |
1010 | \r | |
1011 | mod_ty\r | |
1012 | Expression(expr_ty body, PyArena *arena)\r | |
1013 | {\r | |
1014 | mod_ty p;\r | |
1015 | if (!body) {\r | |
1016 | PyErr_SetString(PyExc_ValueError,\r | |
1017 | "field body is required for Expression");\r | |
1018 | return NULL;\r | |
1019 | }\r | |
1020 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1021 | if (!p)\r | |
1022 | return NULL;\r | |
1023 | p->kind = Expression_kind;\r | |
1024 | p->v.Expression.body = body;\r | |
1025 | return p;\r | |
1026 | }\r | |
1027 | \r | |
1028 | mod_ty\r | |
1029 | Suite(asdl_seq * body, PyArena *arena)\r | |
1030 | {\r | |
1031 | mod_ty p;\r | |
1032 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1033 | if (!p)\r | |
1034 | return NULL;\r | |
1035 | p->kind = Suite_kind;\r | |
1036 | p->v.Suite.body = body;\r | |
1037 | return p;\r | |
1038 | }\r | |
1039 | \r | |
1040 | stmt_ty\r | |
1041 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *\r | |
1042 | decorator_list, int lineno, int col_offset, PyArena *arena)\r | |
1043 | {\r | |
1044 | stmt_ty p;\r | |
1045 | if (!name) {\r | |
1046 | PyErr_SetString(PyExc_ValueError,\r | |
1047 | "field name is required for FunctionDef");\r | |
1048 | return NULL;\r | |
1049 | }\r | |
1050 | if (!args) {\r | |
1051 | PyErr_SetString(PyExc_ValueError,\r | |
1052 | "field args is required for FunctionDef");\r | |
1053 | return NULL;\r | |
1054 | }\r | |
1055 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1056 | if (!p)\r | |
1057 | return NULL;\r | |
1058 | p->kind = FunctionDef_kind;\r | |
1059 | p->v.FunctionDef.name = name;\r | |
1060 | p->v.FunctionDef.args = args;\r | |
1061 | p->v.FunctionDef.body = body;\r | |
1062 | p->v.FunctionDef.decorator_list = decorator_list;\r | |
1063 | p->lineno = lineno;\r | |
1064 | p->col_offset = col_offset;\r | |
1065 | return p;\r | |
1066 | }\r | |
1067 | \r | |
1068 | stmt_ty\r | |
1069 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *\r | |
1070 | decorator_list, int lineno, int col_offset, PyArena *arena)\r | |
1071 | {\r | |
1072 | stmt_ty p;\r | |
1073 | if (!name) {\r | |
1074 | PyErr_SetString(PyExc_ValueError,\r | |
1075 | "field name is required for ClassDef");\r | |
1076 | return NULL;\r | |
1077 | }\r | |
1078 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1079 | if (!p)\r | |
1080 | return NULL;\r | |
1081 | p->kind = ClassDef_kind;\r | |
1082 | p->v.ClassDef.name = name;\r | |
1083 | p->v.ClassDef.bases = bases;\r | |
1084 | p->v.ClassDef.body = body;\r | |
1085 | p->v.ClassDef.decorator_list = decorator_list;\r | |
1086 | p->lineno = lineno;\r | |
1087 | p->col_offset = col_offset;\r | |
1088 | return p;\r | |
1089 | }\r | |
1090 | \r | |
1091 | stmt_ty\r | |
1092 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena)\r | |
1093 | {\r | |
1094 | stmt_ty p;\r | |
1095 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1096 | if (!p)\r | |
1097 | return NULL;\r | |
1098 | p->kind = Return_kind;\r | |
1099 | p->v.Return.value = value;\r | |
1100 | p->lineno = lineno;\r | |
1101 | p->col_offset = col_offset;\r | |
1102 | return p;\r | |
1103 | }\r | |
1104 | \r | |
1105 | stmt_ty\r | |
1106 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)\r | |
1107 | {\r | |
1108 | stmt_ty p;\r | |
1109 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1110 | if (!p)\r | |
1111 | return NULL;\r | |
1112 | p->kind = Delete_kind;\r | |
1113 | p->v.Delete.targets = targets;\r | |
1114 | p->lineno = lineno;\r | |
1115 | p->col_offset = col_offset;\r | |
1116 | return p;\r | |
1117 | }\r | |
1118 | \r | |
1119 | stmt_ty\r | |
1120 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena\r | |
1121 | *arena)\r | |
1122 | {\r | |
1123 | stmt_ty p;\r | |
1124 | if (!value) {\r | |
1125 | PyErr_SetString(PyExc_ValueError,\r | |
1126 | "field value is required for Assign");\r | |
1127 | return NULL;\r | |
1128 | }\r | |
1129 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1130 | if (!p)\r | |
1131 | return NULL;\r | |
1132 | p->kind = Assign_kind;\r | |
1133 | p->v.Assign.targets = targets;\r | |
1134 | p->v.Assign.value = value;\r | |
1135 | p->lineno = lineno;\r | |
1136 | p->col_offset = col_offset;\r | |
1137 | return p;\r | |
1138 | }\r | |
1139 | \r | |
1140 | stmt_ty\r | |
1141 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int\r | |
1142 | col_offset, PyArena *arena)\r | |
1143 | {\r | |
1144 | stmt_ty p;\r | |
1145 | if (!target) {\r | |
1146 | PyErr_SetString(PyExc_ValueError,\r | |
1147 | "field target is required for AugAssign");\r | |
1148 | return NULL;\r | |
1149 | }\r | |
1150 | if (!op) {\r | |
1151 | PyErr_SetString(PyExc_ValueError,\r | |
1152 | "field op is required for AugAssign");\r | |
1153 | return NULL;\r | |
1154 | }\r | |
1155 | if (!value) {\r | |
1156 | PyErr_SetString(PyExc_ValueError,\r | |
1157 | "field value is required for AugAssign");\r | |
1158 | return NULL;\r | |
1159 | }\r | |
1160 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1161 | if (!p)\r | |
1162 | return NULL;\r | |
1163 | p->kind = AugAssign_kind;\r | |
1164 | p->v.AugAssign.target = target;\r | |
1165 | p->v.AugAssign.op = op;\r | |
1166 | p->v.AugAssign.value = value;\r | |
1167 | p->lineno = lineno;\r | |
1168 | p->col_offset = col_offset;\r | |
1169 | return p;\r | |
1170 | }\r | |
1171 | \r | |
1172 | stmt_ty\r | |
1173 | Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,\r | |
1174 | PyArena *arena)\r | |
1175 | {\r | |
1176 | stmt_ty p;\r | |
1177 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1178 | if (!p)\r | |
1179 | return NULL;\r | |
1180 | p->kind = Print_kind;\r | |
1181 | p->v.Print.dest = dest;\r | |
1182 | p->v.Print.values = values;\r | |
1183 | p->v.Print.nl = nl;\r | |
1184 | p->lineno = lineno;\r | |
1185 | p->col_offset = col_offset;\r | |
1186 | return p;\r | |
1187 | }\r | |
1188 | \r | |
1189 | stmt_ty\r | |
1190 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int\r | |
1191 | lineno, int col_offset, PyArena *arena)\r | |
1192 | {\r | |
1193 | stmt_ty p;\r | |
1194 | if (!target) {\r | |
1195 | PyErr_SetString(PyExc_ValueError,\r | |
1196 | "field target is required for For");\r | |
1197 | return NULL;\r | |
1198 | }\r | |
1199 | if (!iter) {\r | |
1200 | PyErr_SetString(PyExc_ValueError,\r | |
1201 | "field iter is required for For");\r | |
1202 | return NULL;\r | |
1203 | }\r | |
1204 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1205 | if (!p)\r | |
1206 | return NULL;\r | |
1207 | p->kind = For_kind;\r | |
1208 | p->v.For.target = target;\r | |
1209 | p->v.For.iter = iter;\r | |
1210 | p->v.For.body = body;\r | |
1211 | p->v.For.orelse = orelse;\r | |
1212 | p->lineno = lineno;\r | |
1213 | p->col_offset = col_offset;\r | |
1214 | return p;\r | |
1215 | }\r | |
1216 | \r | |
1217 | stmt_ty\r | |
1218 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r | |
1219 | col_offset, PyArena *arena)\r | |
1220 | {\r | |
1221 | stmt_ty p;\r | |
1222 | if (!test) {\r | |
1223 | PyErr_SetString(PyExc_ValueError,\r | |
1224 | "field test is required for While");\r | |
1225 | return NULL;\r | |
1226 | }\r | |
1227 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1228 | if (!p)\r | |
1229 | return NULL;\r | |
1230 | p->kind = While_kind;\r | |
1231 | p->v.While.test = test;\r | |
1232 | p->v.While.body = body;\r | |
1233 | p->v.While.orelse = orelse;\r | |
1234 | p->lineno = lineno;\r | |
1235 | p->col_offset = col_offset;\r | |
1236 | return p;\r | |
1237 | }\r | |
1238 | \r | |
1239 | stmt_ty\r | |
1240 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r | |
1241 | col_offset, PyArena *arena)\r | |
1242 | {\r | |
1243 | stmt_ty p;\r | |
1244 | if (!test) {\r | |
1245 | PyErr_SetString(PyExc_ValueError,\r | |
1246 | "field test is required for If");\r | |
1247 | return NULL;\r | |
1248 | }\r | |
1249 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1250 | if (!p)\r | |
1251 | return NULL;\r | |
1252 | p->kind = If_kind;\r | |
1253 | p->v.If.test = test;\r | |
1254 | p->v.If.body = body;\r | |
1255 | p->v.If.orelse = orelse;\r | |
1256 | p->lineno = lineno;\r | |
1257 | p->col_offset = col_offset;\r | |
1258 | return p;\r | |
1259 | }\r | |
1260 | \r | |
1261 | stmt_ty\r | |
1262 | With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,\r | |
1263 | int col_offset, PyArena *arena)\r | |
1264 | {\r | |
1265 | stmt_ty p;\r | |
1266 | if (!context_expr) {\r | |
1267 | PyErr_SetString(PyExc_ValueError,\r | |
1268 | "field context_expr is required for With");\r | |
1269 | return NULL;\r | |
1270 | }\r | |
1271 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1272 | if (!p)\r | |
1273 | return NULL;\r | |
1274 | p->kind = With_kind;\r | |
1275 | p->v.With.context_expr = context_expr;\r | |
1276 | p->v.With.optional_vars = optional_vars;\r | |
1277 | p->v.With.body = body;\r | |
1278 | p->lineno = lineno;\r | |
1279 | p->col_offset = col_offset;\r | |
1280 | return p;\r | |
1281 | }\r | |
1282 | \r | |
1283 | stmt_ty\r | |
1284 | Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,\r | |
1285 | PyArena *arena)\r | |
1286 | {\r | |
1287 | stmt_ty p;\r | |
1288 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1289 | if (!p)\r | |
1290 | return NULL;\r | |
1291 | p->kind = Raise_kind;\r | |
1292 | p->v.Raise.type = type;\r | |
1293 | p->v.Raise.inst = inst;\r | |
1294 | p->v.Raise.tback = tback;\r | |
1295 | p->lineno = lineno;\r | |
1296 | p->col_offset = col_offset;\r | |
1297 | return p;\r | |
1298 | }\r | |
1299 | \r | |
1300 | stmt_ty\r | |
1301 | TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,\r | |
1302 | int col_offset, PyArena *arena)\r | |
1303 | {\r | |
1304 | stmt_ty p;\r | |
1305 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1306 | if (!p)\r | |
1307 | return NULL;\r | |
1308 | p->kind = TryExcept_kind;\r | |
1309 | p->v.TryExcept.body = body;\r | |
1310 | p->v.TryExcept.handlers = handlers;\r | |
1311 | p->v.TryExcept.orelse = orelse;\r | |
1312 | p->lineno = lineno;\r | |
1313 | p->col_offset = col_offset;\r | |
1314 | return p;\r | |
1315 | }\r | |
1316 | \r | |
1317 | stmt_ty\r | |
1318 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,\r | |
1319 | PyArena *arena)\r | |
1320 | {\r | |
1321 | stmt_ty p;\r | |
1322 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1323 | if (!p)\r | |
1324 | return NULL;\r | |
1325 | p->kind = TryFinally_kind;\r | |
1326 | p->v.TryFinally.body = body;\r | |
1327 | p->v.TryFinally.finalbody = finalbody;\r | |
1328 | p->lineno = lineno;\r | |
1329 | p->col_offset = col_offset;\r | |
1330 | return p;\r | |
1331 | }\r | |
1332 | \r | |
1333 | stmt_ty\r | |
1334 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)\r | |
1335 | {\r | |
1336 | stmt_ty p;\r | |
1337 | if (!test) {\r | |
1338 | PyErr_SetString(PyExc_ValueError,\r | |
1339 | "field test is required for Assert");\r | |
1340 | return NULL;\r | |
1341 | }\r | |
1342 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1343 | if (!p)\r | |
1344 | return NULL;\r | |
1345 | p->kind = Assert_kind;\r | |
1346 | p->v.Assert.test = test;\r | |
1347 | p->v.Assert.msg = msg;\r | |
1348 | p->lineno = lineno;\r | |
1349 | p->col_offset = col_offset;\r | |
1350 | return p;\r | |
1351 | }\r | |
1352 | \r | |
1353 | stmt_ty\r | |
1354 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r | |
1355 | {\r | |
1356 | stmt_ty p;\r | |
1357 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1358 | if (!p)\r | |
1359 | return NULL;\r | |
1360 | p->kind = Import_kind;\r | |
1361 | p->v.Import.names = names;\r | |
1362 | p->lineno = lineno;\r | |
1363 | p->col_offset = col_offset;\r | |
1364 | return p;\r | |
1365 | }\r | |
1366 | \r | |
1367 | stmt_ty\r | |
1368 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int\r | |
1369 | col_offset, PyArena *arena)\r | |
1370 | {\r | |
1371 | stmt_ty p;\r | |
1372 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1373 | if (!p)\r | |
1374 | return NULL;\r | |
1375 | p->kind = ImportFrom_kind;\r | |
1376 | p->v.ImportFrom.module = module;\r | |
1377 | p->v.ImportFrom.names = names;\r | |
1378 | p->v.ImportFrom.level = level;\r | |
1379 | p->lineno = lineno;\r | |
1380 | p->col_offset = col_offset;\r | |
1381 | return p;\r | |
1382 | }\r | |
1383 | \r | |
1384 | stmt_ty\r | |
1385 | Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,\r | |
1386 | PyArena *arena)\r | |
1387 | {\r | |
1388 | stmt_ty p;\r | |
1389 | if (!body) {\r | |
1390 | PyErr_SetString(PyExc_ValueError,\r | |
1391 | "field body is required for Exec");\r | |
1392 | return NULL;\r | |
1393 | }\r | |
1394 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1395 | if (!p)\r | |
1396 | return NULL;\r | |
1397 | p->kind = Exec_kind;\r | |
1398 | p->v.Exec.body = body;\r | |
1399 | p->v.Exec.globals = globals;\r | |
1400 | p->v.Exec.locals = locals;\r | |
1401 | p->lineno = lineno;\r | |
1402 | p->col_offset = col_offset;\r | |
1403 | return p;\r | |
1404 | }\r | |
1405 | \r | |
1406 | stmt_ty\r | |
1407 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r | |
1408 | {\r | |
1409 | stmt_ty p;\r | |
1410 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1411 | if (!p)\r | |
1412 | return NULL;\r | |
1413 | p->kind = Global_kind;\r | |
1414 | p->v.Global.names = names;\r | |
1415 | p->lineno = lineno;\r | |
1416 | p->col_offset = col_offset;\r | |
1417 | return p;\r | |
1418 | }\r | |
1419 | \r | |
1420 | stmt_ty\r | |
1421 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r | |
1422 | {\r | |
1423 | stmt_ty p;\r | |
1424 | if (!value) {\r | |
1425 | PyErr_SetString(PyExc_ValueError,\r | |
1426 | "field value is required for Expr");\r | |
1427 | return NULL;\r | |
1428 | }\r | |
1429 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1430 | if (!p)\r | |
1431 | return NULL;\r | |
1432 | p->kind = Expr_kind;\r | |
1433 | p->v.Expr.value = value;\r | |
1434 | p->lineno = lineno;\r | |
1435 | p->col_offset = col_offset;\r | |
1436 | return p;\r | |
1437 | }\r | |
1438 | \r | |
1439 | stmt_ty\r | |
1440 | Pass(int lineno, int col_offset, PyArena *arena)\r | |
1441 | {\r | |
1442 | stmt_ty p;\r | |
1443 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1444 | if (!p)\r | |
1445 | return NULL;\r | |
1446 | p->kind = Pass_kind;\r | |
1447 | p->lineno = lineno;\r | |
1448 | p->col_offset = col_offset;\r | |
1449 | return p;\r | |
1450 | }\r | |
1451 | \r | |
1452 | stmt_ty\r | |
1453 | Break(int lineno, int col_offset, PyArena *arena)\r | |
1454 | {\r | |
1455 | stmt_ty p;\r | |
1456 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1457 | if (!p)\r | |
1458 | return NULL;\r | |
1459 | p->kind = Break_kind;\r | |
1460 | p->lineno = lineno;\r | |
1461 | p->col_offset = col_offset;\r | |
1462 | return p;\r | |
1463 | }\r | |
1464 | \r | |
1465 | stmt_ty\r | |
1466 | Continue(int lineno, int col_offset, PyArena *arena)\r | |
1467 | {\r | |
1468 | stmt_ty p;\r | |
1469 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1470 | if (!p)\r | |
1471 | return NULL;\r | |
1472 | p->kind = Continue_kind;\r | |
1473 | p->lineno = lineno;\r | |
1474 | p->col_offset = col_offset;\r | |
1475 | return p;\r | |
1476 | }\r | |
1477 | \r | |
1478 | expr_ty\r | |
1479 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena\r | |
1480 | *arena)\r | |
1481 | {\r | |
1482 | expr_ty p;\r | |
1483 | if (!op) {\r | |
1484 | PyErr_SetString(PyExc_ValueError,\r | |
1485 | "field op is required for BoolOp");\r | |
1486 | return NULL;\r | |
1487 | }\r | |
1488 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1489 | if (!p)\r | |
1490 | return NULL;\r | |
1491 | p->kind = BoolOp_kind;\r | |
1492 | p->v.BoolOp.op = op;\r | |
1493 | p->v.BoolOp.values = values;\r | |
1494 | p->lineno = lineno;\r | |
1495 | p->col_offset = col_offset;\r | |
1496 | return p;\r | |
1497 | }\r | |
1498 | \r | |
1499 | expr_ty\r | |
1500 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,\r | |
1501 | PyArena *arena)\r | |
1502 | {\r | |
1503 | expr_ty p;\r | |
1504 | if (!left) {\r | |
1505 | PyErr_SetString(PyExc_ValueError,\r | |
1506 | "field left is required for BinOp");\r | |
1507 | return NULL;\r | |
1508 | }\r | |
1509 | if (!op) {\r | |
1510 | PyErr_SetString(PyExc_ValueError,\r | |
1511 | "field op is required for BinOp");\r | |
1512 | return NULL;\r | |
1513 | }\r | |
1514 | if (!right) {\r | |
1515 | PyErr_SetString(PyExc_ValueError,\r | |
1516 | "field right is required for BinOp");\r | |
1517 | return NULL;\r | |
1518 | }\r | |
1519 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1520 | if (!p)\r | |
1521 | return NULL;\r | |
1522 | p->kind = BinOp_kind;\r | |
1523 | p->v.BinOp.left = left;\r | |
1524 | p->v.BinOp.op = op;\r | |
1525 | p->v.BinOp.right = right;\r | |
1526 | p->lineno = lineno;\r | |
1527 | p->col_offset = col_offset;\r | |
1528 | return p;\r | |
1529 | }\r | |
1530 | \r | |
1531 | expr_ty\r | |
1532 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena\r | |
1533 | *arena)\r | |
1534 | {\r | |
1535 | expr_ty p;\r | |
1536 | if (!op) {\r | |
1537 | PyErr_SetString(PyExc_ValueError,\r | |
1538 | "field op is required for UnaryOp");\r | |
1539 | return NULL;\r | |
1540 | }\r | |
1541 | if (!operand) {\r | |
1542 | PyErr_SetString(PyExc_ValueError,\r | |
1543 | "field operand is required for UnaryOp");\r | |
1544 | return NULL;\r | |
1545 | }\r | |
1546 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1547 | if (!p)\r | |
1548 | return NULL;\r | |
1549 | p->kind = UnaryOp_kind;\r | |
1550 | p->v.UnaryOp.op = op;\r | |
1551 | p->v.UnaryOp.operand = operand;\r | |
1552 | p->lineno = lineno;\r | |
1553 | p->col_offset = col_offset;\r | |
1554 | return p;\r | |
1555 | }\r | |
1556 | \r | |
1557 | expr_ty\r | |
1558 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena\r | |
1559 | *arena)\r | |
1560 | {\r | |
1561 | expr_ty p;\r | |
1562 | if (!args) {\r | |
1563 | PyErr_SetString(PyExc_ValueError,\r | |
1564 | "field args is required for Lambda");\r | |
1565 | return NULL;\r | |
1566 | }\r | |
1567 | if (!body) {\r | |
1568 | PyErr_SetString(PyExc_ValueError,\r | |
1569 | "field body is required for Lambda");\r | |
1570 | return NULL;\r | |
1571 | }\r | |
1572 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1573 | if (!p)\r | |
1574 | return NULL;\r | |
1575 | p->kind = Lambda_kind;\r | |
1576 | p->v.Lambda.args = args;\r | |
1577 | p->v.Lambda.body = body;\r | |
1578 | p->lineno = lineno;\r | |
1579 | p->col_offset = col_offset;\r | |
1580 | return p;\r | |
1581 | }\r | |
1582 | \r | |
1583 | expr_ty\r | |
1584 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,\r | |
1585 | PyArena *arena)\r | |
1586 | {\r | |
1587 | expr_ty p;\r | |
1588 | if (!test) {\r | |
1589 | PyErr_SetString(PyExc_ValueError,\r | |
1590 | "field test is required for IfExp");\r | |
1591 | return NULL;\r | |
1592 | }\r | |
1593 | if (!body) {\r | |
1594 | PyErr_SetString(PyExc_ValueError,\r | |
1595 | "field body is required for IfExp");\r | |
1596 | return NULL;\r | |
1597 | }\r | |
1598 | if (!orelse) {\r | |
1599 | PyErr_SetString(PyExc_ValueError,\r | |
1600 | "field orelse is required for IfExp");\r | |
1601 | return NULL;\r | |
1602 | }\r | |
1603 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1604 | if (!p)\r | |
1605 | return NULL;\r | |
1606 | p->kind = IfExp_kind;\r | |
1607 | p->v.IfExp.test = test;\r | |
1608 | p->v.IfExp.body = body;\r | |
1609 | p->v.IfExp.orelse = orelse;\r | |
1610 | p->lineno = lineno;\r | |
1611 | p->col_offset = col_offset;\r | |
1612 | return p;\r | |
1613 | }\r | |
1614 | \r | |
1615 | expr_ty\r | |
1616 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena\r | |
1617 | *arena)\r | |
1618 | {\r | |
1619 | expr_ty p;\r | |
1620 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1621 | if (!p)\r | |
1622 | return NULL;\r | |
1623 | p->kind = Dict_kind;\r | |
1624 | p->v.Dict.keys = keys;\r | |
1625 | p->v.Dict.values = values;\r | |
1626 | p->lineno = lineno;\r | |
1627 | p->col_offset = col_offset;\r | |
1628 | return p;\r | |
1629 | }\r | |
1630 | \r | |
1631 | expr_ty\r | |
1632 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)\r | |
1633 | {\r | |
1634 | expr_ty p;\r | |
1635 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1636 | if (!p)\r | |
1637 | return NULL;\r | |
1638 | p->kind = Set_kind;\r | |
1639 | p->v.Set.elts = elts;\r | |
1640 | p->lineno = lineno;\r | |
1641 | p->col_offset = col_offset;\r | |
1642 | return p;\r | |
1643 | }\r | |
1644 | \r | |
1645 | expr_ty\r | |
1646 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r | |
1647 | PyArena *arena)\r | |
1648 | {\r | |
1649 | expr_ty p;\r | |
1650 | if (!elt) {\r | |
1651 | PyErr_SetString(PyExc_ValueError,\r | |
1652 | "field elt is required for ListComp");\r | |
1653 | return NULL;\r | |
1654 | }\r | |
1655 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1656 | if (!p)\r | |
1657 | return NULL;\r | |
1658 | p->kind = ListComp_kind;\r | |
1659 | p->v.ListComp.elt = elt;\r | |
1660 | p->v.ListComp.generators = generators;\r | |
1661 | p->lineno = lineno;\r | |
1662 | p->col_offset = col_offset;\r | |
1663 | return p;\r | |
1664 | }\r | |
1665 | \r | |
1666 | expr_ty\r | |
1667 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena\r | |
1668 | *arena)\r | |
1669 | {\r | |
1670 | expr_ty p;\r | |
1671 | if (!elt) {\r | |
1672 | PyErr_SetString(PyExc_ValueError,\r | |
1673 | "field elt is required for SetComp");\r | |
1674 | return NULL;\r | |
1675 | }\r | |
1676 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1677 | if (!p)\r | |
1678 | return NULL;\r | |
1679 | p->kind = SetComp_kind;\r | |
1680 | p->v.SetComp.elt = elt;\r | |
1681 | p->v.SetComp.generators = generators;\r | |
1682 | p->lineno = lineno;\r | |
1683 | p->col_offset = col_offset;\r | |
1684 | return p;\r | |
1685 | }\r | |
1686 | \r | |
1687 | expr_ty\r | |
1688 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int\r | |
1689 | col_offset, PyArena *arena)\r | |
1690 | {\r | |
1691 | expr_ty p;\r | |
1692 | if (!key) {\r | |
1693 | PyErr_SetString(PyExc_ValueError,\r | |
1694 | "field key is required for DictComp");\r | |
1695 | return NULL;\r | |
1696 | }\r | |
1697 | if (!value) {\r | |
1698 | PyErr_SetString(PyExc_ValueError,\r | |
1699 | "field value is required for DictComp");\r | |
1700 | return NULL;\r | |
1701 | }\r | |
1702 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1703 | if (!p)\r | |
1704 | return NULL;\r | |
1705 | p->kind = DictComp_kind;\r | |
1706 | p->v.DictComp.key = key;\r | |
1707 | p->v.DictComp.value = value;\r | |
1708 | p->v.DictComp.generators = generators;\r | |
1709 | p->lineno = lineno;\r | |
1710 | p->col_offset = col_offset;\r | |
1711 | return p;\r | |
1712 | }\r | |
1713 | \r | |
1714 | expr_ty\r | |
1715 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r | |
1716 | PyArena *arena)\r | |
1717 | {\r | |
1718 | expr_ty p;\r | |
1719 | if (!elt) {\r | |
1720 | PyErr_SetString(PyExc_ValueError,\r | |
1721 | "field elt is required for GeneratorExp");\r | |
1722 | return NULL;\r | |
1723 | }\r | |
1724 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1725 | if (!p)\r | |
1726 | return NULL;\r | |
1727 | p->kind = GeneratorExp_kind;\r | |
1728 | p->v.GeneratorExp.elt = elt;\r | |
1729 | p->v.GeneratorExp.generators = generators;\r | |
1730 | p->lineno = lineno;\r | |
1731 | p->col_offset = col_offset;\r | |
1732 | return p;\r | |
1733 | }\r | |
1734 | \r | |
1735 | expr_ty\r | |
1736 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)\r | |
1737 | {\r | |
1738 | expr_ty p;\r | |
1739 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1740 | if (!p)\r | |
1741 | return NULL;\r | |
1742 | p->kind = Yield_kind;\r | |
1743 | p->v.Yield.value = value;\r | |
1744 | p->lineno = lineno;\r | |
1745 | p->col_offset = col_offset;\r | |
1746 | return p;\r | |
1747 | }\r | |
1748 | \r | |
1749 | expr_ty\r | |
1750 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,\r | |
1751 | int col_offset, PyArena *arena)\r | |
1752 | {\r | |
1753 | expr_ty p;\r | |
1754 | if (!left) {\r | |
1755 | PyErr_SetString(PyExc_ValueError,\r | |
1756 | "field left is required for Compare");\r | |
1757 | return NULL;\r | |
1758 | }\r | |
1759 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1760 | if (!p)\r | |
1761 | return NULL;\r | |
1762 | p->kind = Compare_kind;\r | |
1763 | p->v.Compare.left = left;\r | |
1764 | p->v.Compare.ops = ops;\r | |
1765 | p->v.Compare.comparators = comparators;\r | |
1766 | p->lineno = lineno;\r | |
1767 | p->col_offset = col_offset;\r | |
1768 | return p;\r | |
1769 | }\r | |
1770 | \r | |
1771 | expr_ty\r | |
1772 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,\r | |
1773 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena)\r | |
1774 | {\r | |
1775 | expr_ty p;\r | |
1776 | if (!func) {\r | |
1777 | PyErr_SetString(PyExc_ValueError,\r | |
1778 | "field func is required for Call");\r | |
1779 | return NULL;\r | |
1780 | }\r | |
1781 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1782 | if (!p)\r | |
1783 | return NULL;\r | |
1784 | p->kind = Call_kind;\r | |
1785 | p->v.Call.func = func;\r | |
1786 | p->v.Call.args = args;\r | |
1787 | p->v.Call.keywords = keywords;\r | |
1788 | p->v.Call.starargs = starargs;\r | |
1789 | p->v.Call.kwargs = kwargs;\r | |
1790 | p->lineno = lineno;\r | |
1791 | p->col_offset = col_offset;\r | |
1792 | return p;\r | |
1793 | }\r | |
1794 | \r | |
1795 | expr_ty\r | |
1796 | Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r | |
1797 | {\r | |
1798 | expr_ty p;\r | |
1799 | if (!value) {\r | |
1800 | PyErr_SetString(PyExc_ValueError,\r | |
1801 | "field value is required for Repr");\r | |
1802 | return NULL;\r | |
1803 | }\r | |
1804 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1805 | if (!p)\r | |
1806 | return NULL;\r | |
1807 | p->kind = Repr_kind;\r | |
1808 | p->v.Repr.value = value;\r | |
1809 | p->lineno = lineno;\r | |
1810 | p->col_offset = col_offset;\r | |
1811 | return p;\r | |
1812 | }\r | |
1813 | \r | |
1814 | expr_ty\r | |
1815 | Num(object n, int lineno, int col_offset, PyArena *arena)\r | |
1816 | {\r | |
1817 | expr_ty p;\r | |
1818 | if (!n) {\r | |
1819 | PyErr_SetString(PyExc_ValueError,\r | |
1820 | "field n is required for Num");\r | |
1821 | return NULL;\r | |
1822 | }\r | |
1823 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1824 | if (!p)\r | |
1825 | return NULL;\r | |
1826 | p->kind = Num_kind;\r | |
1827 | p->v.Num.n = n;\r | |
1828 | p->lineno = lineno;\r | |
1829 | p->col_offset = col_offset;\r | |
1830 | return p;\r | |
1831 | }\r | |
1832 | \r | |
1833 | expr_ty\r | |
1834 | Str(string s, int lineno, int col_offset, PyArena *arena)\r | |
1835 | {\r | |
1836 | expr_ty p;\r | |
1837 | if (!s) {\r | |
1838 | PyErr_SetString(PyExc_ValueError,\r | |
1839 | "field s is required for Str");\r | |
1840 | return NULL;\r | |
1841 | }\r | |
1842 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1843 | if (!p)\r | |
1844 | return NULL;\r | |
1845 | p->kind = Str_kind;\r | |
1846 | p->v.Str.s = s;\r | |
1847 | p->lineno = lineno;\r | |
1848 | p->col_offset = col_offset;\r | |
1849 | return p;\r | |
1850 | }\r | |
1851 | \r | |
1852 | expr_ty\r | |
1853 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int\r | |
1854 | col_offset, PyArena *arena)\r | |
1855 | {\r | |
1856 | expr_ty p;\r | |
1857 | if (!value) {\r | |
1858 | PyErr_SetString(PyExc_ValueError,\r | |
1859 | "field value is required for Attribute");\r | |
1860 | return NULL;\r | |
1861 | }\r | |
1862 | if (!attr) {\r | |
1863 | PyErr_SetString(PyExc_ValueError,\r | |
1864 | "field attr is required for Attribute");\r | |
1865 | return NULL;\r | |
1866 | }\r | |
1867 | if (!ctx) {\r | |
1868 | PyErr_SetString(PyExc_ValueError,\r | |
1869 | "field ctx is required for Attribute");\r | |
1870 | return NULL;\r | |
1871 | }\r | |
1872 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1873 | if (!p)\r | |
1874 | return NULL;\r | |
1875 | p->kind = Attribute_kind;\r | |
1876 | p->v.Attribute.value = value;\r | |
1877 | p->v.Attribute.attr = attr;\r | |
1878 | p->v.Attribute.ctx = ctx;\r | |
1879 | p->lineno = lineno;\r | |
1880 | p->col_offset = col_offset;\r | |
1881 | return p;\r | |
1882 | }\r | |
1883 | \r | |
1884 | expr_ty\r | |
1885 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int\r | |
1886 | col_offset, PyArena *arena)\r | |
1887 | {\r | |
1888 | expr_ty p;\r | |
1889 | if (!value) {\r | |
1890 | PyErr_SetString(PyExc_ValueError,\r | |
1891 | "field value is required for Subscript");\r | |
1892 | return NULL;\r | |
1893 | }\r | |
1894 | if (!slice) {\r | |
1895 | PyErr_SetString(PyExc_ValueError,\r | |
1896 | "field slice is required for Subscript");\r | |
1897 | return NULL;\r | |
1898 | }\r | |
1899 | if (!ctx) {\r | |
1900 | PyErr_SetString(PyExc_ValueError,\r | |
1901 | "field ctx is required for Subscript");\r | |
1902 | return NULL;\r | |
1903 | }\r | |
1904 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1905 | if (!p)\r | |
1906 | return NULL;\r | |
1907 | p->kind = Subscript_kind;\r | |
1908 | p->v.Subscript.value = value;\r | |
1909 | p->v.Subscript.slice = slice;\r | |
1910 | p->v.Subscript.ctx = ctx;\r | |
1911 | p->lineno = lineno;\r | |
1912 | p->col_offset = col_offset;\r | |
1913 | return p;\r | |
1914 | }\r | |
1915 | \r | |
1916 | expr_ty\r | |
1917 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena\r | |
1918 | *arena)\r | |
1919 | {\r | |
1920 | expr_ty p;\r | |
1921 | if (!id) {\r | |
1922 | PyErr_SetString(PyExc_ValueError,\r | |
1923 | "field id is required for Name");\r | |
1924 | return NULL;\r | |
1925 | }\r | |
1926 | if (!ctx) {\r | |
1927 | PyErr_SetString(PyExc_ValueError,\r | |
1928 | "field ctx is required for Name");\r | |
1929 | return NULL;\r | |
1930 | }\r | |
1931 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1932 | if (!p)\r | |
1933 | return NULL;\r | |
1934 | p->kind = Name_kind;\r | |
1935 | p->v.Name.id = id;\r | |
1936 | p->v.Name.ctx = ctx;\r | |
1937 | p->lineno = lineno;\r | |
1938 | p->col_offset = col_offset;\r | |
1939 | return p;\r | |
1940 | }\r | |
1941 | \r | |
1942 | expr_ty\r | |
1943 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r | |
1944 | *arena)\r | |
1945 | {\r | |
1946 | expr_ty p;\r | |
1947 | if (!ctx) {\r | |
1948 | PyErr_SetString(PyExc_ValueError,\r | |
1949 | "field ctx is required for List");\r | |
1950 | return NULL;\r | |
1951 | }\r | |
1952 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1953 | if (!p)\r | |
1954 | return NULL;\r | |
1955 | p->kind = List_kind;\r | |
1956 | p->v.List.elts = elts;\r | |
1957 | p->v.List.ctx = ctx;\r | |
1958 | p->lineno = lineno;\r | |
1959 | p->col_offset = col_offset;\r | |
1960 | return p;\r | |
1961 | }\r | |
1962 | \r | |
1963 | expr_ty\r | |
1964 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r | |
1965 | *arena)\r | |
1966 | {\r | |
1967 | expr_ty p;\r | |
1968 | if (!ctx) {\r | |
1969 | PyErr_SetString(PyExc_ValueError,\r | |
1970 | "field ctx is required for Tuple");\r | |
1971 | return NULL;\r | |
1972 | }\r | |
1973 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1974 | if (!p)\r | |
1975 | return NULL;\r | |
1976 | p->kind = Tuple_kind;\r | |
1977 | p->v.Tuple.elts = elts;\r | |
1978 | p->v.Tuple.ctx = ctx;\r | |
1979 | p->lineno = lineno;\r | |
1980 | p->col_offset = col_offset;\r | |
1981 | return p;\r | |
1982 | }\r | |
1983 | \r | |
1984 | slice_ty\r | |
1985 | Ellipsis(PyArena *arena)\r | |
1986 | {\r | |
1987 | slice_ty p;\r | |
1988 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
1989 | if (!p)\r | |
1990 | return NULL;\r | |
1991 | p->kind = Ellipsis_kind;\r | |
1992 | return p;\r | |
1993 | }\r | |
1994 | \r | |
1995 | slice_ty\r | |
1996 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)\r | |
1997 | {\r | |
1998 | slice_ty p;\r | |
1999 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2000 | if (!p)\r | |
2001 | return NULL;\r | |
2002 | p->kind = Slice_kind;\r | |
2003 | p->v.Slice.lower = lower;\r | |
2004 | p->v.Slice.upper = upper;\r | |
2005 | p->v.Slice.step = step;\r | |
2006 | return p;\r | |
2007 | }\r | |
2008 | \r | |
2009 | slice_ty\r | |
2010 | ExtSlice(asdl_seq * dims, PyArena *arena)\r | |
2011 | {\r | |
2012 | slice_ty p;\r | |
2013 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2014 | if (!p)\r | |
2015 | return NULL;\r | |
2016 | p->kind = ExtSlice_kind;\r | |
2017 | p->v.ExtSlice.dims = dims;\r | |
2018 | return p;\r | |
2019 | }\r | |
2020 | \r | |
2021 | slice_ty\r | |
2022 | Index(expr_ty value, PyArena *arena)\r | |
2023 | {\r | |
2024 | slice_ty p;\r | |
2025 | if (!value) {\r | |
2026 | PyErr_SetString(PyExc_ValueError,\r | |
2027 | "field value is required for Index");\r | |
2028 | return NULL;\r | |
2029 | }\r | |
2030 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2031 | if (!p)\r | |
2032 | return NULL;\r | |
2033 | p->kind = Index_kind;\r | |
2034 | p->v.Index.value = value;\r | |
2035 | return p;\r | |
2036 | }\r | |
2037 | \r | |
2038 | comprehension_ty\r | |
2039 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)\r | |
2040 | {\r | |
2041 | comprehension_ty p;\r | |
2042 | if (!target) {\r | |
2043 | PyErr_SetString(PyExc_ValueError,\r | |
2044 | "field target is required for comprehension");\r | |
2045 | return NULL;\r | |
2046 | }\r | |
2047 | if (!iter) {\r | |
2048 | PyErr_SetString(PyExc_ValueError,\r | |
2049 | "field iter is required for comprehension");\r | |
2050 | return NULL;\r | |
2051 | }\r | |
2052 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2053 | if (!p)\r | |
2054 | return NULL;\r | |
2055 | p->target = target;\r | |
2056 | p->iter = iter;\r | |
2057 | p->ifs = ifs;\r | |
2058 | return p;\r | |
2059 | }\r | |
2060 | \r | |
2061 | excepthandler_ty\r | |
2062 | ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int\r | |
2063 | col_offset, PyArena *arena)\r | |
2064 | {\r | |
2065 | excepthandler_ty p;\r | |
2066 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2067 | if (!p)\r | |
2068 | return NULL;\r | |
2069 | p->kind = ExceptHandler_kind;\r | |
2070 | p->v.ExceptHandler.type = type;\r | |
2071 | p->v.ExceptHandler.name = name;\r | |
2072 | p->v.ExceptHandler.body = body;\r | |
2073 | p->lineno = lineno;\r | |
2074 | p->col_offset = col_offset;\r | |
2075 | return p;\r | |
2076 | }\r | |
2077 | \r | |
2078 | arguments_ty\r | |
2079 | arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *\r | |
2080 | defaults, PyArena *arena)\r | |
2081 | {\r | |
2082 | arguments_ty p;\r | |
2083 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2084 | if (!p)\r | |
2085 | return NULL;\r | |
2086 | p->args = args;\r | |
2087 | p->vararg = vararg;\r | |
2088 | p->kwarg = kwarg;\r | |
2089 | p->defaults = defaults;\r | |
2090 | return p;\r | |
2091 | }\r | |
2092 | \r | |
2093 | keyword_ty\r | |
2094 | keyword(identifier arg, expr_ty value, PyArena *arena)\r | |
2095 | {\r | |
2096 | keyword_ty p;\r | |
2097 | if (!arg) {\r | |
2098 | PyErr_SetString(PyExc_ValueError,\r | |
2099 | "field arg is required for keyword");\r | |
2100 | return NULL;\r | |
2101 | }\r | |
2102 | if (!value) {\r | |
2103 | PyErr_SetString(PyExc_ValueError,\r | |
2104 | "field value is required for keyword");\r | |
2105 | return NULL;\r | |
2106 | }\r | |
2107 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2108 | if (!p)\r | |
2109 | return NULL;\r | |
2110 | p->arg = arg;\r | |
2111 | p->value = value;\r | |
2112 | return p;\r | |
2113 | }\r | |
2114 | \r | |
2115 | alias_ty\r | |
2116 | alias(identifier name, identifier asname, PyArena *arena)\r | |
2117 | {\r | |
2118 | alias_ty p;\r | |
2119 | if (!name) {\r | |
2120 | PyErr_SetString(PyExc_ValueError,\r | |
2121 | "field name is required for alias");\r | |
2122 | return NULL;\r | |
2123 | }\r | |
2124 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));\r | |
2125 | if (!p)\r | |
2126 | return NULL;\r | |
2127 | p->name = name;\r | |
2128 | p->asname = asname;\r | |
2129 | return p;\r | |
2130 | }\r | |
2131 | \r | |
2132 | \r | |
2133 | PyObject*\r | |
2134 | ast2obj_mod(void* _o)\r | |
2135 | {\r | |
2136 | mod_ty o = (mod_ty)_o;\r | |
2137 | PyObject *result = NULL, *value = NULL;\r | |
2138 | if (!o) {\r | |
2139 | Py_INCREF(Py_None);\r | |
2140 | return Py_None;\r | |
2141 | }\r | |
2142 | \r | |
2143 | switch (o->kind) {\r | |
2144 | case Module_kind:\r | |
2145 | result = PyType_GenericNew(Module_type, NULL, NULL);\r | |
2146 | if (!result) goto failed;\r | |
2147 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt);\r | |
2148 | if (!value) goto failed;\r | |
2149 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2150 | goto failed;\r | |
2151 | Py_DECREF(value);\r | |
2152 | break;\r | |
2153 | case Interactive_kind:\r | |
2154 | result = PyType_GenericNew(Interactive_type, NULL, NULL);\r | |
2155 | if (!result) goto failed;\r | |
2156 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);\r | |
2157 | if (!value) goto failed;\r | |
2158 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2159 | goto failed;\r | |
2160 | Py_DECREF(value);\r | |
2161 | break;\r | |
2162 | case Expression_kind:\r | |
2163 | result = PyType_GenericNew(Expression_type, NULL, NULL);\r | |
2164 | if (!result) goto failed;\r | |
2165 | value = ast2obj_expr(o->v.Expression.body);\r | |
2166 | if (!value) goto failed;\r | |
2167 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2168 | goto failed;\r | |
2169 | Py_DECREF(value);\r | |
2170 | break;\r | |
2171 | case Suite_kind:\r | |
2172 | result = PyType_GenericNew(Suite_type, NULL, NULL);\r | |
2173 | if (!result) goto failed;\r | |
2174 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);\r | |
2175 | if (!value) goto failed;\r | |
2176 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2177 | goto failed;\r | |
2178 | Py_DECREF(value);\r | |
2179 | break;\r | |
2180 | }\r | |
2181 | return result;\r | |
2182 | failed:\r | |
2183 | Py_XDECREF(value);\r | |
2184 | Py_XDECREF(result);\r | |
2185 | return NULL;\r | |
2186 | }\r | |
2187 | \r | |
2188 | PyObject*\r | |
2189 | ast2obj_stmt(void* _o)\r | |
2190 | {\r | |
2191 | stmt_ty o = (stmt_ty)_o;\r | |
2192 | PyObject *result = NULL, *value = NULL;\r | |
2193 | if (!o) {\r | |
2194 | Py_INCREF(Py_None);\r | |
2195 | return Py_None;\r | |
2196 | }\r | |
2197 | \r | |
2198 | switch (o->kind) {\r | |
2199 | case FunctionDef_kind:\r | |
2200 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL);\r | |
2201 | if (!result) goto failed;\r | |
2202 | value = ast2obj_identifier(o->v.FunctionDef.name);\r | |
2203 | if (!value) goto failed;\r | |
2204 | if (PyObject_SetAttrString(result, "name", value) == -1)\r | |
2205 | goto failed;\r | |
2206 | Py_DECREF(value);\r | |
2207 | value = ast2obj_arguments(o->v.FunctionDef.args);\r | |
2208 | if (!value) goto failed;\r | |
2209 | if (PyObject_SetAttrString(result, "args", value) == -1)\r | |
2210 | goto failed;\r | |
2211 | Py_DECREF(value);\r | |
2212 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);\r | |
2213 | if (!value) goto failed;\r | |
2214 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2215 | goto failed;\r | |
2216 | Py_DECREF(value);\r | |
2217 | value = ast2obj_list(o->v.FunctionDef.decorator_list,\r | |
2218 | ast2obj_expr);\r | |
2219 | if (!value) goto failed;\r | |
2220 | if (PyObject_SetAttrString(result, "decorator_list", value) ==\r | |
2221 | -1)\r | |
2222 | goto failed;\r | |
2223 | Py_DECREF(value);\r | |
2224 | break;\r | |
2225 | case ClassDef_kind:\r | |
2226 | result = PyType_GenericNew(ClassDef_type, NULL, NULL);\r | |
2227 | if (!result) goto failed;\r | |
2228 | value = ast2obj_identifier(o->v.ClassDef.name);\r | |
2229 | if (!value) goto failed;\r | |
2230 | if (PyObject_SetAttrString(result, "name", value) == -1)\r | |
2231 | goto failed;\r | |
2232 | Py_DECREF(value);\r | |
2233 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);\r | |
2234 | if (!value) goto failed;\r | |
2235 | if (PyObject_SetAttrString(result, "bases", value) == -1)\r | |
2236 | goto failed;\r | |
2237 | Py_DECREF(value);\r | |
2238 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);\r | |
2239 | if (!value) goto failed;\r | |
2240 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2241 | goto failed;\r | |
2242 | Py_DECREF(value);\r | |
2243 | value = ast2obj_list(o->v.ClassDef.decorator_list,\r | |
2244 | ast2obj_expr);\r | |
2245 | if (!value) goto failed;\r | |
2246 | if (PyObject_SetAttrString(result, "decorator_list", value) ==\r | |
2247 | -1)\r | |
2248 | goto failed;\r | |
2249 | Py_DECREF(value);\r | |
2250 | break;\r | |
2251 | case Return_kind:\r | |
2252 | result = PyType_GenericNew(Return_type, NULL, NULL);\r | |
2253 | if (!result) goto failed;\r | |
2254 | value = ast2obj_expr(o->v.Return.value);\r | |
2255 | if (!value) goto failed;\r | |
2256 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2257 | goto failed;\r | |
2258 | Py_DECREF(value);\r | |
2259 | break;\r | |
2260 | case Delete_kind:\r | |
2261 | result = PyType_GenericNew(Delete_type, NULL, NULL);\r | |
2262 | if (!result) goto failed;\r | |
2263 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);\r | |
2264 | if (!value) goto failed;\r | |
2265 | if (PyObject_SetAttrString(result, "targets", value) == -1)\r | |
2266 | goto failed;\r | |
2267 | Py_DECREF(value);\r | |
2268 | break;\r | |
2269 | case Assign_kind:\r | |
2270 | result = PyType_GenericNew(Assign_type, NULL, NULL);\r | |
2271 | if (!result) goto failed;\r | |
2272 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);\r | |
2273 | if (!value) goto failed;\r | |
2274 | if (PyObject_SetAttrString(result, "targets", value) == -1)\r | |
2275 | goto failed;\r | |
2276 | Py_DECREF(value);\r | |
2277 | value = ast2obj_expr(o->v.Assign.value);\r | |
2278 | if (!value) goto failed;\r | |
2279 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2280 | goto failed;\r | |
2281 | Py_DECREF(value);\r | |
2282 | break;\r | |
2283 | case AugAssign_kind:\r | |
2284 | result = PyType_GenericNew(AugAssign_type, NULL, NULL);\r | |
2285 | if (!result) goto failed;\r | |
2286 | value = ast2obj_expr(o->v.AugAssign.target);\r | |
2287 | if (!value) goto failed;\r | |
2288 | if (PyObject_SetAttrString(result, "target", value) == -1)\r | |
2289 | goto failed;\r | |
2290 | Py_DECREF(value);\r | |
2291 | value = ast2obj_operator(o->v.AugAssign.op);\r | |
2292 | if (!value) goto failed;\r | |
2293 | if (PyObject_SetAttrString(result, "op", value) == -1)\r | |
2294 | goto failed;\r | |
2295 | Py_DECREF(value);\r | |
2296 | value = ast2obj_expr(o->v.AugAssign.value);\r | |
2297 | if (!value) goto failed;\r | |
2298 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2299 | goto failed;\r | |
2300 | Py_DECREF(value);\r | |
2301 | break;\r | |
2302 | case Print_kind:\r | |
2303 | result = PyType_GenericNew(Print_type, NULL, NULL);\r | |
2304 | if (!result) goto failed;\r | |
2305 | value = ast2obj_expr(o->v.Print.dest);\r | |
2306 | if (!value) goto failed;\r | |
2307 | if (PyObject_SetAttrString(result, "dest", value) == -1)\r | |
2308 | goto failed;\r | |
2309 | Py_DECREF(value);\r | |
2310 | value = ast2obj_list(o->v.Print.values, ast2obj_expr);\r | |
2311 | if (!value) goto failed;\r | |
2312 | if (PyObject_SetAttrString(result, "values", value) == -1)\r | |
2313 | goto failed;\r | |
2314 | Py_DECREF(value);\r | |
2315 | value = ast2obj_bool(o->v.Print.nl);\r | |
2316 | if (!value) goto failed;\r | |
2317 | if (PyObject_SetAttrString(result, "nl", value) == -1)\r | |
2318 | goto failed;\r | |
2319 | Py_DECREF(value);\r | |
2320 | break;\r | |
2321 | case For_kind:\r | |
2322 | result = PyType_GenericNew(For_type, NULL, NULL);\r | |
2323 | if (!result) goto failed;\r | |
2324 | value = ast2obj_expr(o->v.For.target);\r | |
2325 | if (!value) goto failed;\r | |
2326 | if (PyObject_SetAttrString(result, "target", value) == -1)\r | |
2327 | goto failed;\r | |
2328 | Py_DECREF(value);\r | |
2329 | value = ast2obj_expr(o->v.For.iter);\r | |
2330 | if (!value) goto failed;\r | |
2331 | if (PyObject_SetAttrString(result, "iter", value) == -1)\r | |
2332 | goto failed;\r | |
2333 | Py_DECREF(value);\r | |
2334 | value = ast2obj_list(o->v.For.body, ast2obj_stmt);\r | |
2335 | if (!value) goto failed;\r | |
2336 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2337 | goto failed;\r | |
2338 | Py_DECREF(value);\r | |
2339 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);\r | |
2340 | if (!value) goto failed;\r | |
2341 | if (PyObject_SetAttrString(result, "orelse", value) == -1)\r | |
2342 | goto failed;\r | |
2343 | Py_DECREF(value);\r | |
2344 | break;\r | |
2345 | case While_kind:\r | |
2346 | result = PyType_GenericNew(While_type, NULL, NULL);\r | |
2347 | if (!result) goto failed;\r | |
2348 | value = ast2obj_expr(o->v.While.test);\r | |
2349 | if (!value) goto failed;\r | |
2350 | if (PyObject_SetAttrString(result, "test", value) == -1)\r | |
2351 | goto failed;\r | |
2352 | Py_DECREF(value);\r | |
2353 | value = ast2obj_list(o->v.While.body, ast2obj_stmt);\r | |
2354 | if (!value) goto failed;\r | |
2355 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2356 | goto failed;\r | |
2357 | Py_DECREF(value);\r | |
2358 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);\r | |
2359 | if (!value) goto failed;\r | |
2360 | if (PyObject_SetAttrString(result, "orelse", value) == -1)\r | |
2361 | goto failed;\r | |
2362 | Py_DECREF(value);\r | |
2363 | break;\r | |
2364 | case If_kind:\r | |
2365 | result = PyType_GenericNew(If_type, NULL, NULL);\r | |
2366 | if (!result) goto failed;\r | |
2367 | value = ast2obj_expr(o->v.If.test);\r | |
2368 | if (!value) goto failed;\r | |
2369 | if (PyObject_SetAttrString(result, "test", value) == -1)\r | |
2370 | goto failed;\r | |
2371 | Py_DECREF(value);\r | |
2372 | value = ast2obj_list(o->v.If.body, ast2obj_stmt);\r | |
2373 | if (!value) goto failed;\r | |
2374 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2375 | goto failed;\r | |
2376 | Py_DECREF(value);\r | |
2377 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);\r | |
2378 | if (!value) goto failed;\r | |
2379 | if (PyObject_SetAttrString(result, "orelse", value) == -1)\r | |
2380 | goto failed;\r | |
2381 | Py_DECREF(value);\r | |
2382 | break;\r | |
2383 | case With_kind:\r | |
2384 | result = PyType_GenericNew(With_type, NULL, NULL);\r | |
2385 | if (!result) goto failed;\r | |
2386 | value = ast2obj_expr(o->v.With.context_expr);\r | |
2387 | if (!value) goto failed;\r | |
2388 | if (PyObject_SetAttrString(result, "context_expr", value) == -1)\r | |
2389 | goto failed;\r | |
2390 | Py_DECREF(value);\r | |
2391 | value = ast2obj_expr(o->v.With.optional_vars);\r | |
2392 | if (!value) goto failed;\r | |
2393 | if (PyObject_SetAttrString(result, "optional_vars", value) ==\r | |
2394 | -1)\r | |
2395 | goto failed;\r | |
2396 | Py_DECREF(value);\r | |
2397 | value = ast2obj_list(o->v.With.body, ast2obj_stmt);\r | |
2398 | if (!value) goto failed;\r | |
2399 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2400 | goto failed;\r | |
2401 | Py_DECREF(value);\r | |
2402 | break;\r | |
2403 | case Raise_kind:\r | |
2404 | result = PyType_GenericNew(Raise_type, NULL, NULL);\r | |
2405 | if (!result) goto failed;\r | |
2406 | value = ast2obj_expr(o->v.Raise.type);\r | |
2407 | if (!value) goto failed;\r | |
2408 | if (PyObject_SetAttrString(result, "type", value) == -1)\r | |
2409 | goto failed;\r | |
2410 | Py_DECREF(value);\r | |
2411 | value = ast2obj_expr(o->v.Raise.inst);\r | |
2412 | if (!value) goto failed;\r | |
2413 | if (PyObject_SetAttrString(result, "inst", value) == -1)\r | |
2414 | goto failed;\r | |
2415 | Py_DECREF(value);\r | |
2416 | value = ast2obj_expr(o->v.Raise.tback);\r | |
2417 | if (!value) goto failed;\r | |
2418 | if (PyObject_SetAttrString(result, "tback", value) == -1)\r | |
2419 | goto failed;\r | |
2420 | Py_DECREF(value);\r | |
2421 | break;\r | |
2422 | case TryExcept_kind:\r | |
2423 | result = PyType_GenericNew(TryExcept_type, NULL, NULL);\r | |
2424 | if (!result) goto failed;\r | |
2425 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);\r | |
2426 | if (!value) goto failed;\r | |
2427 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2428 | goto failed;\r | |
2429 | Py_DECREF(value);\r | |
2430 | value = ast2obj_list(o->v.TryExcept.handlers,\r | |
2431 | ast2obj_excepthandler);\r | |
2432 | if (!value) goto failed;\r | |
2433 | if (PyObject_SetAttrString(result, "handlers", value) == -1)\r | |
2434 | goto failed;\r | |
2435 | Py_DECREF(value);\r | |
2436 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);\r | |
2437 | if (!value) goto failed;\r | |
2438 | if (PyObject_SetAttrString(result, "orelse", value) == -1)\r | |
2439 | goto failed;\r | |
2440 | Py_DECREF(value);\r | |
2441 | break;\r | |
2442 | case TryFinally_kind:\r | |
2443 | result = PyType_GenericNew(TryFinally_type, NULL, NULL);\r | |
2444 | if (!result) goto failed;\r | |
2445 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);\r | |
2446 | if (!value) goto failed;\r | |
2447 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2448 | goto failed;\r | |
2449 | Py_DECREF(value);\r | |
2450 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);\r | |
2451 | if (!value) goto failed;\r | |
2452 | if (PyObject_SetAttrString(result, "finalbody", value) == -1)\r | |
2453 | goto failed;\r | |
2454 | Py_DECREF(value);\r | |
2455 | break;\r | |
2456 | case Assert_kind:\r | |
2457 | result = PyType_GenericNew(Assert_type, NULL, NULL);\r | |
2458 | if (!result) goto failed;\r | |
2459 | value = ast2obj_expr(o->v.Assert.test);\r | |
2460 | if (!value) goto failed;\r | |
2461 | if (PyObject_SetAttrString(result, "test", value) == -1)\r | |
2462 | goto failed;\r | |
2463 | Py_DECREF(value);\r | |
2464 | value = ast2obj_expr(o->v.Assert.msg);\r | |
2465 | if (!value) goto failed;\r | |
2466 | if (PyObject_SetAttrString(result, "msg", value) == -1)\r | |
2467 | goto failed;\r | |
2468 | Py_DECREF(value);\r | |
2469 | break;\r | |
2470 | case Import_kind:\r | |
2471 | result = PyType_GenericNew(Import_type, NULL, NULL);\r | |
2472 | if (!result) goto failed;\r | |
2473 | value = ast2obj_list(o->v.Import.names, ast2obj_alias);\r | |
2474 | if (!value) goto failed;\r | |
2475 | if (PyObject_SetAttrString(result, "names", value) == -1)\r | |
2476 | goto failed;\r | |
2477 | Py_DECREF(value);\r | |
2478 | break;\r | |
2479 | case ImportFrom_kind:\r | |
2480 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL);\r | |
2481 | if (!result) goto failed;\r | |
2482 | value = ast2obj_identifier(o->v.ImportFrom.module);\r | |
2483 | if (!value) goto failed;\r | |
2484 | if (PyObject_SetAttrString(result, "module", value) == -1)\r | |
2485 | goto failed;\r | |
2486 | Py_DECREF(value);\r | |
2487 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);\r | |
2488 | if (!value) goto failed;\r | |
2489 | if (PyObject_SetAttrString(result, "names", value) == -1)\r | |
2490 | goto failed;\r | |
2491 | Py_DECREF(value);\r | |
2492 | value = ast2obj_int(o->v.ImportFrom.level);\r | |
2493 | if (!value) goto failed;\r | |
2494 | if (PyObject_SetAttrString(result, "level", value) == -1)\r | |
2495 | goto failed;\r | |
2496 | Py_DECREF(value);\r | |
2497 | break;\r | |
2498 | case Exec_kind:\r | |
2499 | result = PyType_GenericNew(Exec_type, NULL, NULL);\r | |
2500 | if (!result) goto failed;\r | |
2501 | value = ast2obj_expr(o->v.Exec.body);\r | |
2502 | if (!value) goto failed;\r | |
2503 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2504 | goto failed;\r | |
2505 | Py_DECREF(value);\r | |
2506 | value = ast2obj_expr(o->v.Exec.globals);\r | |
2507 | if (!value) goto failed;\r | |
2508 | if (PyObject_SetAttrString(result, "globals", value) == -1)\r | |
2509 | goto failed;\r | |
2510 | Py_DECREF(value);\r | |
2511 | value = ast2obj_expr(o->v.Exec.locals);\r | |
2512 | if (!value) goto failed;\r | |
2513 | if (PyObject_SetAttrString(result, "locals", value) == -1)\r | |
2514 | goto failed;\r | |
2515 | Py_DECREF(value);\r | |
2516 | break;\r | |
2517 | case Global_kind:\r | |
2518 | result = PyType_GenericNew(Global_type, NULL, NULL);\r | |
2519 | if (!result) goto failed;\r | |
2520 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier);\r | |
2521 | if (!value) goto failed;\r | |
2522 | if (PyObject_SetAttrString(result, "names", value) == -1)\r | |
2523 | goto failed;\r | |
2524 | Py_DECREF(value);\r | |
2525 | break;\r | |
2526 | case Expr_kind:\r | |
2527 | result = PyType_GenericNew(Expr_type, NULL, NULL);\r | |
2528 | if (!result) goto failed;\r | |
2529 | value = ast2obj_expr(o->v.Expr.value);\r | |
2530 | if (!value) goto failed;\r | |
2531 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2532 | goto failed;\r | |
2533 | Py_DECREF(value);\r | |
2534 | break;\r | |
2535 | case Pass_kind:\r | |
2536 | result = PyType_GenericNew(Pass_type, NULL, NULL);\r | |
2537 | if (!result) goto failed;\r | |
2538 | break;\r | |
2539 | case Break_kind:\r | |
2540 | result = PyType_GenericNew(Break_type, NULL, NULL);\r | |
2541 | if (!result) goto failed;\r | |
2542 | break;\r | |
2543 | case Continue_kind:\r | |
2544 | result = PyType_GenericNew(Continue_type, NULL, NULL);\r | |
2545 | if (!result) goto failed;\r | |
2546 | break;\r | |
2547 | }\r | |
2548 | value = ast2obj_int(o->lineno);\r | |
2549 | if (!value) goto failed;\r | |
2550 | if (PyObject_SetAttrString(result, "lineno", value) < 0)\r | |
2551 | goto failed;\r | |
2552 | Py_DECREF(value);\r | |
2553 | value = ast2obj_int(o->col_offset);\r | |
2554 | if (!value) goto failed;\r | |
2555 | if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r | |
2556 | goto failed;\r | |
2557 | Py_DECREF(value);\r | |
2558 | return result;\r | |
2559 | failed:\r | |
2560 | Py_XDECREF(value);\r | |
2561 | Py_XDECREF(result);\r | |
2562 | return NULL;\r | |
2563 | }\r | |
2564 | \r | |
2565 | PyObject*\r | |
2566 | ast2obj_expr(void* _o)\r | |
2567 | {\r | |
2568 | expr_ty o = (expr_ty)_o;\r | |
2569 | PyObject *result = NULL, *value = NULL;\r | |
2570 | if (!o) {\r | |
2571 | Py_INCREF(Py_None);\r | |
2572 | return Py_None;\r | |
2573 | }\r | |
2574 | \r | |
2575 | switch (o->kind) {\r | |
2576 | case BoolOp_kind:\r | |
2577 | result = PyType_GenericNew(BoolOp_type, NULL, NULL);\r | |
2578 | if (!result) goto failed;\r | |
2579 | value = ast2obj_boolop(o->v.BoolOp.op);\r | |
2580 | if (!value) goto failed;\r | |
2581 | if (PyObject_SetAttrString(result, "op", value) == -1)\r | |
2582 | goto failed;\r | |
2583 | Py_DECREF(value);\r | |
2584 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);\r | |
2585 | if (!value) goto failed;\r | |
2586 | if (PyObject_SetAttrString(result, "values", value) == -1)\r | |
2587 | goto failed;\r | |
2588 | Py_DECREF(value);\r | |
2589 | break;\r | |
2590 | case BinOp_kind:\r | |
2591 | result = PyType_GenericNew(BinOp_type, NULL, NULL);\r | |
2592 | if (!result) goto failed;\r | |
2593 | value = ast2obj_expr(o->v.BinOp.left);\r | |
2594 | if (!value) goto failed;\r | |
2595 | if (PyObject_SetAttrString(result, "left", value) == -1)\r | |
2596 | goto failed;\r | |
2597 | Py_DECREF(value);\r | |
2598 | value = ast2obj_operator(o->v.BinOp.op);\r | |
2599 | if (!value) goto failed;\r | |
2600 | if (PyObject_SetAttrString(result, "op", value) == -1)\r | |
2601 | goto failed;\r | |
2602 | Py_DECREF(value);\r | |
2603 | value = ast2obj_expr(o->v.BinOp.right);\r | |
2604 | if (!value) goto failed;\r | |
2605 | if (PyObject_SetAttrString(result, "right", value) == -1)\r | |
2606 | goto failed;\r | |
2607 | Py_DECREF(value);\r | |
2608 | break;\r | |
2609 | case UnaryOp_kind:\r | |
2610 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL);\r | |
2611 | if (!result) goto failed;\r | |
2612 | value = ast2obj_unaryop(o->v.UnaryOp.op);\r | |
2613 | if (!value) goto failed;\r | |
2614 | if (PyObject_SetAttrString(result, "op", value) == -1)\r | |
2615 | goto failed;\r | |
2616 | Py_DECREF(value);\r | |
2617 | value = ast2obj_expr(o->v.UnaryOp.operand);\r | |
2618 | if (!value) goto failed;\r | |
2619 | if (PyObject_SetAttrString(result, "operand", value) == -1)\r | |
2620 | goto failed;\r | |
2621 | Py_DECREF(value);\r | |
2622 | break;\r | |
2623 | case Lambda_kind:\r | |
2624 | result = PyType_GenericNew(Lambda_type, NULL, NULL);\r | |
2625 | if (!result) goto failed;\r | |
2626 | value = ast2obj_arguments(o->v.Lambda.args);\r | |
2627 | if (!value) goto failed;\r | |
2628 | if (PyObject_SetAttrString(result, "args", value) == -1)\r | |
2629 | goto failed;\r | |
2630 | Py_DECREF(value);\r | |
2631 | value = ast2obj_expr(o->v.Lambda.body);\r | |
2632 | if (!value) goto failed;\r | |
2633 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2634 | goto failed;\r | |
2635 | Py_DECREF(value);\r | |
2636 | break;\r | |
2637 | case IfExp_kind:\r | |
2638 | result = PyType_GenericNew(IfExp_type, NULL, NULL);\r | |
2639 | if (!result) goto failed;\r | |
2640 | value = ast2obj_expr(o->v.IfExp.test);\r | |
2641 | if (!value) goto failed;\r | |
2642 | if (PyObject_SetAttrString(result, "test", value) == -1)\r | |
2643 | goto failed;\r | |
2644 | Py_DECREF(value);\r | |
2645 | value = ast2obj_expr(o->v.IfExp.body);\r | |
2646 | if (!value) goto failed;\r | |
2647 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
2648 | goto failed;\r | |
2649 | Py_DECREF(value);\r | |
2650 | value = ast2obj_expr(o->v.IfExp.orelse);\r | |
2651 | if (!value) goto failed;\r | |
2652 | if (PyObject_SetAttrString(result, "orelse", value) == -1)\r | |
2653 | goto failed;\r | |
2654 | Py_DECREF(value);\r | |
2655 | break;\r | |
2656 | case Dict_kind:\r | |
2657 | result = PyType_GenericNew(Dict_type, NULL, NULL);\r | |
2658 | if (!result) goto failed;\r | |
2659 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);\r | |
2660 | if (!value) goto failed;\r | |
2661 | if (PyObject_SetAttrString(result, "keys", value) == -1)\r | |
2662 | goto failed;\r | |
2663 | Py_DECREF(value);\r | |
2664 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr);\r | |
2665 | if (!value) goto failed;\r | |
2666 | if (PyObject_SetAttrString(result, "values", value) == -1)\r | |
2667 | goto failed;\r | |
2668 | Py_DECREF(value);\r | |
2669 | break;\r | |
2670 | case Set_kind:\r | |
2671 | result = PyType_GenericNew(Set_type, NULL, NULL);\r | |
2672 | if (!result) goto failed;\r | |
2673 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr);\r | |
2674 | if (!value) goto failed;\r | |
2675 | if (PyObject_SetAttrString(result, "elts", value) == -1)\r | |
2676 | goto failed;\r | |
2677 | Py_DECREF(value);\r | |
2678 | break;\r | |
2679 | case ListComp_kind:\r | |
2680 | result = PyType_GenericNew(ListComp_type, NULL, NULL);\r | |
2681 | if (!result) goto failed;\r | |
2682 | value = ast2obj_expr(o->v.ListComp.elt);\r | |
2683 | if (!value) goto failed;\r | |
2684 | if (PyObject_SetAttrString(result, "elt", value) == -1)\r | |
2685 | goto failed;\r | |
2686 | Py_DECREF(value);\r | |
2687 | value = ast2obj_list(o->v.ListComp.generators,\r | |
2688 | ast2obj_comprehension);\r | |
2689 | if (!value) goto failed;\r | |
2690 | if (PyObject_SetAttrString(result, "generators", value) == -1)\r | |
2691 | goto failed;\r | |
2692 | Py_DECREF(value);\r | |
2693 | break;\r | |
2694 | case SetComp_kind:\r | |
2695 | result = PyType_GenericNew(SetComp_type, NULL, NULL);\r | |
2696 | if (!result) goto failed;\r | |
2697 | value = ast2obj_expr(o->v.SetComp.elt);\r | |
2698 | if (!value) goto failed;\r | |
2699 | if (PyObject_SetAttrString(result, "elt", value) == -1)\r | |
2700 | goto failed;\r | |
2701 | Py_DECREF(value);\r | |
2702 | value = ast2obj_list(o->v.SetComp.generators,\r | |
2703 | ast2obj_comprehension);\r | |
2704 | if (!value) goto failed;\r | |
2705 | if (PyObject_SetAttrString(result, "generators", value) == -1)\r | |
2706 | goto failed;\r | |
2707 | Py_DECREF(value);\r | |
2708 | break;\r | |
2709 | case DictComp_kind:\r | |
2710 | result = PyType_GenericNew(DictComp_type, NULL, NULL);\r | |
2711 | if (!result) goto failed;\r | |
2712 | value = ast2obj_expr(o->v.DictComp.key);\r | |
2713 | if (!value) goto failed;\r | |
2714 | if (PyObject_SetAttrString(result, "key", value) == -1)\r | |
2715 | goto failed;\r | |
2716 | Py_DECREF(value);\r | |
2717 | value = ast2obj_expr(o->v.DictComp.value);\r | |
2718 | if (!value) goto failed;\r | |
2719 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2720 | goto failed;\r | |
2721 | Py_DECREF(value);\r | |
2722 | value = ast2obj_list(o->v.DictComp.generators,\r | |
2723 | ast2obj_comprehension);\r | |
2724 | if (!value) goto failed;\r | |
2725 | if (PyObject_SetAttrString(result, "generators", value) == -1)\r | |
2726 | goto failed;\r | |
2727 | Py_DECREF(value);\r | |
2728 | break;\r | |
2729 | case GeneratorExp_kind:\r | |
2730 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);\r | |
2731 | if (!result) goto failed;\r | |
2732 | value = ast2obj_expr(o->v.GeneratorExp.elt);\r | |
2733 | if (!value) goto failed;\r | |
2734 | if (PyObject_SetAttrString(result, "elt", value) == -1)\r | |
2735 | goto failed;\r | |
2736 | Py_DECREF(value);\r | |
2737 | value = ast2obj_list(o->v.GeneratorExp.generators,\r | |
2738 | ast2obj_comprehension);\r | |
2739 | if (!value) goto failed;\r | |
2740 | if (PyObject_SetAttrString(result, "generators", value) == -1)\r | |
2741 | goto failed;\r | |
2742 | Py_DECREF(value);\r | |
2743 | break;\r | |
2744 | case Yield_kind:\r | |
2745 | result = PyType_GenericNew(Yield_type, NULL, NULL);\r | |
2746 | if (!result) goto failed;\r | |
2747 | value = ast2obj_expr(o->v.Yield.value);\r | |
2748 | if (!value) goto failed;\r | |
2749 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2750 | goto failed;\r | |
2751 | Py_DECREF(value);\r | |
2752 | break;\r | |
2753 | case Compare_kind:\r | |
2754 | result = PyType_GenericNew(Compare_type, NULL, NULL);\r | |
2755 | if (!result) goto failed;\r | |
2756 | value = ast2obj_expr(o->v.Compare.left);\r | |
2757 | if (!value) goto failed;\r | |
2758 | if (PyObject_SetAttrString(result, "left", value) == -1)\r | |
2759 | goto failed;\r | |
2760 | Py_DECREF(value);\r | |
2761 | {\r | |
2762 | int i, n = asdl_seq_LEN(o->v.Compare.ops);\r | |
2763 | value = PyList_New(n);\r | |
2764 | if (!value) goto failed;\r | |
2765 | for(i = 0; i < n; i++)\r | |
2766 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));\r | |
2767 | }\r | |
2768 | if (!value) goto failed;\r | |
2769 | if (PyObject_SetAttrString(result, "ops", value) == -1)\r | |
2770 | goto failed;\r | |
2771 | Py_DECREF(value);\r | |
2772 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);\r | |
2773 | if (!value) goto failed;\r | |
2774 | if (PyObject_SetAttrString(result, "comparators", value) == -1)\r | |
2775 | goto failed;\r | |
2776 | Py_DECREF(value);\r | |
2777 | break;\r | |
2778 | case Call_kind:\r | |
2779 | result = PyType_GenericNew(Call_type, NULL, NULL);\r | |
2780 | if (!result) goto failed;\r | |
2781 | value = ast2obj_expr(o->v.Call.func);\r | |
2782 | if (!value) goto failed;\r | |
2783 | if (PyObject_SetAttrString(result, "func", value) == -1)\r | |
2784 | goto failed;\r | |
2785 | Py_DECREF(value);\r | |
2786 | value = ast2obj_list(o->v.Call.args, ast2obj_expr);\r | |
2787 | if (!value) goto failed;\r | |
2788 | if (PyObject_SetAttrString(result, "args", value) == -1)\r | |
2789 | goto failed;\r | |
2790 | Py_DECREF(value);\r | |
2791 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);\r | |
2792 | if (!value) goto failed;\r | |
2793 | if (PyObject_SetAttrString(result, "keywords", value) == -1)\r | |
2794 | goto failed;\r | |
2795 | Py_DECREF(value);\r | |
2796 | value = ast2obj_expr(o->v.Call.starargs);\r | |
2797 | if (!value) goto failed;\r | |
2798 | if (PyObject_SetAttrString(result, "starargs", value) == -1)\r | |
2799 | goto failed;\r | |
2800 | Py_DECREF(value);\r | |
2801 | value = ast2obj_expr(o->v.Call.kwargs);\r | |
2802 | if (!value) goto failed;\r | |
2803 | if (PyObject_SetAttrString(result, "kwargs", value) == -1)\r | |
2804 | goto failed;\r | |
2805 | Py_DECREF(value);\r | |
2806 | break;\r | |
2807 | case Repr_kind:\r | |
2808 | result = PyType_GenericNew(Repr_type, NULL, NULL);\r | |
2809 | if (!result) goto failed;\r | |
2810 | value = ast2obj_expr(o->v.Repr.value);\r | |
2811 | if (!value) goto failed;\r | |
2812 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2813 | goto failed;\r | |
2814 | Py_DECREF(value);\r | |
2815 | break;\r | |
2816 | case Num_kind:\r | |
2817 | result = PyType_GenericNew(Num_type, NULL, NULL);\r | |
2818 | if (!result) goto failed;\r | |
2819 | value = ast2obj_object(o->v.Num.n);\r | |
2820 | if (!value) goto failed;\r | |
2821 | if (PyObject_SetAttrString(result, "n", value) == -1)\r | |
2822 | goto failed;\r | |
2823 | Py_DECREF(value);\r | |
2824 | break;\r | |
2825 | case Str_kind:\r | |
2826 | result = PyType_GenericNew(Str_type, NULL, NULL);\r | |
2827 | if (!result) goto failed;\r | |
2828 | value = ast2obj_string(o->v.Str.s);\r | |
2829 | if (!value) goto failed;\r | |
2830 | if (PyObject_SetAttrString(result, "s", value) == -1)\r | |
2831 | goto failed;\r | |
2832 | Py_DECREF(value);\r | |
2833 | break;\r | |
2834 | case Attribute_kind:\r | |
2835 | result = PyType_GenericNew(Attribute_type, NULL, NULL);\r | |
2836 | if (!result) goto failed;\r | |
2837 | value = ast2obj_expr(o->v.Attribute.value);\r | |
2838 | if (!value) goto failed;\r | |
2839 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2840 | goto failed;\r | |
2841 | Py_DECREF(value);\r | |
2842 | value = ast2obj_identifier(o->v.Attribute.attr);\r | |
2843 | if (!value) goto failed;\r | |
2844 | if (PyObject_SetAttrString(result, "attr", value) == -1)\r | |
2845 | goto failed;\r | |
2846 | Py_DECREF(value);\r | |
2847 | value = ast2obj_expr_context(o->v.Attribute.ctx);\r | |
2848 | if (!value) goto failed;\r | |
2849 | if (PyObject_SetAttrString(result, "ctx", value) == -1)\r | |
2850 | goto failed;\r | |
2851 | Py_DECREF(value);\r | |
2852 | break;\r | |
2853 | case Subscript_kind:\r | |
2854 | result = PyType_GenericNew(Subscript_type, NULL, NULL);\r | |
2855 | if (!result) goto failed;\r | |
2856 | value = ast2obj_expr(o->v.Subscript.value);\r | |
2857 | if (!value) goto failed;\r | |
2858 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
2859 | goto failed;\r | |
2860 | Py_DECREF(value);\r | |
2861 | value = ast2obj_slice(o->v.Subscript.slice);\r | |
2862 | if (!value) goto failed;\r | |
2863 | if (PyObject_SetAttrString(result, "slice", value) == -1)\r | |
2864 | goto failed;\r | |
2865 | Py_DECREF(value);\r | |
2866 | value = ast2obj_expr_context(o->v.Subscript.ctx);\r | |
2867 | if (!value) goto failed;\r | |
2868 | if (PyObject_SetAttrString(result, "ctx", value) == -1)\r | |
2869 | goto failed;\r | |
2870 | Py_DECREF(value);\r | |
2871 | break;\r | |
2872 | case Name_kind:\r | |
2873 | result = PyType_GenericNew(Name_type, NULL, NULL);\r | |
2874 | if (!result) goto failed;\r | |
2875 | value = ast2obj_identifier(o->v.Name.id);\r | |
2876 | if (!value) goto failed;\r | |
2877 | if (PyObject_SetAttrString(result, "id", value) == -1)\r | |
2878 | goto failed;\r | |
2879 | Py_DECREF(value);\r | |
2880 | value = ast2obj_expr_context(o->v.Name.ctx);\r | |
2881 | if (!value) goto failed;\r | |
2882 | if (PyObject_SetAttrString(result, "ctx", value) == -1)\r | |
2883 | goto failed;\r | |
2884 | Py_DECREF(value);\r | |
2885 | break;\r | |
2886 | case List_kind:\r | |
2887 | result = PyType_GenericNew(List_type, NULL, NULL);\r | |
2888 | if (!result) goto failed;\r | |
2889 | value = ast2obj_list(o->v.List.elts, ast2obj_expr);\r | |
2890 | if (!value) goto failed;\r | |
2891 | if (PyObject_SetAttrString(result, "elts", value) == -1)\r | |
2892 | goto failed;\r | |
2893 | Py_DECREF(value);\r | |
2894 | value = ast2obj_expr_context(o->v.List.ctx);\r | |
2895 | if (!value) goto failed;\r | |
2896 | if (PyObject_SetAttrString(result, "ctx", value) == -1)\r | |
2897 | goto failed;\r | |
2898 | Py_DECREF(value);\r | |
2899 | break;\r | |
2900 | case Tuple_kind:\r | |
2901 | result = PyType_GenericNew(Tuple_type, NULL, NULL);\r | |
2902 | if (!result) goto failed;\r | |
2903 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);\r | |
2904 | if (!value) goto failed;\r | |
2905 | if (PyObject_SetAttrString(result, "elts", value) == -1)\r | |
2906 | goto failed;\r | |
2907 | Py_DECREF(value);\r | |
2908 | value = ast2obj_expr_context(o->v.Tuple.ctx);\r | |
2909 | if (!value) goto failed;\r | |
2910 | if (PyObject_SetAttrString(result, "ctx", value) == -1)\r | |
2911 | goto failed;\r | |
2912 | Py_DECREF(value);\r | |
2913 | break;\r | |
2914 | }\r | |
2915 | value = ast2obj_int(o->lineno);\r | |
2916 | if (!value) goto failed;\r | |
2917 | if (PyObject_SetAttrString(result, "lineno", value) < 0)\r | |
2918 | goto failed;\r | |
2919 | Py_DECREF(value);\r | |
2920 | value = ast2obj_int(o->col_offset);\r | |
2921 | if (!value) goto failed;\r | |
2922 | if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r | |
2923 | goto failed;\r | |
2924 | Py_DECREF(value);\r | |
2925 | return result;\r | |
2926 | failed:\r | |
2927 | Py_XDECREF(value);\r | |
2928 | Py_XDECREF(result);\r | |
2929 | return NULL;\r | |
2930 | }\r | |
2931 | \r | |
2932 | PyObject* ast2obj_expr_context(expr_context_ty o)\r | |
2933 | {\r | |
2934 | switch(o) {\r | |
2935 | case Load:\r | |
2936 | Py_INCREF(Load_singleton);\r | |
2937 | return Load_singleton;\r | |
2938 | case Store:\r | |
2939 | Py_INCREF(Store_singleton);\r | |
2940 | return Store_singleton;\r | |
2941 | case Del:\r | |
2942 | Py_INCREF(Del_singleton);\r | |
2943 | return Del_singleton;\r | |
2944 | case AugLoad:\r | |
2945 | Py_INCREF(AugLoad_singleton);\r | |
2946 | return AugLoad_singleton;\r | |
2947 | case AugStore:\r | |
2948 | Py_INCREF(AugStore_singleton);\r | |
2949 | return AugStore_singleton;\r | |
2950 | case Param:\r | |
2951 | Py_INCREF(Param_singleton);\r | |
2952 | return Param_singleton;\r | |
2953 | default:\r | |
2954 | /* should never happen, but just in case ... */\r | |
2955 | PyErr_Format(PyExc_SystemError, "unknown expr_context found");\r | |
2956 | return NULL;\r | |
2957 | }\r | |
2958 | }\r | |
2959 | PyObject*\r | |
2960 | ast2obj_slice(void* _o)\r | |
2961 | {\r | |
2962 | slice_ty o = (slice_ty)_o;\r | |
2963 | PyObject *result = NULL, *value = NULL;\r | |
2964 | if (!o) {\r | |
2965 | Py_INCREF(Py_None);\r | |
2966 | return Py_None;\r | |
2967 | }\r | |
2968 | \r | |
2969 | switch (o->kind) {\r | |
2970 | case Ellipsis_kind:\r | |
2971 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL);\r | |
2972 | if (!result) goto failed;\r | |
2973 | break;\r | |
2974 | case Slice_kind:\r | |
2975 | result = PyType_GenericNew(Slice_type, NULL, NULL);\r | |
2976 | if (!result) goto failed;\r | |
2977 | value = ast2obj_expr(o->v.Slice.lower);\r | |
2978 | if (!value) goto failed;\r | |
2979 | if (PyObject_SetAttrString(result, "lower", value) == -1)\r | |
2980 | goto failed;\r | |
2981 | Py_DECREF(value);\r | |
2982 | value = ast2obj_expr(o->v.Slice.upper);\r | |
2983 | if (!value) goto failed;\r | |
2984 | if (PyObject_SetAttrString(result, "upper", value) == -1)\r | |
2985 | goto failed;\r | |
2986 | Py_DECREF(value);\r | |
2987 | value = ast2obj_expr(o->v.Slice.step);\r | |
2988 | if (!value) goto failed;\r | |
2989 | if (PyObject_SetAttrString(result, "step", value) == -1)\r | |
2990 | goto failed;\r | |
2991 | Py_DECREF(value);\r | |
2992 | break;\r | |
2993 | case ExtSlice_kind:\r | |
2994 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL);\r | |
2995 | if (!result) goto failed;\r | |
2996 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);\r | |
2997 | if (!value) goto failed;\r | |
2998 | if (PyObject_SetAttrString(result, "dims", value) == -1)\r | |
2999 | goto failed;\r | |
3000 | Py_DECREF(value);\r | |
3001 | break;\r | |
3002 | case Index_kind:\r | |
3003 | result = PyType_GenericNew(Index_type, NULL, NULL);\r | |
3004 | if (!result) goto failed;\r | |
3005 | value = ast2obj_expr(o->v.Index.value);\r | |
3006 | if (!value) goto failed;\r | |
3007 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
3008 | goto failed;\r | |
3009 | Py_DECREF(value);\r | |
3010 | break;\r | |
3011 | }\r | |
3012 | return result;\r | |
3013 | failed:\r | |
3014 | Py_XDECREF(value);\r | |
3015 | Py_XDECREF(result);\r | |
3016 | return NULL;\r | |
3017 | }\r | |
3018 | \r | |
3019 | PyObject* ast2obj_boolop(boolop_ty o)\r | |
3020 | {\r | |
3021 | switch(o) {\r | |
3022 | case And:\r | |
3023 | Py_INCREF(And_singleton);\r | |
3024 | return And_singleton;\r | |
3025 | case Or:\r | |
3026 | Py_INCREF(Or_singleton);\r | |
3027 | return Or_singleton;\r | |
3028 | default:\r | |
3029 | /* should never happen, but just in case ... */\r | |
3030 | PyErr_Format(PyExc_SystemError, "unknown boolop found");\r | |
3031 | return NULL;\r | |
3032 | }\r | |
3033 | }\r | |
3034 | PyObject* ast2obj_operator(operator_ty o)\r | |
3035 | {\r | |
3036 | switch(o) {\r | |
3037 | case Add:\r | |
3038 | Py_INCREF(Add_singleton);\r | |
3039 | return Add_singleton;\r | |
3040 | case Sub:\r | |
3041 | Py_INCREF(Sub_singleton);\r | |
3042 | return Sub_singleton;\r | |
3043 | case Mult:\r | |
3044 | Py_INCREF(Mult_singleton);\r | |
3045 | return Mult_singleton;\r | |
3046 | case Div:\r | |
3047 | Py_INCREF(Div_singleton);\r | |
3048 | return Div_singleton;\r | |
3049 | case Mod:\r | |
3050 | Py_INCREF(Mod_singleton);\r | |
3051 | return Mod_singleton;\r | |
3052 | case Pow:\r | |
3053 | Py_INCREF(Pow_singleton);\r | |
3054 | return Pow_singleton;\r | |
3055 | case LShift:\r | |
3056 | Py_INCREF(LShift_singleton);\r | |
3057 | return LShift_singleton;\r | |
3058 | case RShift:\r | |
3059 | Py_INCREF(RShift_singleton);\r | |
3060 | return RShift_singleton;\r | |
3061 | case BitOr:\r | |
3062 | Py_INCREF(BitOr_singleton);\r | |
3063 | return BitOr_singleton;\r | |
3064 | case BitXor:\r | |
3065 | Py_INCREF(BitXor_singleton);\r | |
3066 | return BitXor_singleton;\r | |
3067 | case BitAnd:\r | |
3068 | Py_INCREF(BitAnd_singleton);\r | |
3069 | return BitAnd_singleton;\r | |
3070 | case FloorDiv:\r | |
3071 | Py_INCREF(FloorDiv_singleton);\r | |
3072 | return FloorDiv_singleton;\r | |
3073 | default:\r | |
3074 | /* should never happen, but just in case ... */\r | |
3075 | PyErr_Format(PyExc_SystemError, "unknown operator found");\r | |
3076 | return NULL;\r | |
3077 | }\r | |
3078 | }\r | |
3079 | PyObject* ast2obj_unaryop(unaryop_ty o)\r | |
3080 | {\r | |
3081 | switch(o) {\r | |
3082 | case Invert:\r | |
3083 | Py_INCREF(Invert_singleton);\r | |
3084 | return Invert_singleton;\r | |
3085 | case Not:\r | |
3086 | Py_INCREF(Not_singleton);\r | |
3087 | return Not_singleton;\r | |
3088 | case UAdd:\r | |
3089 | Py_INCREF(UAdd_singleton);\r | |
3090 | return UAdd_singleton;\r | |
3091 | case USub:\r | |
3092 | Py_INCREF(USub_singleton);\r | |
3093 | return USub_singleton;\r | |
3094 | default:\r | |
3095 | /* should never happen, but just in case ... */\r | |
3096 | PyErr_Format(PyExc_SystemError, "unknown unaryop found");\r | |
3097 | return NULL;\r | |
3098 | }\r | |
3099 | }\r | |
3100 | PyObject* ast2obj_cmpop(cmpop_ty o)\r | |
3101 | {\r | |
3102 | switch(o) {\r | |
3103 | case Eq:\r | |
3104 | Py_INCREF(Eq_singleton);\r | |
3105 | return Eq_singleton;\r | |
3106 | case NotEq:\r | |
3107 | Py_INCREF(NotEq_singleton);\r | |
3108 | return NotEq_singleton;\r | |
3109 | case Lt:\r | |
3110 | Py_INCREF(Lt_singleton);\r | |
3111 | return Lt_singleton;\r | |
3112 | case LtE:\r | |
3113 | Py_INCREF(LtE_singleton);\r | |
3114 | return LtE_singleton;\r | |
3115 | case Gt:\r | |
3116 | Py_INCREF(Gt_singleton);\r | |
3117 | return Gt_singleton;\r | |
3118 | case GtE:\r | |
3119 | Py_INCREF(GtE_singleton);\r | |
3120 | return GtE_singleton;\r | |
3121 | case Is:\r | |
3122 | Py_INCREF(Is_singleton);\r | |
3123 | return Is_singleton;\r | |
3124 | case IsNot:\r | |
3125 | Py_INCREF(IsNot_singleton);\r | |
3126 | return IsNot_singleton;\r | |
3127 | case In:\r | |
3128 | Py_INCREF(In_singleton);\r | |
3129 | return In_singleton;\r | |
3130 | case NotIn:\r | |
3131 | Py_INCREF(NotIn_singleton);\r | |
3132 | return NotIn_singleton;\r | |
3133 | default:\r | |
3134 | /* should never happen, but just in case ... */\r | |
3135 | PyErr_Format(PyExc_SystemError, "unknown cmpop found");\r | |
3136 | return NULL;\r | |
3137 | }\r | |
3138 | }\r | |
3139 | PyObject*\r | |
3140 | ast2obj_comprehension(void* _o)\r | |
3141 | {\r | |
3142 | comprehension_ty o = (comprehension_ty)_o;\r | |
3143 | PyObject *result = NULL, *value = NULL;\r | |
3144 | if (!o) {\r | |
3145 | Py_INCREF(Py_None);\r | |
3146 | return Py_None;\r | |
3147 | }\r | |
3148 | \r | |
3149 | result = PyType_GenericNew(comprehension_type, NULL, NULL);\r | |
3150 | if (!result) return NULL;\r | |
3151 | value = ast2obj_expr(o->target);\r | |
3152 | if (!value) goto failed;\r | |
3153 | if (PyObject_SetAttrString(result, "target", value) == -1)\r | |
3154 | goto failed;\r | |
3155 | Py_DECREF(value);\r | |
3156 | value = ast2obj_expr(o->iter);\r | |
3157 | if (!value) goto failed;\r | |
3158 | if (PyObject_SetAttrString(result, "iter", value) == -1)\r | |
3159 | goto failed;\r | |
3160 | Py_DECREF(value);\r | |
3161 | value = ast2obj_list(o->ifs, ast2obj_expr);\r | |
3162 | if (!value) goto failed;\r | |
3163 | if (PyObject_SetAttrString(result, "ifs", value) == -1)\r | |
3164 | goto failed;\r | |
3165 | Py_DECREF(value);\r | |
3166 | return result;\r | |
3167 | failed:\r | |
3168 | Py_XDECREF(value);\r | |
3169 | Py_XDECREF(result);\r | |
3170 | return NULL;\r | |
3171 | }\r | |
3172 | \r | |
3173 | PyObject*\r | |
3174 | ast2obj_excepthandler(void* _o)\r | |
3175 | {\r | |
3176 | excepthandler_ty o = (excepthandler_ty)_o;\r | |
3177 | PyObject *result = NULL, *value = NULL;\r | |
3178 | if (!o) {\r | |
3179 | Py_INCREF(Py_None);\r | |
3180 | return Py_None;\r | |
3181 | }\r | |
3182 | \r | |
3183 | switch (o->kind) {\r | |
3184 | case ExceptHandler_kind:\r | |
3185 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);\r | |
3186 | if (!result) goto failed;\r | |
3187 | value = ast2obj_expr(o->v.ExceptHandler.type);\r | |
3188 | if (!value) goto failed;\r | |
3189 | if (PyObject_SetAttrString(result, "type", value) == -1)\r | |
3190 | goto failed;\r | |
3191 | Py_DECREF(value);\r | |
3192 | value = ast2obj_expr(o->v.ExceptHandler.name);\r | |
3193 | if (!value) goto failed;\r | |
3194 | if (PyObject_SetAttrString(result, "name", value) == -1)\r | |
3195 | goto failed;\r | |
3196 | Py_DECREF(value);\r | |
3197 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);\r | |
3198 | if (!value) goto failed;\r | |
3199 | if (PyObject_SetAttrString(result, "body", value) == -1)\r | |
3200 | goto failed;\r | |
3201 | Py_DECREF(value);\r | |
3202 | break;\r | |
3203 | }\r | |
3204 | value = ast2obj_int(o->lineno);\r | |
3205 | if (!value) goto failed;\r | |
3206 | if (PyObject_SetAttrString(result, "lineno", value) < 0)\r | |
3207 | goto failed;\r | |
3208 | Py_DECREF(value);\r | |
3209 | value = ast2obj_int(o->col_offset);\r | |
3210 | if (!value) goto failed;\r | |
3211 | if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r | |
3212 | goto failed;\r | |
3213 | Py_DECREF(value);\r | |
3214 | return result;\r | |
3215 | failed:\r | |
3216 | Py_XDECREF(value);\r | |
3217 | Py_XDECREF(result);\r | |
3218 | return NULL;\r | |
3219 | }\r | |
3220 | \r | |
3221 | PyObject*\r | |
3222 | ast2obj_arguments(void* _o)\r | |
3223 | {\r | |
3224 | arguments_ty o = (arguments_ty)_o;\r | |
3225 | PyObject *result = NULL, *value = NULL;\r | |
3226 | if (!o) {\r | |
3227 | Py_INCREF(Py_None);\r | |
3228 | return Py_None;\r | |
3229 | }\r | |
3230 | \r | |
3231 | result = PyType_GenericNew(arguments_type, NULL, NULL);\r | |
3232 | if (!result) return NULL;\r | |
3233 | value = ast2obj_list(o->args, ast2obj_expr);\r | |
3234 | if (!value) goto failed;\r | |
3235 | if (PyObject_SetAttrString(result, "args", value) == -1)\r | |
3236 | goto failed;\r | |
3237 | Py_DECREF(value);\r | |
3238 | value = ast2obj_identifier(o->vararg);\r | |
3239 | if (!value) goto failed;\r | |
3240 | if (PyObject_SetAttrString(result, "vararg", value) == -1)\r | |
3241 | goto failed;\r | |
3242 | Py_DECREF(value);\r | |
3243 | value = ast2obj_identifier(o->kwarg);\r | |
3244 | if (!value) goto failed;\r | |
3245 | if (PyObject_SetAttrString(result, "kwarg", value) == -1)\r | |
3246 | goto failed;\r | |
3247 | Py_DECREF(value);\r | |
3248 | value = ast2obj_list(o->defaults, ast2obj_expr);\r | |
3249 | if (!value) goto failed;\r | |
3250 | if (PyObject_SetAttrString(result, "defaults", value) == -1)\r | |
3251 | goto failed;\r | |
3252 | Py_DECREF(value);\r | |
3253 | return result;\r | |
3254 | failed:\r | |
3255 | Py_XDECREF(value);\r | |
3256 | Py_XDECREF(result);\r | |
3257 | return NULL;\r | |
3258 | }\r | |
3259 | \r | |
3260 | PyObject*\r | |
3261 | ast2obj_keyword(void* _o)\r | |
3262 | {\r | |
3263 | keyword_ty o = (keyword_ty)_o;\r | |
3264 | PyObject *result = NULL, *value = NULL;\r | |
3265 | if (!o) {\r | |
3266 | Py_INCREF(Py_None);\r | |
3267 | return Py_None;\r | |
3268 | }\r | |
3269 | \r | |
3270 | result = PyType_GenericNew(keyword_type, NULL, NULL);\r | |
3271 | if (!result) return NULL;\r | |
3272 | value = ast2obj_identifier(o->arg);\r | |
3273 | if (!value) goto failed;\r | |
3274 | if (PyObject_SetAttrString(result, "arg", value) == -1)\r | |
3275 | goto failed;\r | |
3276 | Py_DECREF(value);\r | |
3277 | value = ast2obj_expr(o->value);\r | |
3278 | if (!value) goto failed;\r | |
3279 | if (PyObject_SetAttrString(result, "value", value) == -1)\r | |
3280 | goto failed;\r | |
3281 | Py_DECREF(value);\r | |
3282 | return result;\r | |
3283 | failed:\r | |
3284 | Py_XDECREF(value);\r | |
3285 | Py_XDECREF(result);\r | |
3286 | return NULL;\r | |
3287 | }\r | |
3288 | \r | |
3289 | PyObject*\r | |
3290 | ast2obj_alias(void* _o)\r | |
3291 | {\r | |
3292 | alias_ty o = (alias_ty)_o;\r | |
3293 | PyObject *result = NULL, *value = NULL;\r | |
3294 | if (!o) {\r | |
3295 | Py_INCREF(Py_None);\r | |
3296 | return Py_None;\r | |
3297 | }\r | |
3298 | \r | |
3299 | result = PyType_GenericNew(alias_type, NULL, NULL);\r | |
3300 | if (!result) return NULL;\r | |
3301 | value = ast2obj_identifier(o->name);\r | |
3302 | if (!value) goto failed;\r | |
3303 | if (PyObject_SetAttrString(result, "name", value) == -1)\r | |
3304 | goto failed;\r | |
3305 | Py_DECREF(value);\r | |
3306 | value = ast2obj_identifier(o->asname);\r | |
3307 | if (!value) goto failed;\r | |
3308 | if (PyObject_SetAttrString(result, "asname", value) == -1)\r | |
3309 | goto failed;\r | |
3310 | Py_DECREF(value);\r | |
3311 | return result;\r | |
3312 | failed:\r | |
3313 | Py_XDECREF(value);\r | |
3314 | Py_XDECREF(result);\r | |
3315 | return NULL;\r | |
3316 | }\r | |
3317 | \r | |
3318 | \r | |
3319 | int\r | |
3320 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)\r | |
3321 | {\r | |
3322 | PyObject* tmp = NULL;\r | |
3323 | int isinstance;\r | |
3324 | \r | |
3325 | \r | |
3326 | if (obj == Py_None) {\r | |
3327 | *out = NULL;\r | |
3328 | return 0;\r | |
3329 | }\r | |
3330 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);\r | |
3331 | if (isinstance == -1) {\r | |
3332 | return 1;\r | |
3333 | }\r | |
3334 | if (isinstance) {\r | |
3335 | asdl_seq* body;\r | |
3336 | \r | |
3337 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3338 | int res;\r | |
3339 | Py_ssize_t len;\r | |
3340 | Py_ssize_t i;\r | |
3341 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3342 | if (tmp == NULL) goto failed;\r | |
3343 | if (!PyList_Check(tmp)) {\r | |
3344 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3345 | goto failed;\r | |
3346 | }\r | |
3347 | len = PyList_GET_SIZE(tmp);\r | |
3348 | body = asdl_seq_new(len, arena);\r | |
3349 | if (body == NULL) goto failed;\r | |
3350 | for (i = 0; i < len; i++) {\r | |
3351 | stmt_ty value;\r | |
3352 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3353 | if (res != 0) goto failed;\r | |
3354 | asdl_seq_SET(body, i, value);\r | |
3355 | }\r | |
3356 | Py_XDECREF(tmp);\r | |
3357 | tmp = NULL;\r | |
3358 | } else {\r | |
3359 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");\r | |
3360 | return 1;\r | |
3361 | }\r | |
3362 | *out = Module(body, arena);\r | |
3363 | if (*out == NULL) goto failed;\r | |
3364 | return 0;\r | |
3365 | }\r | |
3366 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);\r | |
3367 | if (isinstance == -1) {\r | |
3368 | return 1;\r | |
3369 | }\r | |
3370 | if (isinstance) {\r | |
3371 | asdl_seq* body;\r | |
3372 | \r | |
3373 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3374 | int res;\r | |
3375 | Py_ssize_t len;\r | |
3376 | Py_ssize_t i;\r | |
3377 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3378 | if (tmp == NULL) goto failed;\r | |
3379 | if (!PyList_Check(tmp)) {\r | |
3380 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3381 | goto failed;\r | |
3382 | }\r | |
3383 | len = PyList_GET_SIZE(tmp);\r | |
3384 | body = asdl_seq_new(len, arena);\r | |
3385 | if (body == NULL) goto failed;\r | |
3386 | for (i = 0; i < len; i++) {\r | |
3387 | stmt_ty value;\r | |
3388 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3389 | if (res != 0) goto failed;\r | |
3390 | asdl_seq_SET(body, i, value);\r | |
3391 | }\r | |
3392 | Py_XDECREF(tmp);\r | |
3393 | tmp = NULL;\r | |
3394 | } else {\r | |
3395 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");\r | |
3396 | return 1;\r | |
3397 | }\r | |
3398 | *out = Interactive(body, arena);\r | |
3399 | if (*out == NULL) goto failed;\r | |
3400 | return 0;\r | |
3401 | }\r | |
3402 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);\r | |
3403 | if (isinstance == -1) {\r | |
3404 | return 1;\r | |
3405 | }\r | |
3406 | if (isinstance) {\r | |
3407 | expr_ty body;\r | |
3408 | \r | |
3409 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3410 | int res;\r | |
3411 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3412 | if (tmp == NULL) goto failed;\r | |
3413 | res = obj2ast_expr(tmp, &body, arena);\r | |
3414 | if (res != 0) goto failed;\r | |
3415 | Py_XDECREF(tmp);\r | |
3416 | tmp = NULL;\r | |
3417 | } else {\r | |
3418 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");\r | |
3419 | return 1;\r | |
3420 | }\r | |
3421 | *out = Expression(body, arena);\r | |
3422 | if (*out == NULL) goto failed;\r | |
3423 | return 0;\r | |
3424 | }\r | |
3425 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);\r | |
3426 | if (isinstance == -1) {\r | |
3427 | return 1;\r | |
3428 | }\r | |
3429 | if (isinstance) {\r | |
3430 | asdl_seq* body;\r | |
3431 | \r | |
3432 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3433 | int res;\r | |
3434 | Py_ssize_t len;\r | |
3435 | Py_ssize_t i;\r | |
3436 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3437 | if (tmp == NULL) goto failed;\r | |
3438 | if (!PyList_Check(tmp)) {\r | |
3439 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3440 | goto failed;\r | |
3441 | }\r | |
3442 | len = PyList_GET_SIZE(tmp);\r | |
3443 | body = asdl_seq_new(len, arena);\r | |
3444 | if (body == NULL) goto failed;\r | |
3445 | for (i = 0; i < len; i++) {\r | |
3446 | stmt_ty value;\r | |
3447 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3448 | if (res != 0) goto failed;\r | |
3449 | asdl_seq_SET(body, i, value);\r | |
3450 | }\r | |
3451 | Py_XDECREF(tmp);\r | |
3452 | tmp = NULL;\r | |
3453 | } else {\r | |
3454 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");\r | |
3455 | return 1;\r | |
3456 | }\r | |
3457 | *out = Suite(body, arena);\r | |
3458 | if (*out == NULL) goto failed;\r | |
3459 | return 0;\r | |
3460 | }\r | |
3461 | \r | |
3462 | tmp = PyObject_Repr(obj);\r | |
3463 | if (tmp == NULL) goto failed;\r | |
3464 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));\r | |
3465 | failed:\r | |
3466 | Py_XDECREF(tmp);\r | |
3467 | return 1;\r | |
3468 | }\r | |
3469 | \r | |
3470 | int\r | |
3471 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)\r | |
3472 | {\r | |
3473 | PyObject* tmp = NULL;\r | |
3474 | int isinstance;\r | |
3475 | \r | |
3476 | int lineno;\r | |
3477 | int col_offset;\r | |
3478 | \r | |
3479 | if (obj == Py_None) {\r | |
3480 | *out = NULL;\r | |
3481 | return 0;\r | |
3482 | }\r | |
3483 | if (PyObject_HasAttrString(obj, "lineno")) {\r | |
3484 | int res;\r | |
3485 | tmp = PyObject_GetAttrString(obj, "lineno");\r | |
3486 | if (tmp == NULL) goto failed;\r | |
3487 | res = obj2ast_int(tmp, &lineno, arena);\r | |
3488 | if (res != 0) goto failed;\r | |
3489 | Py_XDECREF(tmp);\r | |
3490 | tmp = NULL;\r | |
3491 | } else {\r | |
3492 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");\r | |
3493 | return 1;\r | |
3494 | }\r | |
3495 | if (PyObject_HasAttrString(obj, "col_offset")) {\r | |
3496 | int res;\r | |
3497 | tmp = PyObject_GetAttrString(obj, "col_offset");\r | |
3498 | if (tmp == NULL) goto failed;\r | |
3499 | res = obj2ast_int(tmp, &col_offset, arena);\r | |
3500 | if (res != 0) goto failed;\r | |
3501 | Py_XDECREF(tmp);\r | |
3502 | tmp = NULL;\r | |
3503 | } else {\r | |
3504 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");\r | |
3505 | return 1;\r | |
3506 | }\r | |
3507 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);\r | |
3508 | if (isinstance == -1) {\r | |
3509 | return 1;\r | |
3510 | }\r | |
3511 | if (isinstance) {\r | |
3512 | identifier name;\r | |
3513 | arguments_ty args;\r | |
3514 | asdl_seq* body;\r | |
3515 | asdl_seq* decorator_list;\r | |
3516 | \r | |
3517 | if (PyObject_HasAttrString(obj, "name")) {\r | |
3518 | int res;\r | |
3519 | tmp = PyObject_GetAttrString(obj, "name");\r | |
3520 | if (tmp == NULL) goto failed;\r | |
3521 | res = obj2ast_identifier(tmp, &name, arena);\r | |
3522 | if (res != 0) goto failed;\r | |
3523 | Py_XDECREF(tmp);\r | |
3524 | tmp = NULL;\r | |
3525 | } else {\r | |
3526 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");\r | |
3527 | return 1;\r | |
3528 | }\r | |
3529 | if (PyObject_HasAttrString(obj, "args")) {\r | |
3530 | int res;\r | |
3531 | tmp = PyObject_GetAttrString(obj, "args");\r | |
3532 | if (tmp == NULL) goto failed;\r | |
3533 | res = obj2ast_arguments(tmp, &args, arena);\r | |
3534 | if (res != 0) goto failed;\r | |
3535 | Py_XDECREF(tmp);\r | |
3536 | tmp = NULL;\r | |
3537 | } else {\r | |
3538 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");\r | |
3539 | return 1;\r | |
3540 | }\r | |
3541 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3542 | int res;\r | |
3543 | Py_ssize_t len;\r | |
3544 | Py_ssize_t i;\r | |
3545 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3546 | if (tmp == NULL) goto failed;\r | |
3547 | if (!PyList_Check(tmp)) {\r | |
3548 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3549 | goto failed;\r | |
3550 | }\r | |
3551 | len = PyList_GET_SIZE(tmp);\r | |
3552 | body = asdl_seq_new(len, arena);\r | |
3553 | if (body == NULL) goto failed;\r | |
3554 | for (i = 0; i < len; i++) {\r | |
3555 | stmt_ty value;\r | |
3556 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3557 | if (res != 0) goto failed;\r | |
3558 | asdl_seq_SET(body, i, value);\r | |
3559 | }\r | |
3560 | Py_XDECREF(tmp);\r | |
3561 | tmp = NULL;\r | |
3562 | } else {\r | |
3563 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");\r | |
3564 | return 1;\r | |
3565 | }\r | |
3566 | if (PyObject_HasAttrString(obj, "decorator_list")) {\r | |
3567 | int res;\r | |
3568 | Py_ssize_t len;\r | |
3569 | Py_ssize_t i;\r | |
3570 | tmp = PyObject_GetAttrString(obj, "decorator_list");\r | |
3571 | if (tmp == NULL) goto failed;\r | |
3572 | if (!PyList_Check(tmp)) {\r | |
3573 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3574 | goto failed;\r | |
3575 | }\r | |
3576 | len = PyList_GET_SIZE(tmp);\r | |
3577 | decorator_list = asdl_seq_new(len, arena);\r | |
3578 | if (decorator_list == NULL) goto failed;\r | |
3579 | for (i = 0; i < len; i++) {\r | |
3580 | expr_ty value;\r | |
3581 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3582 | if (res != 0) goto failed;\r | |
3583 | asdl_seq_SET(decorator_list, i, value);\r | |
3584 | }\r | |
3585 | Py_XDECREF(tmp);\r | |
3586 | tmp = NULL;\r | |
3587 | } else {\r | |
3588 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");\r | |
3589 | return 1;\r | |
3590 | }\r | |
3591 | *out = FunctionDef(name, args, body, decorator_list, lineno,\r | |
3592 | col_offset, arena);\r | |
3593 | if (*out == NULL) goto failed;\r | |
3594 | return 0;\r | |
3595 | }\r | |
3596 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);\r | |
3597 | if (isinstance == -1) {\r | |
3598 | return 1;\r | |
3599 | }\r | |
3600 | if (isinstance) {\r | |
3601 | identifier name;\r | |
3602 | asdl_seq* bases;\r | |
3603 | asdl_seq* body;\r | |
3604 | asdl_seq* decorator_list;\r | |
3605 | \r | |
3606 | if (PyObject_HasAttrString(obj, "name")) {\r | |
3607 | int res;\r | |
3608 | tmp = PyObject_GetAttrString(obj, "name");\r | |
3609 | if (tmp == NULL) goto failed;\r | |
3610 | res = obj2ast_identifier(tmp, &name, arena);\r | |
3611 | if (res != 0) goto failed;\r | |
3612 | Py_XDECREF(tmp);\r | |
3613 | tmp = NULL;\r | |
3614 | } else {\r | |
3615 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");\r | |
3616 | return 1;\r | |
3617 | }\r | |
3618 | if (PyObject_HasAttrString(obj, "bases")) {\r | |
3619 | int res;\r | |
3620 | Py_ssize_t len;\r | |
3621 | Py_ssize_t i;\r | |
3622 | tmp = PyObject_GetAttrString(obj, "bases");\r | |
3623 | if (tmp == NULL) goto failed;\r | |
3624 | if (!PyList_Check(tmp)) {\r | |
3625 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3626 | goto failed;\r | |
3627 | }\r | |
3628 | len = PyList_GET_SIZE(tmp);\r | |
3629 | bases = asdl_seq_new(len, arena);\r | |
3630 | if (bases == NULL) goto failed;\r | |
3631 | for (i = 0; i < len; i++) {\r | |
3632 | expr_ty value;\r | |
3633 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3634 | if (res != 0) goto failed;\r | |
3635 | asdl_seq_SET(bases, i, value);\r | |
3636 | }\r | |
3637 | Py_XDECREF(tmp);\r | |
3638 | tmp = NULL;\r | |
3639 | } else {\r | |
3640 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");\r | |
3641 | return 1;\r | |
3642 | }\r | |
3643 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3644 | int res;\r | |
3645 | Py_ssize_t len;\r | |
3646 | Py_ssize_t i;\r | |
3647 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3648 | if (tmp == NULL) goto failed;\r | |
3649 | if (!PyList_Check(tmp)) {\r | |
3650 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3651 | goto failed;\r | |
3652 | }\r | |
3653 | len = PyList_GET_SIZE(tmp);\r | |
3654 | body = asdl_seq_new(len, arena);\r | |
3655 | if (body == NULL) goto failed;\r | |
3656 | for (i = 0; i < len; i++) {\r | |
3657 | stmt_ty value;\r | |
3658 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3659 | if (res != 0) goto failed;\r | |
3660 | asdl_seq_SET(body, i, value);\r | |
3661 | }\r | |
3662 | Py_XDECREF(tmp);\r | |
3663 | tmp = NULL;\r | |
3664 | } else {\r | |
3665 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");\r | |
3666 | return 1;\r | |
3667 | }\r | |
3668 | if (PyObject_HasAttrString(obj, "decorator_list")) {\r | |
3669 | int res;\r | |
3670 | Py_ssize_t len;\r | |
3671 | Py_ssize_t i;\r | |
3672 | tmp = PyObject_GetAttrString(obj, "decorator_list");\r | |
3673 | if (tmp == NULL) goto failed;\r | |
3674 | if (!PyList_Check(tmp)) {\r | |
3675 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3676 | goto failed;\r | |
3677 | }\r | |
3678 | len = PyList_GET_SIZE(tmp);\r | |
3679 | decorator_list = asdl_seq_new(len, arena);\r | |
3680 | if (decorator_list == NULL) goto failed;\r | |
3681 | for (i = 0; i < len; i++) {\r | |
3682 | expr_ty value;\r | |
3683 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3684 | if (res != 0) goto failed;\r | |
3685 | asdl_seq_SET(decorator_list, i, value);\r | |
3686 | }\r | |
3687 | Py_XDECREF(tmp);\r | |
3688 | tmp = NULL;\r | |
3689 | } else {\r | |
3690 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");\r | |
3691 | return 1;\r | |
3692 | }\r | |
3693 | *out = ClassDef(name, bases, body, decorator_list, lineno,\r | |
3694 | col_offset, arena);\r | |
3695 | if (*out == NULL) goto failed;\r | |
3696 | return 0;\r | |
3697 | }\r | |
3698 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);\r | |
3699 | if (isinstance == -1) {\r | |
3700 | return 1;\r | |
3701 | }\r | |
3702 | if (isinstance) {\r | |
3703 | expr_ty value;\r | |
3704 | \r | |
3705 | if (PyObject_HasAttrString(obj, "value")) {\r | |
3706 | int res;\r | |
3707 | tmp = PyObject_GetAttrString(obj, "value");\r | |
3708 | if (tmp == NULL) goto failed;\r | |
3709 | res = obj2ast_expr(tmp, &value, arena);\r | |
3710 | if (res != 0) goto failed;\r | |
3711 | Py_XDECREF(tmp);\r | |
3712 | tmp = NULL;\r | |
3713 | } else {\r | |
3714 | value = NULL;\r | |
3715 | }\r | |
3716 | *out = Return(value, lineno, col_offset, arena);\r | |
3717 | if (*out == NULL) goto failed;\r | |
3718 | return 0;\r | |
3719 | }\r | |
3720 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);\r | |
3721 | if (isinstance == -1) {\r | |
3722 | return 1;\r | |
3723 | }\r | |
3724 | if (isinstance) {\r | |
3725 | asdl_seq* targets;\r | |
3726 | \r | |
3727 | if (PyObject_HasAttrString(obj, "targets")) {\r | |
3728 | int res;\r | |
3729 | Py_ssize_t len;\r | |
3730 | Py_ssize_t i;\r | |
3731 | tmp = PyObject_GetAttrString(obj, "targets");\r | |
3732 | if (tmp == NULL) goto failed;\r | |
3733 | if (!PyList_Check(tmp)) {\r | |
3734 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3735 | goto failed;\r | |
3736 | }\r | |
3737 | len = PyList_GET_SIZE(tmp);\r | |
3738 | targets = asdl_seq_new(len, arena);\r | |
3739 | if (targets == NULL) goto failed;\r | |
3740 | for (i = 0; i < len; i++) {\r | |
3741 | expr_ty value;\r | |
3742 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3743 | if (res != 0) goto failed;\r | |
3744 | asdl_seq_SET(targets, i, value);\r | |
3745 | }\r | |
3746 | Py_XDECREF(tmp);\r | |
3747 | tmp = NULL;\r | |
3748 | } else {\r | |
3749 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");\r | |
3750 | return 1;\r | |
3751 | }\r | |
3752 | *out = Delete(targets, lineno, col_offset, arena);\r | |
3753 | if (*out == NULL) goto failed;\r | |
3754 | return 0;\r | |
3755 | }\r | |
3756 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);\r | |
3757 | if (isinstance == -1) {\r | |
3758 | return 1;\r | |
3759 | }\r | |
3760 | if (isinstance) {\r | |
3761 | asdl_seq* targets;\r | |
3762 | expr_ty value;\r | |
3763 | \r | |
3764 | if (PyObject_HasAttrString(obj, "targets")) {\r | |
3765 | int res;\r | |
3766 | Py_ssize_t len;\r | |
3767 | Py_ssize_t i;\r | |
3768 | tmp = PyObject_GetAttrString(obj, "targets");\r | |
3769 | if (tmp == NULL) goto failed;\r | |
3770 | if (!PyList_Check(tmp)) {\r | |
3771 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3772 | goto failed;\r | |
3773 | }\r | |
3774 | len = PyList_GET_SIZE(tmp);\r | |
3775 | targets = asdl_seq_new(len, arena);\r | |
3776 | if (targets == NULL) goto failed;\r | |
3777 | for (i = 0; i < len; i++) {\r | |
3778 | expr_ty value;\r | |
3779 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3780 | if (res != 0) goto failed;\r | |
3781 | asdl_seq_SET(targets, i, value);\r | |
3782 | }\r | |
3783 | Py_XDECREF(tmp);\r | |
3784 | tmp = NULL;\r | |
3785 | } else {\r | |
3786 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");\r | |
3787 | return 1;\r | |
3788 | }\r | |
3789 | if (PyObject_HasAttrString(obj, "value")) {\r | |
3790 | int res;\r | |
3791 | tmp = PyObject_GetAttrString(obj, "value");\r | |
3792 | if (tmp == NULL) goto failed;\r | |
3793 | res = obj2ast_expr(tmp, &value, arena);\r | |
3794 | if (res != 0) goto failed;\r | |
3795 | Py_XDECREF(tmp);\r | |
3796 | tmp = NULL;\r | |
3797 | } else {\r | |
3798 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");\r | |
3799 | return 1;\r | |
3800 | }\r | |
3801 | *out = Assign(targets, value, lineno, col_offset, arena);\r | |
3802 | if (*out == NULL) goto failed;\r | |
3803 | return 0;\r | |
3804 | }\r | |
3805 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);\r | |
3806 | if (isinstance == -1) {\r | |
3807 | return 1;\r | |
3808 | }\r | |
3809 | if (isinstance) {\r | |
3810 | expr_ty target;\r | |
3811 | operator_ty op;\r | |
3812 | expr_ty value;\r | |
3813 | \r | |
3814 | if (PyObject_HasAttrString(obj, "target")) {\r | |
3815 | int res;\r | |
3816 | tmp = PyObject_GetAttrString(obj, "target");\r | |
3817 | if (tmp == NULL) goto failed;\r | |
3818 | res = obj2ast_expr(tmp, &target, arena);\r | |
3819 | if (res != 0) goto failed;\r | |
3820 | Py_XDECREF(tmp);\r | |
3821 | tmp = NULL;\r | |
3822 | } else {\r | |
3823 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");\r | |
3824 | return 1;\r | |
3825 | }\r | |
3826 | if (PyObject_HasAttrString(obj, "op")) {\r | |
3827 | int res;\r | |
3828 | tmp = PyObject_GetAttrString(obj, "op");\r | |
3829 | if (tmp == NULL) goto failed;\r | |
3830 | res = obj2ast_operator(tmp, &op, arena);\r | |
3831 | if (res != 0) goto failed;\r | |
3832 | Py_XDECREF(tmp);\r | |
3833 | tmp = NULL;\r | |
3834 | } else {\r | |
3835 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");\r | |
3836 | return 1;\r | |
3837 | }\r | |
3838 | if (PyObject_HasAttrString(obj, "value")) {\r | |
3839 | int res;\r | |
3840 | tmp = PyObject_GetAttrString(obj, "value");\r | |
3841 | if (tmp == NULL) goto failed;\r | |
3842 | res = obj2ast_expr(tmp, &value, arena);\r | |
3843 | if (res != 0) goto failed;\r | |
3844 | Py_XDECREF(tmp);\r | |
3845 | tmp = NULL;\r | |
3846 | } else {\r | |
3847 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");\r | |
3848 | return 1;\r | |
3849 | }\r | |
3850 | *out = AugAssign(target, op, value, lineno, col_offset, arena);\r | |
3851 | if (*out == NULL) goto failed;\r | |
3852 | return 0;\r | |
3853 | }\r | |
3854 | isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);\r | |
3855 | if (isinstance == -1) {\r | |
3856 | return 1;\r | |
3857 | }\r | |
3858 | if (isinstance) {\r | |
3859 | expr_ty dest;\r | |
3860 | asdl_seq* values;\r | |
3861 | bool nl;\r | |
3862 | \r | |
3863 | if (PyObject_HasAttrString(obj, "dest")) {\r | |
3864 | int res;\r | |
3865 | tmp = PyObject_GetAttrString(obj, "dest");\r | |
3866 | if (tmp == NULL) goto failed;\r | |
3867 | res = obj2ast_expr(tmp, &dest, arena);\r | |
3868 | if (res != 0) goto failed;\r | |
3869 | Py_XDECREF(tmp);\r | |
3870 | tmp = NULL;\r | |
3871 | } else {\r | |
3872 | dest = NULL;\r | |
3873 | }\r | |
3874 | if (PyObject_HasAttrString(obj, "values")) {\r | |
3875 | int res;\r | |
3876 | Py_ssize_t len;\r | |
3877 | Py_ssize_t i;\r | |
3878 | tmp = PyObject_GetAttrString(obj, "values");\r | |
3879 | if (tmp == NULL) goto failed;\r | |
3880 | if (!PyList_Check(tmp)) {\r | |
3881 | PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3882 | goto failed;\r | |
3883 | }\r | |
3884 | len = PyList_GET_SIZE(tmp);\r | |
3885 | values = asdl_seq_new(len, arena);\r | |
3886 | if (values == NULL) goto failed;\r | |
3887 | for (i = 0; i < len; i++) {\r | |
3888 | expr_ty value;\r | |
3889 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3890 | if (res != 0) goto failed;\r | |
3891 | asdl_seq_SET(values, i, value);\r | |
3892 | }\r | |
3893 | Py_XDECREF(tmp);\r | |
3894 | tmp = NULL;\r | |
3895 | } else {\r | |
3896 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");\r | |
3897 | return 1;\r | |
3898 | }\r | |
3899 | if (PyObject_HasAttrString(obj, "nl")) {\r | |
3900 | int res;\r | |
3901 | tmp = PyObject_GetAttrString(obj, "nl");\r | |
3902 | if (tmp == NULL) goto failed;\r | |
3903 | res = obj2ast_bool(tmp, &nl, arena);\r | |
3904 | if (res != 0) goto failed;\r | |
3905 | Py_XDECREF(tmp);\r | |
3906 | tmp = NULL;\r | |
3907 | } else {\r | |
3908 | PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");\r | |
3909 | return 1;\r | |
3910 | }\r | |
3911 | *out = Print(dest, values, nl, lineno, col_offset, arena);\r | |
3912 | if (*out == NULL) goto failed;\r | |
3913 | return 0;\r | |
3914 | }\r | |
3915 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);\r | |
3916 | if (isinstance == -1) {\r | |
3917 | return 1;\r | |
3918 | }\r | |
3919 | if (isinstance) {\r | |
3920 | expr_ty target;\r | |
3921 | expr_ty iter;\r | |
3922 | asdl_seq* body;\r | |
3923 | asdl_seq* orelse;\r | |
3924 | \r | |
3925 | if (PyObject_HasAttrString(obj, "target")) {\r | |
3926 | int res;\r | |
3927 | tmp = PyObject_GetAttrString(obj, "target");\r | |
3928 | if (tmp == NULL) goto failed;\r | |
3929 | res = obj2ast_expr(tmp, &target, arena);\r | |
3930 | if (res != 0) goto failed;\r | |
3931 | Py_XDECREF(tmp);\r | |
3932 | tmp = NULL;\r | |
3933 | } else {\r | |
3934 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");\r | |
3935 | return 1;\r | |
3936 | }\r | |
3937 | if (PyObject_HasAttrString(obj, "iter")) {\r | |
3938 | int res;\r | |
3939 | tmp = PyObject_GetAttrString(obj, "iter");\r | |
3940 | if (tmp == NULL) goto failed;\r | |
3941 | res = obj2ast_expr(tmp, &iter, arena);\r | |
3942 | if (res != 0) goto failed;\r | |
3943 | Py_XDECREF(tmp);\r | |
3944 | tmp = NULL;\r | |
3945 | } else {\r | |
3946 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");\r | |
3947 | return 1;\r | |
3948 | }\r | |
3949 | if (PyObject_HasAttrString(obj, "body")) {\r | |
3950 | int res;\r | |
3951 | Py_ssize_t len;\r | |
3952 | Py_ssize_t i;\r | |
3953 | tmp = PyObject_GetAttrString(obj, "body");\r | |
3954 | if (tmp == NULL) goto failed;\r | |
3955 | if (!PyList_Check(tmp)) {\r | |
3956 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3957 | goto failed;\r | |
3958 | }\r | |
3959 | len = PyList_GET_SIZE(tmp);\r | |
3960 | body = asdl_seq_new(len, arena);\r | |
3961 | if (body == NULL) goto failed;\r | |
3962 | for (i = 0; i < len; i++) {\r | |
3963 | stmt_ty value;\r | |
3964 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3965 | if (res != 0) goto failed;\r | |
3966 | asdl_seq_SET(body, i, value);\r | |
3967 | }\r | |
3968 | Py_XDECREF(tmp);\r | |
3969 | tmp = NULL;\r | |
3970 | } else {\r | |
3971 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");\r | |
3972 | return 1;\r | |
3973 | }\r | |
3974 | if (PyObject_HasAttrString(obj, "orelse")) {\r | |
3975 | int res;\r | |
3976 | Py_ssize_t len;\r | |
3977 | Py_ssize_t i;\r | |
3978 | tmp = PyObject_GetAttrString(obj, "orelse");\r | |
3979 | if (tmp == NULL) goto failed;\r | |
3980 | if (!PyList_Check(tmp)) {\r | |
3981 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
3982 | goto failed;\r | |
3983 | }\r | |
3984 | len = PyList_GET_SIZE(tmp);\r | |
3985 | orelse = asdl_seq_new(len, arena);\r | |
3986 | if (orelse == NULL) goto failed;\r | |
3987 | for (i = 0; i < len; i++) {\r | |
3988 | stmt_ty value;\r | |
3989 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
3990 | if (res != 0) goto failed;\r | |
3991 | asdl_seq_SET(orelse, i, value);\r | |
3992 | }\r | |
3993 | Py_XDECREF(tmp);\r | |
3994 | tmp = NULL;\r | |
3995 | } else {\r | |
3996 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");\r | |
3997 | return 1;\r | |
3998 | }\r | |
3999 | *out = For(target, iter, body, orelse, lineno, col_offset,\r | |
4000 | arena);\r | |
4001 | if (*out == NULL) goto failed;\r | |
4002 | return 0;\r | |
4003 | }\r | |
4004 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);\r | |
4005 | if (isinstance == -1) {\r | |
4006 | return 1;\r | |
4007 | }\r | |
4008 | if (isinstance) {\r | |
4009 | expr_ty test;\r | |
4010 | asdl_seq* body;\r | |
4011 | asdl_seq* orelse;\r | |
4012 | \r | |
4013 | if (PyObject_HasAttrString(obj, "test")) {\r | |
4014 | int res;\r | |
4015 | tmp = PyObject_GetAttrString(obj, "test");\r | |
4016 | if (tmp == NULL) goto failed;\r | |
4017 | res = obj2ast_expr(tmp, &test, arena);\r | |
4018 | if (res != 0) goto failed;\r | |
4019 | Py_XDECREF(tmp);\r | |
4020 | tmp = NULL;\r | |
4021 | } else {\r | |
4022 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");\r | |
4023 | return 1;\r | |
4024 | }\r | |
4025 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4026 | int res;\r | |
4027 | Py_ssize_t len;\r | |
4028 | Py_ssize_t i;\r | |
4029 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4030 | if (tmp == NULL) goto failed;\r | |
4031 | if (!PyList_Check(tmp)) {\r | |
4032 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4033 | goto failed;\r | |
4034 | }\r | |
4035 | len = PyList_GET_SIZE(tmp);\r | |
4036 | body = asdl_seq_new(len, arena);\r | |
4037 | if (body == NULL) goto failed;\r | |
4038 | for (i = 0; i < len; i++) {\r | |
4039 | stmt_ty value;\r | |
4040 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4041 | if (res != 0) goto failed;\r | |
4042 | asdl_seq_SET(body, i, value);\r | |
4043 | }\r | |
4044 | Py_XDECREF(tmp);\r | |
4045 | tmp = NULL;\r | |
4046 | } else {\r | |
4047 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");\r | |
4048 | return 1;\r | |
4049 | }\r | |
4050 | if (PyObject_HasAttrString(obj, "orelse")) {\r | |
4051 | int res;\r | |
4052 | Py_ssize_t len;\r | |
4053 | Py_ssize_t i;\r | |
4054 | tmp = PyObject_GetAttrString(obj, "orelse");\r | |
4055 | if (tmp == NULL) goto failed;\r | |
4056 | if (!PyList_Check(tmp)) {\r | |
4057 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4058 | goto failed;\r | |
4059 | }\r | |
4060 | len = PyList_GET_SIZE(tmp);\r | |
4061 | orelse = asdl_seq_new(len, arena);\r | |
4062 | if (orelse == NULL) goto failed;\r | |
4063 | for (i = 0; i < len; i++) {\r | |
4064 | stmt_ty value;\r | |
4065 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4066 | if (res != 0) goto failed;\r | |
4067 | asdl_seq_SET(orelse, i, value);\r | |
4068 | }\r | |
4069 | Py_XDECREF(tmp);\r | |
4070 | tmp = NULL;\r | |
4071 | } else {\r | |
4072 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");\r | |
4073 | return 1;\r | |
4074 | }\r | |
4075 | *out = While(test, body, orelse, lineno, col_offset, arena);\r | |
4076 | if (*out == NULL) goto failed;\r | |
4077 | return 0;\r | |
4078 | }\r | |
4079 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);\r | |
4080 | if (isinstance == -1) {\r | |
4081 | return 1;\r | |
4082 | }\r | |
4083 | if (isinstance) {\r | |
4084 | expr_ty test;\r | |
4085 | asdl_seq* body;\r | |
4086 | asdl_seq* orelse;\r | |
4087 | \r | |
4088 | if (PyObject_HasAttrString(obj, "test")) {\r | |
4089 | int res;\r | |
4090 | tmp = PyObject_GetAttrString(obj, "test");\r | |
4091 | if (tmp == NULL) goto failed;\r | |
4092 | res = obj2ast_expr(tmp, &test, arena);\r | |
4093 | if (res != 0) goto failed;\r | |
4094 | Py_XDECREF(tmp);\r | |
4095 | tmp = NULL;\r | |
4096 | } else {\r | |
4097 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");\r | |
4098 | return 1;\r | |
4099 | }\r | |
4100 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4101 | int res;\r | |
4102 | Py_ssize_t len;\r | |
4103 | Py_ssize_t i;\r | |
4104 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4105 | if (tmp == NULL) goto failed;\r | |
4106 | if (!PyList_Check(tmp)) {\r | |
4107 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4108 | goto failed;\r | |
4109 | }\r | |
4110 | len = PyList_GET_SIZE(tmp);\r | |
4111 | body = asdl_seq_new(len, arena);\r | |
4112 | if (body == NULL) goto failed;\r | |
4113 | for (i = 0; i < len; i++) {\r | |
4114 | stmt_ty value;\r | |
4115 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4116 | if (res != 0) goto failed;\r | |
4117 | asdl_seq_SET(body, i, value);\r | |
4118 | }\r | |
4119 | Py_XDECREF(tmp);\r | |
4120 | tmp = NULL;\r | |
4121 | } else {\r | |
4122 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");\r | |
4123 | return 1;\r | |
4124 | }\r | |
4125 | if (PyObject_HasAttrString(obj, "orelse")) {\r | |
4126 | int res;\r | |
4127 | Py_ssize_t len;\r | |
4128 | Py_ssize_t i;\r | |
4129 | tmp = PyObject_GetAttrString(obj, "orelse");\r | |
4130 | if (tmp == NULL) goto failed;\r | |
4131 | if (!PyList_Check(tmp)) {\r | |
4132 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4133 | goto failed;\r | |
4134 | }\r | |
4135 | len = PyList_GET_SIZE(tmp);\r | |
4136 | orelse = asdl_seq_new(len, arena);\r | |
4137 | if (orelse == NULL) goto failed;\r | |
4138 | for (i = 0; i < len; i++) {\r | |
4139 | stmt_ty value;\r | |
4140 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4141 | if (res != 0) goto failed;\r | |
4142 | asdl_seq_SET(orelse, i, value);\r | |
4143 | }\r | |
4144 | Py_XDECREF(tmp);\r | |
4145 | tmp = NULL;\r | |
4146 | } else {\r | |
4147 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");\r | |
4148 | return 1;\r | |
4149 | }\r | |
4150 | *out = If(test, body, orelse, lineno, col_offset, arena);\r | |
4151 | if (*out == NULL) goto failed;\r | |
4152 | return 0;\r | |
4153 | }\r | |
4154 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);\r | |
4155 | if (isinstance == -1) {\r | |
4156 | return 1;\r | |
4157 | }\r | |
4158 | if (isinstance) {\r | |
4159 | expr_ty context_expr;\r | |
4160 | expr_ty optional_vars;\r | |
4161 | asdl_seq* body;\r | |
4162 | \r | |
4163 | if (PyObject_HasAttrString(obj, "context_expr")) {\r | |
4164 | int res;\r | |
4165 | tmp = PyObject_GetAttrString(obj, "context_expr");\r | |
4166 | if (tmp == NULL) goto failed;\r | |
4167 | res = obj2ast_expr(tmp, &context_expr, arena);\r | |
4168 | if (res != 0) goto failed;\r | |
4169 | Py_XDECREF(tmp);\r | |
4170 | tmp = NULL;\r | |
4171 | } else {\r | |
4172 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");\r | |
4173 | return 1;\r | |
4174 | }\r | |
4175 | if (PyObject_HasAttrString(obj, "optional_vars")) {\r | |
4176 | int res;\r | |
4177 | tmp = PyObject_GetAttrString(obj, "optional_vars");\r | |
4178 | if (tmp == NULL) goto failed;\r | |
4179 | res = obj2ast_expr(tmp, &optional_vars, arena);\r | |
4180 | if (res != 0) goto failed;\r | |
4181 | Py_XDECREF(tmp);\r | |
4182 | tmp = NULL;\r | |
4183 | } else {\r | |
4184 | optional_vars = NULL;\r | |
4185 | }\r | |
4186 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4187 | int res;\r | |
4188 | Py_ssize_t len;\r | |
4189 | Py_ssize_t i;\r | |
4190 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4191 | if (tmp == NULL) goto failed;\r | |
4192 | if (!PyList_Check(tmp)) {\r | |
4193 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4194 | goto failed;\r | |
4195 | }\r | |
4196 | len = PyList_GET_SIZE(tmp);\r | |
4197 | body = asdl_seq_new(len, arena);\r | |
4198 | if (body == NULL) goto failed;\r | |
4199 | for (i = 0; i < len; i++) {\r | |
4200 | stmt_ty value;\r | |
4201 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4202 | if (res != 0) goto failed;\r | |
4203 | asdl_seq_SET(body, i, value);\r | |
4204 | }\r | |
4205 | Py_XDECREF(tmp);\r | |
4206 | tmp = NULL;\r | |
4207 | } else {\r | |
4208 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");\r | |
4209 | return 1;\r | |
4210 | }\r | |
4211 | *out = With(context_expr, optional_vars, body, lineno,\r | |
4212 | col_offset, arena);\r | |
4213 | if (*out == NULL) goto failed;\r | |
4214 | return 0;\r | |
4215 | }\r | |
4216 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);\r | |
4217 | if (isinstance == -1) {\r | |
4218 | return 1;\r | |
4219 | }\r | |
4220 | if (isinstance) {\r | |
4221 | expr_ty type;\r | |
4222 | expr_ty inst;\r | |
4223 | expr_ty tback;\r | |
4224 | \r | |
4225 | if (PyObject_HasAttrString(obj, "type")) {\r | |
4226 | int res;\r | |
4227 | tmp = PyObject_GetAttrString(obj, "type");\r | |
4228 | if (tmp == NULL) goto failed;\r | |
4229 | res = obj2ast_expr(tmp, &type, arena);\r | |
4230 | if (res != 0) goto failed;\r | |
4231 | Py_XDECREF(tmp);\r | |
4232 | tmp = NULL;\r | |
4233 | } else {\r | |
4234 | type = NULL;\r | |
4235 | }\r | |
4236 | if (PyObject_HasAttrString(obj, "inst")) {\r | |
4237 | int res;\r | |
4238 | tmp = PyObject_GetAttrString(obj, "inst");\r | |
4239 | if (tmp == NULL) goto failed;\r | |
4240 | res = obj2ast_expr(tmp, &inst, arena);\r | |
4241 | if (res != 0) goto failed;\r | |
4242 | Py_XDECREF(tmp);\r | |
4243 | tmp = NULL;\r | |
4244 | } else {\r | |
4245 | inst = NULL;\r | |
4246 | }\r | |
4247 | if (PyObject_HasAttrString(obj, "tback")) {\r | |
4248 | int res;\r | |
4249 | tmp = PyObject_GetAttrString(obj, "tback");\r | |
4250 | if (tmp == NULL) goto failed;\r | |
4251 | res = obj2ast_expr(tmp, &tback, arena);\r | |
4252 | if (res != 0) goto failed;\r | |
4253 | Py_XDECREF(tmp);\r | |
4254 | tmp = NULL;\r | |
4255 | } else {\r | |
4256 | tback = NULL;\r | |
4257 | }\r | |
4258 | *out = Raise(type, inst, tback, lineno, col_offset, arena);\r | |
4259 | if (*out == NULL) goto failed;\r | |
4260 | return 0;\r | |
4261 | }\r | |
4262 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);\r | |
4263 | if (isinstance == -1) {\r | |
4264 | return 1;\r | |
4265 | }\r | |
4266 | if (isinstance) {\r | |
4267 | asdl_seq* body;\r | |
4268 | asdl_seq* handlers;\r | |
4269 | asdl_seq* orelse;\r | |
4270 | \r | |
4271 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4272 | int res;\r | |
4273 | Py_ssize_t len;\r | |
4274 | Py_ssize_t i;\r | |
4275 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4276 | if (tmp == NULL) goto failed;\r | |
4277 | if (!PyList_Check(tmp)) {\r | |
4278 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4279 | goto failed;\r | |
4280 | }\r | |
4281 | len = PyList_GET_SIZE(tmp);\r | |
4282 | body = asdl_seq_new(len, arena);\r | |
4283 | if (body == NULL) goto failed;\r | |
4284 | for (i = 0; i < len; i++) {\r | |
4285 | stmt_ty value;\r | |
4286 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4287 | if (res != 0) goto failed;\r | |
4288 | asdl_seq_SET(body, i, value);\r | |
4289 | }\r | |
4290 | Py_XDECREF(tmp);\r | |
4291 | tmp = NULL;\r | |
4292 | } else {\r | |
4293 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");\r | |
4294 | return 1;\r | |
4295 | }\r | |
4296 | if (PyObject_HasAttrString(obj, "handlers")) {\r | |
4297 | int res;\r | |
4298 | Py_ssize_t len;\r | |
4299 | Py_ssize_t i;\r | |
4300 | tmp = PyObject_GetAttrString(obj, "handlers");\r | |
4301 | if (tmp == NULL) goto failed;\r | |
4302 | if (!PyList_Check(tmp)) {\r | |
4303 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4304 | goto failed;\r | |
4305 | }\r | |
4306 | len = PyList_GET_SIZE(tmp);\r | |
4307 | handlers = asdl_seq_new(len, arena);\r | |
4308 | if (handlers == NULL) goto failed;\r | |
4309 | for (i = 0; i < len; i++) {\r | |
4310 | excepthandler_ty value;\r | |
4311 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4312 | if (res != 0) goto failed;\r | |
4313 | asdl_seq_SET(handlers, i, value);\r | |
4314 | }\r | |
4315 | Py_XDECREF(tmp);\r | |
4316 | tmp = NULL;\r | |
4317 | } else {\r | |
4318 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");\r | |
4319 | return 1;\r | |
4320 | }\r | |
4321 | if (PyObject_HasAttrString(obj, "orelse")) {\r | |
4322 | int res;\r | |
4323 | Py_ssize_t len;\r | |
4324 | Py_ssize_t i;\r | |
4325 | tmp = PyObject_GetAttrString(obj, "orelse");\r | |
4326 | if (tmp == NULL) goto failed;\r | |
4327 | if (!PyList_Check(tmp)) {\r | |
4328 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4329 | goto failed;\r | |
4330 | }\r | |
4331 | len = PyList_GET_SIZE(tmp);\r | |
4332 | orelse = asdl_seq_new(len, arena);\r | |
4333 | if (orelse == NULL) goto failed;\r | |
4334 | for (i = 0; i < len; i++) {\r | |
4335 | stmt_ty value;\r | |
4336 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4337 | if (res != 0) goto failed;\r | |
4338 | asdl_seq_SET(orelse, i, value);\r | |
4339 | }\r | |
4340 | Py_XDECREF(tmp);\r | |
4341 | tmp = NULL;\r | |
4342 | } else {\r | |
4343 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");\r | |
4344 | return 1;\r | |
4345 | }\r | |
4346 | *out = TryExcept(body, handlers, orelse, lineno, col_offset,\r | |
4347 | arena);\r | |
4348 | if (*out == NULL) goto failed;\r | |
4349 | return 0;\r | |
4350 | }\r | |
4351 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);\r | |
4352 | if (isinstance == -1) {\r | |
4353 | return 1;\r | |
4354 | }\r | |
4355 | if (isinstance) {\r | |
4356 | asdl_seq* body;\r | |
4357 | asdl_seq* finalbody;\r | |
4358 | \r | |
4359 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4360 | int res;\r | |
4361 | Py_ssize_t len;\r | |
4362 | Py_ssize_t i;\r | |
4363 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4364 | if (tmp == NULL) goto failed;\r | |
4365 | if (!PyList_Check(tmp)) {\r | |
4366 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4367 | goto failed;\r | |
4368 | }\r | |
4369 | len = PyList_GET_SIZE(tmp);\r | |
4370 | body = asdl_seq_new(len, arena);\r | |
4371 | if (body == NULL) goto failed;\r | |
4372 | for (i = 0; i < len; i++) {\r | |
4373 | stmt_ty value;\r | |
4374 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4375 | if (res != 0) goto failed;\r | |
4376 | asdl_seq_SET(body, i, value);\r | |
4377 | }\r | |
4378 | Py_XDECREF(tmp);\r | |
4379 | tmp = NULL;\r | |
4380 | } else {\r | |
4381 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");\r | |
4382 | return 1;\r | |
4383 | }\r | |
4384 | if (PyObject_HasAttrString(obj, "finalbody")) {\r | |
4385 | int res;\r | |
4386 | Py_ssize_t len;\r | |
4387 | Py_ssize_t i;\r | |
4388 | tmp = PyObject_GetAttrString(obj, "finalbody");\r | |
4389 | if (tmp == NULL) goto failed;\r | |
4390 | if (!PyList_Check(tmp)) {\r | |
4391 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4392 | goto failed;\r | |
4393 | }\r | |
4394 | len = PyList_GET_SIZE(tmp);\r | |
4395 | finalbody = asdl_seq_new(len, arena);\r | |
4396 | if (finalbody == NULL) goto failed;\r | |
4397 | for (i = 0; i < len; i++) {\r | |
4398 | stmt_ty value;\r | |
4399 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4400 | if (res != 0) goto failed;\r | |
4401 | asdl_seq_SET(finalbody, i, value);\r | |
4402 | }\r | |
4403 | Py_XDECREF(tmp);\r | |
4404 | tmp = NULL;\r | |
4405 | } else {\r | |
4406 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");\r | |
4407 | return 1;\r | |
4408 | }\r | |
4409 | *out = TryFinally(body, finalbody, lineno, col_offset, arena);\r | |
4410 | if (*out == NULL) goto failed;\r | |
4411 | return 0;\r | |
4412 | }\r | |
4413 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);\r | |
4414 | if (isinstance == -1) {\r | |
4415 | return 1;\r | |
4416 | }\r | |
4417 | if (isinstance) {\r | |
4418 | expr_ty test;\r | |
4419 | expr_ty msg;\r | |
4420 | \r | |
4421 | if (PyObject_HasAttrString(obj, "test")) {\r | |
4422 | int res;\r | |
4423 | tmp = PyObject_GetAttrString(obj, "test");\r | |
4424 | if (tmp == NULL) goto failed;\r | |
4425 | res = obj2ast_expr(tmp, &test, arena);\r | |
4426 | if (res != 0) goto failed;\r | |
4427 | Py_XDECREF(tmp);\r | |
4428 | tmp = NULL;\r | |
4429 | } else {\r | |
4430 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");\r | |
4431 | return 1;\r | |
4432 | }\r | |
4433 | if (PyObject_HasAttrString(obj, "msg")) {\r | |
4434 | int res;\r | |
4435 | tmp = PyObject_GetAttrString(obj, "msg");\r | |
4436 | if (tmp == NULL) goto failed;\r | |
4437 | res = obj2ast_expr(tmp, &msg, arena);\r | |
4438 | if (res != 0) goto failed;\r | |
4439 | Py_XDECREF(tmp);\r | |
4440 | tmp = NULL;\r | |
4441 | } else {\r | |
4442 | msg = NULL;\r | |
4443 | }\r | |
4444 | *out = Assert(test, msg, lineno, col_offset, arena);\r | |
4445 | if (*out == NULL) goto failed;\r | |
4446 | return 0;\r | |
4447 | }\r | |
4448 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);\r | |
4449 | if (isinstance == -1) {\r | |
4450 | return 1;\r | |
4451 | }\r | |
4452 | if (isinstance) {\r | |
4453 | asdl_seq* names;\r | |
4454 | \r | |
4455 | if (PyObject_HasAttrString(obj, "names")) {\r | |
4456 | int res;\r | |
4457 | Py_ssize_t len;\r | |
4458 | Py_ssize_t i;\r | |
4459 | tmp = PyObject_GetAttrString(obj, "names");\r | |
4460 | if (tmp == NULL) goto failed;\r | |
4461 | if (!PyList_Check(tmp)) {\r | |
4462 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4463 | goto failed;\r | |
4464 | }\r | |
4465 | len = PyList_GET_SIZE(tmp);\r | |
4466 | names = asdl_seq_new(len, arena);\r | |
4467 | if (names == NULL) goto failed;\r | |
4468 | for (i = 0; i < len; i++) {\r | |
4469 | alias_ty value;\r | |
4470 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4471 | if (res != 0) goto failed;\r | |
4472 | asdl_seq_SET(names, i, value);\r | |
4473 | }\r | |
4474 | Py_XDECREF(tmp);\r | |
4475 | tmp = NULL;\r | |
4476 | } else {\r | |
4477 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");\r | |
4478 | return 1;\r | |
4479 | }\r | |
4480 | *out = Import(names, lineno, col_offset, arena);\r | |
4481 | if (*out == NULL) goto failed;\r | |
4482 | return 0;\r | |
4483 | }\r | |
4484 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);\r | |
4485 | if (isinstance == -1) {\r | |
4486 | return 1;\r | |
4487 | }\r | |
4488 | if (isinstance) {\r | |
4489 | identifier module;\r | |
4490 | asdl_seq* names;\r | |
4491 | int level;\r | |
4492 | \r | |
4493 | if (PyObject_HasAttrString(obj, "module")) {\r | |
4494 | int res;\r | |
4495 | tmp = PyObject_GetAttrString(obj, "module");\r | |
4496 | if (tmp == NULL) goto failed;\r | |
4497 | res = obj2ast_identifier(tmp, &module, arena);\r | |
4498 | if (res != 0) goto failed;\r | |
4499 | Py_XDECREF(tmp);\r | |
4500 | tmp = NULL;\r | |
4501 | } else {\r | |
4502 | module = NULL;\r | |
4503 | }\r | |
4504 | if (PyObject_HasAttrString(obj, "names")) {\r | |
4505 | int res;\r | |
4506 | Py_ssize_t len;\r | |
4507 | Py_ssize_t i;\r | |
4508 | tmp = PyObject_GetAttrString(obj, "names");\r | |
4509 | if (tmp == NULL) goto failed;\r | |
4510 | if (!PyList_Check(tmp)) {\r | |
4511 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4512 | goto failed;\r | |
4513 | }\r | |
4514 | len = PyList_GET_SIZE(tmp);\r | |
4515 | names = asdl_seq_new(len, arena);\r | |
4516 | if (names == NULL) goto failed;\r | |
4517 | for (i = 0; i < len; i++) {\r | |
4518 | alias_ty value;\r | |
4519 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4520 | if (res != 0) goto failed;\r | |
4521 | asdl_seq_SET(names, i, value);\r | |
4522 | }\r | |
4523 | Py_XDECREF(tmp);\r | |
4524 | tmp = NULL;\r | |
4525 | } else {\r | |
4526 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");\r | |
4527 | return 1;\r | |
4528 | }\r | |
4529 | if (PyObject_HasAttrString(obj, "level")) {\r | |
4530 | int res;\r | |
4531 | tmp = PyObject_GetAttrString(obj, "level");\r | |
4532 | if (tmp == NULL) goto failed;\r | |
4533 | res = obj2ast_int(tmp, &level, arena);\r | |
4534 | if (res != 0) goto failed;\r | |
4535 | Py_XDECREF(tmp);\r | |
4536 | tmp = NULL;\r | |
4537 | } else {\r | |
4538 | level = 0;\r | |
4539 | }\r | |
4540 | *out = ImportFrom(module, names, level, lineno, col_offset,\r | |
4541 | arena);\r | |
4542 | if (*out == NULL) goto failed;\r | |
4543 | return 0;\r | |
4544 | }\r | |
4545 | isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);\r | |
4546 | if (isinstance == -1) {\r | |
4547 | return 1;\r | |
4548 | }\r | |
4549 | if (isinstance) {\r | |
4550 | expr_ty body;\r | |
4551 | expr_ty globals;\r | |
4552 | expr_ty locals;\r | |
4553 | \r | |
4554 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4555 | int res;\r | |
4556 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4557 | if (tmp == NULL) goto failed;\r | |
4558 | res = obj2ast_expr(tmp, &body, arena);\r | |
4559 | if (res != 0) goto failed;\r | |
4560 | Py_XDECREF(tmp);\r | |
4561 | tmp = NULL;\r | |
4562 | } else {\r | |
4563 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");\r | |
4564 | return 1;\r | |
4565 | }\r | |
4566 | if (PyObject_HasAttrString(obj, "globals")) {\r | |
4567 | int res;\r | |
4568 | tmp = PyObject_GetAttrString(obj, "globals");\r | |
4569 | if (tmp == NULL) goto failed;\r | |
4570 | res = obj2ast_expr(tmp, &globals, arena);\r | |
4571 | if (res != 0) goto failed;\r | |
4572 | Py_XDECREF(tmp);\r | |
4573 | tmp = NULL;\r | |
4574 | } else {\r | |
4575 | globals = NULL;\r | |
4576 | }\r | |
4577 | if (PyObject_HasAttrString(obj, "locals")) {\r | |
4578 | int res;\r | |
4579 | tmp = PyObject_GetAttrString(obj, "locals");\r | |
4580 | if (tmp == NULL) goto failed;\r | |
4581 | res = obj2ast_expr(tmp, &locals, arena);\r | |
4582 | if (res != 0) goto failed;\r | |
4583 | Py_XDECREF(tmp);\r | |
4584 | tmp = NULL;\r | |
4585 | } else {\r | |
4586 | locals = NULL;\r | |
4587 | }\r | |
4588 | *out = Exec(body, globals, locals, lineno, col_offset, arena);\r | |
4589 | if (*out == NULL) goto failed;\r | |
4590 | return 0;\r | |
4591 | }\r | |
4592 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);\r | |
4593 | if (isinstance == -1) {\r | |
4594 | return 1;\r | |
4595 | }\r | |
4596 | if (isinstance) {\r | |
4597 | asdl_seq* names;\r | |
4598 | \r | |
4599 | if (PyObject_HasAttrString(obj, "names")) {\r | |
4600 | int res;\r | |
4601 | Py_ssize_t len;\r | |
4602 | Py_ssize_t i;\r | |
4603 | tmp = PyObject_GetAttrString(obj, "names");\r | |
4604 | if (tmp == NULL) goto failed;\r | |
4605 | if (!PyList_Check(tmp)) {\r | |
4606 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4607 | goto failed;\r | |
4608 | }\r | |
4609 | len = PyList_GET_SIZE(tmp);\r | |
4610 | names = asdl_seq_new(len, arena);\r | |
4611 | if (names == NULL) goto failed;\r | |
4612 | for (i = 0; i < len; i++) {\r | |
4613 | identifier value;\r | |
4614 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4615 | if (res != 0) goto failed;\r | |
4616 | asdl_seq_SET(names, i, value);\r | |
4617 | }\r | |
4618 | Py_XDECREF(tmp);\r | |
4619 | tmp = NULL;\r | |
4620 | } else {\r | |
4621 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");\r | |
4622 | return 1;\r | |
4623 | }\r | |
4624 | *out = Global(names, lineno, col_offset, arena);\r | |
4625 | if (*out == NULL) goto failed;\r | |
4626 | return 0;\r | |
4627 | }\r | |
4628 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);\r | |
4629 | if (isinstance == -1) {\r | |
4630 | return 1;\r | |
4631 | }\r | |
4632 | if (isinstance) {\r | |
4633 | expr_ty value;\r | |
4634 | \r | |
4635 | if (PyObject_HasAttrString(obj, "value")) {\r | |
4636 | int res;\r | |
4637 | tmp = PyObject_GetAttrString(obj, "value");\r | |
4638 | if (tmp == NULL) goto failed;\r | |
4639 | res = obj2ast_expr(tmp, &value, arena);\r | |
4640 | if (res != 0) goto failed;\r | |
4641 | Py_XDECREF(tmp);\r | |
4642 | tmp = NULL;\r | |
4643 | } else {\r | |
4644 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");\r | |
4645 | return 1;\r | |
4646 | }\r | |
4647 | *out = Expr(value, lineno, col_offset, arena);\r | |
4648 | if (*out == NULL) goto failed;\r | |
4649 | return 0;\r | |
4650 | }\r | |
4651 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);\r | |
4652 | if (isinstance == -1) {\r | |
4653 | return 1;\r | |
4654 | }\r | |
4655 | if (isinstance) {\r | |
4656 | \r | |
4657 | *out = Pass(lineno, col_offset, arena);\r | |
4658 | if (*out == NULL) goto failed;\r | |
4659 | return 0;\r | |
4660 | }\r | |
4661 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);\r | |
4662 | if (isinstance == -1) {\r | |
4663 | return 1;\r | |
4664 | }\r | |
4665 | if (isinstance) {\r | |
4666 | \r | |
4667 | *out = Break(lineno, col_offset, arena);\r | |
4668 | if (*out == NULL) goto failed;\r | |
4669 | return 0;\r | |
4670 | }\r | |
4671 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);\r | |
4672 | if (isinstance == -1) {\r | |
4673 | return 1;\r | |
4674 | }\r | |
4675 | if (isinstance) {\r | |
4676 | \r | |
4677 | *out = Continue(lineno, col_offset, arena);\r | |
4678 | if (*out == NULL) goto failed;\r | |
4679 | return 0;\r | |
4680 | }\r | |
4681 | \r | |
4682 | tmp = PyObject_Repr(obj);\r | |
4683 | if (tmp == NULL) goto failed;\r | |
4684 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));\r | |
4685 | failed:\r | |
4686 | Py_XDECREF(tmp);\r | |
4687 | return 1;\r | |
4688 | }\r | |
4689 | \r | |
4690 | int\r | |
4691 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)\r | |
4692 | {\r | |
4693 | PyObject* tmp = NULL;\r | |
4694 | int isinstance;\r | |
4695 | \r | |
4696 | int lineno;\r | |
4697 | int col_offset;\r | |
4698 | \r | |
4699 | if (obj == Py_None) {\r | |
4700 | *out = NULL;\r | |
4701 | return 0;\r | |
4702 | }\r | |
4703 | if (PyObject_HasAttrString(obj, "lineno")) {\r | |
4704 | int res;\r | |
4705 | tmp = PyObject_GetAttrString(obj, "lineno");\r | |
4706 | if (tmp == NULL) goto failed;\r | |
4707 | res = obj2ast_int(tmp, &lineno, arena);\r | |
4708 | if (res != 0) goto failed;\r | |
4709 | Py_XDECREF(tmp);\r | |
4710 | tmp = NULL;\r | |
4711 | } else {\r | |
4712 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");\r | |
4713 | return 1;\r | |
4714 | }\r | |
4715 | if (PyObject_HasAttrString(obj, "col_offset")) {\r | |
4716 | int res;\r | |
4717 | tmp = PyObject_GetAttrString(obj, "col_offset");\r | |
4718 | if (tmp == NULL) goto failed;\r | |
4719 | res = obj2ast_int(tmp, &col_offset, arena);\r | |
4720 | if (res != 0) goto failed;\r | |
4721 | Py_XDECREF(tmp);\r | |
4722 | tmp = NULL;\r | |
4723 | } else {\r | |
4724 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");\r | |
4725 | return 1;\r | |
4726 | }\r | |
4727 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);\r | |
4728 | if (isinstance == -1) {\r | |
4729 | return 1;\r | |
4730 | }\r | |
4731 | if (isinstance) {\r | |
4732 | boolop_ty op;\r | |
4733 | asdl_seq* values;\r | |
4734 | \r | |
4735 | if (PyObject_HasAttrString(obj, "op")) {\r | |
4736 | int res;\r | |
4737 | tmp = PyObject_GetAttrString(obj, "op");\r | |
4738 | if (tmp == NULL) goto failed;\r | |
4739 | res = obj2ast_boolop(tmp, &op, arena);\r | |
4740 | if (res != 0) goto failed;\r | |
4741 | Py_XDECREF(tmp);\r | |
4742 | tmp = NULL;\r | |
4743 | } else {\r | |
4744 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");\r | |
4745 | return 1;\r | |
4746 | }\r | |
4747 | if (PyObject_HasAttrString(obj, "values")) {\r | |
4748 | int res;\r | |
4749 | Py_ssize_t len;\r | |
4750 | Py_ssize_t i;\r | |
4751 | tmp = PyObject_GetAttrString(obj, "values");\r | |
4752 | if (tmp == NULL) goto failed;\r | |
4753 | if (!PyList_Check(tmp)) {\r | |
4754 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4755 | goto failed;\r | |
4756 | }\r | |
4757 | len = PyList_GET_SIZE(tmp);\r | |
4758 | values = asdl_seq_new(len, arena);\r | |
4759 | if (values == NULL) goto failed;\r | |
4760 | for (i = 0; i < len; i++) {\r | |
4761 | expr_ty value;\r | |
4762 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4763 | if (res != 0) goto failed;\r | |
4764 | asdl_seq_SET(values, i, value);\r | |
4765 | }\r | |
4766 | Py_XDECREF(tmp);\r | |
4767 | tmp = NULL;\r | |
4768 | } else {\r | |
4769 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");\r | |
4770 | return 1;\r | |
4771 | }\r | |
4772 | *out = BoolOp(op, values, lineno, col_offset, arena);\r | |
4773 | if (*out == NULL) goto failed;\r | |
4774 | return 0;\r | |
4775 | }\r | |
4776 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);\r | |
4777 | if (isinstance == -1) {\r | |
4778 | return 1;\r | |
4779 | }\r | |
4780 | if (isinstance) {\r | |
4781 | expr_ty left;\r | |
4782 | operator_ty op;\r | |
4783 | expr_ty right;\r | |
4784 | \r | |
4785 | if (PyObject_HasAttrString(obj, "left")) {\r | |
4786 | int res;\r | |
4787 | tmp = PyObject_GetAttrString(obj, "left");\r | |
4788 | if (tmp == NULL) goto failed;\r | |
4789 | res = obj2ast_expr(tmp, &left, arena);\r | |
4790 | if (res != 0) goto failed;\r | |
4791 | Py_XDECREF(tmp);\r | |
4792 | tmp = NULL;\r | |
4793 | } else {\r | |
4794 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");\r | |
4795 | return 1;\r | |
4796 | }\r | |
4797 | if (PyObject_HasAttrString(obj, "op")) {\r | |
4798 | int res;\r | |
4799 | tmp = PyObject_GetAttrString(obj, "op");\r | |
4800 | if (tmp == NULL) goto failed;\r | |
4801 | res = obj2ast_operator(tmp, &op, arena);\r | |
4802 | if (res != 0) goto failed;\r | |
4803 | Py_XDECREF(tmp);\r | |
4804 | tmp = NULL;\r | |
4805 | } else {\r | |
4806 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");\r | |
4807 | return 1;\r | |
4808 | }\r | |
4809 | if (PyObject_HasAttrString(obj, "right")) {\r | |
4810 | int res;\r | |
4811 | tmp = PyObject_GetAttrString(obj, "right");\r | |
4812 | if (tmp == NULL) goto failed;\r | |
4813 | res = obj2ast_expr(tmp, &right, arena);\r | |
4814 | if (res != 0) goto failed;\r | |
4815 | Py_XDECREF(tmp);\r | |
4816 | tmp = NULL;\r | |
4817 | } else {\r | |
4818 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");\r | |
4819 | return 1;\r | |
4820 | }\r | |
4821 | *out = BinOp(left, op, right, lineno, col_offset, arena);\r | |
4822 | if (*out == NULL) goto failed;\r | |
4823 | return 0;\r | |
4824 | }\r | |
4825 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);\r | |
4826 | if (isinstance == -1) {\r | |
4827 | return 1;\r | |
4828 | }\r | |
4829 | if (isinstance) {\r | |
4830 | unaryop_ty op;\r | |
4831 | expr_ty operand;\r | |
4832 | \r | |
4833 | if (PyObject_HasAttrString(obj, "op")) {\r | |
4834 | int res;\r | |
4835 | tmp = PyObject_GetAttrString(obj, "op");\r | |
4836 | if (tmp == NULL) goto failed;\r | |
4837 | res = obj2ast_unaryop(tmp, &op, arena);\r | |
4838 | if (res != 0) goto failed;\r | |
4839 | Py_XDECREF(tmp);\r | |
4840 | tmp = NULL;\r | |
4841 | } else {\r | |
4842 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");\r | |
4843 | return 1;\r | |
4844 | }\r | |
4845 | if (PyObject_HasAttrString(obj, "operand")) {\r | |
4846 | int res;\r | |
4847 | tmp = PyObject_GetAttrString(obj, "operand");\r | |
4848 | if (tmp == NULL) goto failed;\r | |
4849 | res = obj2ast_expr(tmp, &operand, arena);\r | |
4850 | if (res != 0) goto failed;\r | |
4851 | Py_XDECREF(tmp);\r | |
4852 | tmp = NULL;\r | |
4853 | } else {\r | |
4854 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");\r | |
4855 | return 1;\r | |
4856 | }\r | |
4857 | *out = UnaryOp(op, operand, lineno, col_offset, arena);\r | |
4858 | if (*out == NULL) goto failed;\r | |
4859 | return 0;\r | |
4860 | }\r | |
4861 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);\r | |
4862 | if (isinstance == -1) {\r | |
4863 | return 1;\r | |
4864 | }\r | |
4865 | if (isinstance) {\r | |
4866 | arguments_ty args;\r | |
4867 | expr_ty body;\r | |
4868 | \r | |
4869 | if (PyObject_HasAttrString(obj, "args")) {\r | |
4870 | int res;\r | |
4871 | tmp = PyObject_GetAttrString(obj, "args");\r | |
4872 | if (tmp == NULL) goto failed;\r | |
4873 | res = obj2ast_arguments(tmp, &args, arena);\r | |
4874 | if (res != 0) goto failed;\r | |
4875 | Py_XDECREF(tmp);\r | |
4876 | tmp = NULL;\r | |
4877 | } else {\r | |
4878 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");\r | |
4879 | return 1;\r | |
4880 | }\r | |
4881 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4882 | int res;\r | |
4883 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4884 | if (tmp == NULL) goto failed;\r | |
4885 | res = obj2ast_expr(tmp, &body, arena);\r | |
4886 | if (res != 0) goto failed;\r | |
4887 | Py_XDECREF(tmp);\r | |
4888 | tmp = NULL;\r | |
4889 | } else {\r | |
4890 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");\r | |
4891 | return 1;\r | |
4892 | }\r | |
4893 | *out = Lambda(args, body, lineno, col_offset, arena);\r | |
4894 | if (*out == NULL) goto failed;\r | |
4895 | return 0;\r | |
4896 | }\r | |
4897 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);\r | |
4898 | if (isinstance == -1) {\r | |
4899 | return 1;\r | |
4900 | }\r | |
4901 | if (isinstance) {\r | |
4902 | expr_ty test;\r | |
4903 | expr_ty body;\r | |
4904 | expr_ty orelse;\r | |
4905 | \r | |
4906 | if (PyObject_HasAttrString(obj, "test")) {\r | |
4907 | int res;\r | |
4908 | tmp = PyObject_GetAttrString(obj, "test");\r | |
4909 | if (tmp == NULL) goto failed;\r | |
4910 | res = obj2ast_expr(tmp, &test, arena);\r | |
4911 | if (res != 0) goto failed;\r | |
4912 | Py_XDECREF(tmp);\r | |
4913 | tmp = NULL;\r | |
4914 | } else {\r | |
4915 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");\r | |
4916 | return 1;\r | |
4917 | }\r | |
4918 | if (PyObject_HasAttrString(obj, "body")) {\r | |
4919 | int res;\r | |
4920 | tmp = PyObject_GetAttrString(obj, "body");\r | |
4921 | if (tmp == NULL) goto failed;\r | |
4922 | res = obj2ast_expr(tmp, &body, arena);\r | |
4923 | if (res != 0) goto failed;\r | |
4924 | Py_XDECREF(tmp);\r | |
4925 | tmp = NULL;\r | |
4926 | } else {\r | |
4927 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");\r | |
4928 | return 1;\r | |
4929 | }\r | |
4930 | if (PyObject_HasAttrString(obj, "orelse")) {\r | |
4931 | int res;\r | |
4932 | tmp = PyObject_GetAttrString(obj, "orelse");\r | |
4933 | if (tmp == NULL) goto failed;\r | |
4934 | res = obj2ast_expr(tmp, &orelse, arena);\r | |
4935 | if (res != 0) goto failed;\r | |
4936 | Py_XDECREF(tmp);\r | |
4937 | tmp = NULL;\r | |
4938 | } else {\r | |
4939 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");\r | |
4940 | return 1;\r | |
4941 | }\r | |
4942 | *out = IfExp(test, body, orelse, lineno, col_offset, arena);\r | |
4943 | if (*out == NULL) goto failed;\r | |
4944 | return 0;\r | |
4945 | }\r | |
4946 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);\r | |
4947 | if (isinstance == -1) {\r | |
4948 | return 1;\r | |
4949 | }\r | |
4950 | if (isinstance) {\r | |
4951 | asdl_seq* keys;\r | |
4952 | asdl_seq* values;\r | |
4953 | \r | |
4954 | if (PyObject_HasAttrString(obj, "keys")) {\r | |
4955 | int res;\r | |
4956 | Py_ssize_t len;\r | |
4957 | Py_ssize_t i;\r | |
4958 | tmp = PyObject_GetAttrString(obj, "keys");\r | |
4959 | if (tmp == NULL) goto failed;\r | |
4960 | if (!PyList_Check(tmp)) {\r | |
4961 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4962 | goto failed;\r | |
4963 | }\r | |
4964 | len = PyList_GET_SIZE(tmp);\r | |
4965 | keys = asdl_seq_new(len, arena);\r | |
4966 | if (keys == NULL) goto failed;\r | |
4967 | for (i = 0; i < len; i++) {\r | |
4968 | expr_ty value;\r | |
4969 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4970 | if (res != 0) goto failed;\r | |
4971 | asdl_seq_SET(keys, i, value);\r | |
4972 | }\r | |
4973 | Py_XDECREF(tmp);\r | |
4974 | tmp = NULL;\r | |
4975 | } else {\r | |
4976 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");\r | |
4977 | return 1;\r | |
4978 | }\r | |
4979 | if (PyObject_HasAttrString(obj, "values")) {\r | |
4980 | int res;\r | |
4981 | Py_ssize_t len;\r | |
4982 | Py_ssize_t i;\r | |
4983 | tmp = PyObject_GetAttrString(obj, "values");\r | |
4984 | if (tmp == NULL) goto failed;\r | |
4985 | if (!PyList_Check(tmp)) {\r | |
4986 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
4987 | goto failed;\r | |
4988 | }\r | |
4989 | len = PyList_GET_SIZE(tmp);\r | |
4990 | values = asdl_seq_new(len, arena);\r | |
4991 | if (values == NULL) goto failed;\r | |
4992 | for (i = 0; i < len; i++) {\r | |
4993 | expr_ty value;\r | |
4994 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
4995 | if (res != 0) goto failed;\r | |
4996 | asdl_seq_SET(values, i, value);\r | |
4997 | }\r | |
4998 | Py_XDECREF(tmp);\r | |
4999 | tmp = NULL;\r | |
5000 | } else {\r | |
5001 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");\r | |
5002 | return 1;\r | |
5003 | }\r | |
5004 | *out = Dict(keys, values, lineno, col_offset, arena);\r | |
5005 | if (*out == NULL) goto failed;\r | |
5006 | return 0;\r | |
5007 | }\r | |
5008 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);\r | |
5009 | if (isinstance == -1) {\r | |
5010 | return 1;\r | |
5011 | }\r | |
5012 | if (isinstance) {\r | |
5013 | asdl_seq* elts;\r | |
5014 | \r | |
5015 | if (PyObject_HasAttrString(obj, "elts")) {\r | |
5016 | int res;\r | |
5017 | Py_ssize_t len;\r | |
5018 | Py_ssize_t i;\r | |
5019 | tmp = PyObject_GetAttrString(obj, "elts");\r | |
5020 | if (tmp == NULL) goto failed;\r | |
5021 | if (!PyList_Check(tmp)) {\r | |
5022 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5023 | goto failed;\r | |
5024 | }\r | |
5025 | len = PyList_GET_SIZE(tmp);\r | |
5026 | elts = asdl_seq_new(len, arena);\r | |
5027 | if (elts == NULL) goto failed;\r | |
5028 | for (i = 0; i < len; i++) {\r | |
5029 | expr_ty value;\r | |
5030 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5031 | if (res != 0) goto failed;\r | |
5032 | asdl_seq_SET(elts, i, value);\r | |
5033 | }\r | |
5034 | Py_XDECREF(tmp);\r | |
5035 | tmp = NULL;\r | |
5036 | } else {\r | |
5037 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");\r | |
5038 | return 1;\r | |
5039 | }\r | |
5040 | *out = Set(elts, lineno, col_offset, arena);\r | |
5041 | if (*out == NULL) goto failed;\r | |
5042 | return 0;\r | |
5043 | }\r | |
5044 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);\r | |
5045 | if (isinstance == -1) {\r | |
5046 | return 1;\r | |
5047 | }\r | |
5048 | if (isinstance) {\r | |
5049 | expr_ty elt;\r | |
5050 | asdl_seq* generators;\r | |
5051 | \r | |
5052 | if (PyObject_HasAttrString(obj, "elt")) {\r | |
5053 | int res;\r | |
5054 | tmp = PyObject_GetAttrString(obj, "elt");\r | |
5055 | if (tmp == NULL) goto failed;\r | |
5056 | res = obj2ast_expr(tmp, &elt, arena);\r | |
5057 | if (res != 0) goto failed;\r | |
5058 | Py_XDECREF(tmp);\r | |
5059 | tmp = NULL;\r | |
5060 | } else {\r | |
5061 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");\r | |
5062 | return 1;\r | |
5063 | }\r | |
5064 | if (PyObject_HasAttrString(obj, "generators")) {\r | |
5065 | int res;\r | |
5066 | Py_ssize_t len;\r | |
5067 | Py_ssize_t i;\r | |
5068 | tmp = PyObject_GetAttrString(obj, "generators");\r | |
5069 | if (tmp == NULL) goto failed;\r | |
5070 | if (!PyList_Check(tmp)) {\r | |
5071 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5072 | goto failed;\r | |
5073 | }\r | |
5074 | len = PyList_GET_SIZE(tmp);\r | |
5075 | generators = asdl_seq_new(len, arena);\r | |
5076 | if (generators == NULL) goto failed;\r | |
5077 | for (i = 0; i < len; i++) {\r | |
5078 | comprehension_ty value;\r | |
5079 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5080 | if (res != 0) goto failed;\r | |
5081 | asdl_seq_SET(generators, i, value);\r | |
5082 | }\r | |
5083 | Py_XDECREF(tmp);\r | |
5084 | tmp = NULL;\r | |
5085 | } else {\r | |
5086 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");\r | |
5087 | return 1;\r | |
5088 | }\r | |
5089 | *out = ListComp(elt, generators, lineno, col_offset, arena);\r | |
5090 | if (*out == NULL) goto failed;\r | |
5091 | return 0;\r | |
5092 | }\r | |
5093 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);\r | |
5094 | if (isinstance == -1) {\r | |
5095 | return 1;\r | |
5096 | }\r | |
5097 | if (isinstance) {\r | |
5098 | expr_ty elt;\r | |
5099 | asdl_seq* generators;\r | |
5100 | \r | |
5101 | if (PyObject_HasAttrString(obj, "elt")) {\r | |
5102 | int res;\r | |
5103 | tmp = PyObject_GetAttrString(obj, "elt");\r | |
5104 | if (tmp == NULL) goto failed;\r | |
5105 | res = obj2ast_expr(tmp, &elt, arena);\r | |
5106 | if (res != 0) goto failed;\r | |
5107 | Py_XDECREF(tmp);\r | |
5108 | tmp = NULL;\r | |
5109 | } else {\r | |
5110 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");\r | |
5111 | return 1;\r | |
5112 | }\r | |
5113 | if (PyObject_HasAttrString(obj, "generators")) {\r | |
5114 | int res;\r | |
5115 | Py_ssize_t len;\r | |
5116 | Py_ssize_t i;\r | |
5117 | tmp = PyObject_GetAttrString(obj, "generators");\r | |
5118 | if (tmp == NULL) goto failed;\r | |
5119 | if (!PyList_Check(tmp)) {\r | |
5120 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5121 | goto failed;\r | |
5122 | }\r | |
5123 | len = PyList_GET_SIZE(tmp);\r | |
5124 | generators = asdl_seq_new(len, arena);\r | |
5125 | if (generators == NULL) goto failed;\r | |
5126 | for (i = 0; i < len; i++) {\r | |
5127 | comprehension_ty value;\r | |
5128 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5129 | if (res != 0) goto failed;\r | |
5130 | asdl_seq_SET(generators, i, value);\r | |
5131 | }\r | |
5132 | Py_XDECREF(tmp);\r | |
5133 | tmp = NULL;\r | |
5134 | } else {\r | |
5135 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");\r | |
5136 | return 1;\r | |
5137 | }\r | |
5138 | *out = SetComp(elt, generators, lineno, col_offset, arena);\r | |
5139 | if (*out == NULL) goto failed;\r | |
5140 | return 0;\r | |
5141 | }\r | |
5142 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);\r | |
5143 | if (isinstance == -1) {\r | |
5144 | return 1;\r | |
5145 | }\r | |
5146 | if (isinstance) {\r | |
5147 | expr_ty key;\r | |
5148 | expr_ty value;\r | |
5149 | asdl_seq* generators;\r | |
5150 | \r | |
5151 | if (PyObject_HasAttrString(obj, "key")) {\r | |
5152 | int res;\r | |
5153 | tmp = PyObject_GetAttrString(obj, "key");\r | |
5154 | if (tmp == NULL) goto failed;\r | |
5155 | res = obj2ast_expr(tmp, &key, arena);\r | |
5156 | if (res != 0) goto failed;\r | |
5157 | Py_XDECREF(tmp);\r | |
5158 | tmp = NULL;\r | |
5159 | } else {\r | |
5160 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");\r | |
5161 | return 1;\r | |
5162 | }\r | |
5163 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5164 | int res;\r | |
5165 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5166 | if (tmp == NULL) goto failed;\r | |
5167 | res = obj2ast_expr(tmp, &value, arena);\r | |
5168 | if (res != 0) goto failed;\r | |
5169 | Py_XDECREF(tmp);\r | |
5170 | tmp = NULL;\r | |
5171 | } else {\r | |
5172 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");\r | |
5173 | return 1;\r | |
5174 | }\r | |
5175 | if (PyObject_HasAttrString(obj, "generators")) {\r | |
5176 | int res;\r | |
5177 | Py_ssize_t len;\r | |
5178 | Py_ssize_t i;\r | |
5179 | tmp = PyObject_GetAttrString(obj, "generators");\r | |
5180 | if (tmp == NULL) goto failed;\r | |
5181 | if (!PyList_Check(tmp)) {\r | |
5182 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5183 | goto failed;\r | |
5184 | }\r | |
5185 | len = PyList_GET_SIZE(tmp);\r | |
5186 | generators = asdl_seq_new(len, arena);\r | |
5187 | if (generators == NULL) goto failed;\r | |
5188 | for (i = 0; i < len; i++) {\r | |
5189 | comprehension_ty value;\r | |
5190 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5191 | if (res != 0) goto failed;\r | |
5192 | asdl_seq_SET(generators, i, value);\r | |
5193 | }\r | |
5194 | Py_XDECREF(tmp);\r | |
5195 | tmp = NULL;\r | |
5196 | } else {\r | |
5197 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");\r | |
5198 | return 1;\r | |
5199 | }\r | |
5200 | *out = DictComp(key, value, generators, lineno, col_offset,\r | |
5201 | arena);\r | |
5202 | if (*out == NULL) goto failed;\r | |
5203 | return 0;\r | |
5204 | }\r | |
5205 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);\r | |
5206 | if (isinstance == -1) {\r | |
5207 | return 1;\r | |
5208 | }\r | |
5209 | if (isinstance) {\r | |
5210 | expr_ty elt;\r | |
5211 | asdl_seq* generators;\r | |
5212 | \r | |
5213 | if (PyObject_HasAttrString(obj, "elt")) {\r | |
5214 | int res;\r | |
5215 | tmp = PyObject_GetAttrString(obj, "elt");\r | |
5216 | if (tmp == NULL) goto failed;\r | |
5217 | res = obj2ast_expr(tmp, &elt, arena);\r | |
5218 | if (res != 0) goto failed;\r | |
5219 | Py_XDECREF(tmp);\r | |
5220 | tmp = NULL;\r | |
5221 | } else {\r | |
5222 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");\r | |
5223 | return 1;\r | |
5224 | }\r | |
5225 | if (PyObject_HasAttrString(obj, "generators")) {\r | |
5226 | int res;\r | |
5227 | Py_ssize_t len;\r | |
5228 | Py_ssize_t i;\r | |
5229 | tmp = PyObject_GetAttrString(obj, "generators");\r | |
5230 | if (tmp == NULL) goto failed;\r | |
5231 | if (!PyList_Check(tmp)) {\r | |
5232 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5233 | goto failed;\r | |
5234 | }\r | |
5235 | len = PyList_GET_SIZE(tmp);\r | |
5236 | generators = asdl_seq_new(len, arena);\r | |
5237 | if (generators == NULL) goto failed;\r | |
5238 | for (i = 0; i < len; i++) {\r | |
5239 | comprehension_ty value;\r | |
5240 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5241 | if (res != 0) goto failed;\r | |
5242 | asdl_seq_SET(generators, i, value);\r | |
5243 | }\r | |
5244 | Py_XDECREF(tmp);\r | |
5245 | tmp = NULL;\r | |
5246 | } else {\r | |
5247 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");\r | |
5248 | return 1;\r | |
5249 | }\r | |
5250 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena);\r | |
5251 | if (*out == NULL) goto failed;\r | |
5252 | return 0;\r | |
5253 | }\r | |
5254 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);\r | |
5255 | if (isinstance == -1) {\r | |
5256 | return 1;\r | |
5257 | }\r | |
5258 | if (isinstance) {\r | |
5259 | expr_ty value;\r | |
5260 | \r | |
5261 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5262 | int res;\r | |
5263 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5264 | if (tmp == NULL) goto failed;\r | |
5265 | res = obj2ast_expr(tmp, &value, arena);\r | |
5266 | if (res != 0) goto failed;\r | |
5267 | Py_XDECREF(tmp);\r | |
5268 | tmp = NULL;\r | |
5269 | } else {\r | |
5270 | value = NULL;\r | |
5271 | }\r | |
5272 | *out = Yield(value, lineno, col_offset, arena);\r | |
5273 | if (*out == NULL) goto failed;\r | |
5274 | return 0;\r | |
5275 | }\r | |
5276 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);\r | |
5277 | if (isinstance == -1) {\r | |
5278 | return 1;\r | |
5279 | }\r | |
5280 | if (isinstance) {\r | |
5281 | expr_ty left;\r | |
5282 | asdl_int_seq* ops;\r | |
5283 | asdl_seq* comparators;\r | |
5284 | \r | |
5285 | if (PyObject_HasAttrString(obj, "left")) {\r | |
5286 | int res;\r | |
5287 | tmp = PyObject_GetAttrString(obj, "left");\r | |
5288 | if (tmp == NULL) goto failed;\r | |
5289 | res = obj2ast_expr(tmp, &left, arena);\r | |
5290 | if (res != 0) goto failed;\r | |
5291 | Py_XDECREF(tmp);\r | |
5292 | tmp = NULL;\r | |
5293 | } else {\r | |
5294 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");\r | |
5295 | return 1;\r | |
5296 | }\r | |
5297 | if (PyObject_HasAttrString(obj, "ops")) {\r | |
5298 | int res;\r | |
5299 | Py_ssize_t len;\r | |
5300 | Py_ssize_t i;\r | |
5301 | tmp = PyObject_GetAttrString(obj, "ops");\r | |
5302 | if (tmp == NULL) goto failed;\r | |
5303 | if (!PyList_Check(tmp)) {\r | |
5304 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5305 | goto failed;\r | |
5306 | }\r | |
5307 | len = PyList_GET_SIZE(tmp);\r | |
5308 | ops = asdl_int_seq_new(len, arena);\r | |
5309 | if (ops == NULL) goto failed;\r | |
5310 | for (i = 0; i < len; i++) {\r | |
5311 | cmpop_ty value;\r | |
5312 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5313 | if (res != 0) goto failed;\r | |
5314 | asdl_seq_SET(ops, i, value);\r | |
5315 | }\r | |
5316 | Py_XDECREF(tmp);\r | |
5317 | tmp = NULL;\r | |
5318 | } else {\r | |
5319 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");\r | |
5320 | return 1;\r | |
5321 | }\r | |
5322 | if (PyObject_HasAttrString(obj, "comparators")) {\r | |
5323 | int res;\r | |
5324 | Py_ssize_t len;\r | |
5325 | Py_ssize_t i;\r | |
5326 | tmp = PyObject_GetAttrString(obj, "comparators");\r | |
5327 | if (tmp == NULL) goto failed;\r | |
5328 | if (!PyList_Check(tmp)) {\r | |
5329 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5330 | goto failed;\r | |
5331 | }\r | |
5332 | len = PyList_GET_SIZE(tmp);\r | |
5333 | comparators = asdl_seq_new(len, arena);\r | |
5334 | if (comparators == NULL) goto failed;\r | |
5335 | for (i = 0; i < len; i++) {\r | |
5336 | expr_ty value;\r | |
5337 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5338 | if (res != 0) goto failed;\r | |
5339 | asdl_seq_SET(comparators, i, value);\r | |
5340 | }\r | |
5341 | Py_XDECREF(tmp);\r | |
5342 | tmp = NULL;\r | |
5343 | } else {\r | |
5344 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");\r | |
5345 | return 1;\r | |
5346 | }\r | |
5347 | *out = Compare(left, ops, comparators, lineno, col_offset,\r | |
5348 | arena);\r | |
5349 | if (*out == NULL) goto failed;\r | |
5350 | return 0;\r | |
5351 | }\r | |
5352 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);\r | |
5353 | if (isinstance == -1) {\r | |
5354 | return 1;\r | |
5355 | }\r | |
5356 | if (isinstance) {\r | |
5357 | expr_ty func;\r | |
5358 | asdl_seq* args;\r | |
5359 | asdl_seq* keywords;\r | |
5360 | expr_ty starargs;\r | |
5361 | expr_ty kwargs;\r | |
5362 | \r | |
5363 | if (PyObject_HasAttrString(obj, "func")) {\r | |
5364 | int res;\r | |
5365 | tmp = PyObject_GetAttrString(obj, "func");\r | |
5366 | if (tmp == NULL) goto failed;\r | |
5367 | res = obj2ast_expr(tmp, &func, arena);\r | |
5368 | if (res != 0) goto failed;\r | |
5369 | Py_XDECREF(tmp);\r | |
5370 | tmp = NULL;\r | |
5371 | } else {\r | |
5372 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");\r | |
5373 | return 1;\r | |
5374 | }\r | |
5375 | if (PyObject_HasAttrString(obj, "args")) {\r | |
5376 | int res;\r | |
5377 | Py_ssize_t len;\r | |
5378 | Py_ssize_t i;\r | |
5379 | tmp = PyObject_GetAttrString(obj, "args");\r | |
5380 | if (tmp == NULL) goto failed;\r | |
5381 | if (!PyList_Check(tmp)) {\r | |
5382 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5383 | goto failed;\r | |
5384 | }\r | |
5385 | len = PyList_GET_SIZE(tmp);\r | |
5386 | args = asdl_seq_new(len, arena);\r | |
5387 | if (args == NULL) goto failed;\r | |
5388 | for (i = 0; i < len; i++) {\r | |
5389 | expr_ty value;\r | |
5390 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5391 | if (res != 0) goto failed;\r | |
5392 | asdl_seq_SET(args, i, value);\r | |
5393 | }\r | |
5394 | Py_XDECREF(tmp);\r | |
5395 | tmp = NULL;\r | |
5396 | } else {\r | |
5397 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");\r | |
5398 | return 1;\r | |
5399 | }\r | |
5400 | if (PyObject_HasAttrString(obj, "keywords")) {\r | |
5401 | int res;\r | |
5402 | Py_ssize_t len;\r | |
5403 | Py_ssize_t i;\r | |
5404 | tmp = PyObject_GetAttrString(obj, "keywords");\r | |
5405 | if (tmp == NULL) goto failed;\r | |
5406 | if (!PyList_Check(tmp)) {\r | |
5407 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5408 | goto failed;\r | |
5409 | }\r | |
5410 | len = PyList_GET_SIZE(tmp);\r | |
5411 | keywords = asdl_seq_new(len, arena);\r | |
5412 | if (keywords == NULL) goto failed;\r | |
5413 | for (i = 0; i < len; i++) {\r | |
5414 | keyword_ty value;\r | |
5415 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5416 | if (res != 0) goto failed;\r | |
5417 | asdl_seq_SET(keywords, i, value);\r | |
5418 | }\r | |
5419 | Py_XDECREF(tmp);\r | |
5420 | tmp = NULL;\r | |
5421 | } else {\r | |
5422 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");\r | |
5423 | return 1;\r | |
5424 | }\r | |
5425 | if (PyObject_HasAttrString(obj, "starargs")) {\r | |
5426 | int res;\r | |
5427 | tmp = PyObject_GetAttrString(obj, "starargs");\r | |
5428 | if (tmp == NULL) goto failed;\r | |
5429 | res = obj2ast_expr(tmp, &starargs, arena);\r | |
5430 | if (res != 0) goto failed;\r | |
5431 | Py_XDECREF(tmp);\r | |
5432 | tmp = NULL;\r | |
5433 | } else {\r | |
5434 | starargs = NULL;\r | |
5435 | }\r | |
5436 | if (PyObject_HasAttrString(obj, "kwargs")) {\r | |
5437 | int res;\r | |
5438 | tmp = PyObject_GetAttrString(obj, "kwargs");\r | |
5439 | if (tmp == NULL) goto failed;\r | |
5440 | res = obj2ast_expr(tmp, &kwargs, arena);\r | |
5441 | if (res != 0) goto failed;\r | |
5442 | Py_XDECREF(tmp);\r | |
5443 | tmp = NULL;\r | |
5444 | } else {\r | |
5445 | kwargs = NULL;\r | |
5446 | }\r | |
5447 | *out = Call(func, args, keywords, starargs, kwargs, lineno,\r | |
5448 | col_offset, arena);\r | |
5449 | if (*out == NULL) goto failed;\r | |
5450 | return 0;\r | |
5451 | }\r | |
5452 | isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);\r | |
5453 | if (isinstance == -1) {\r | |
5454 | return 1;\r | |
5455 | }\r | |
5456 | if (isinstance) {\r | |
5457 | expr_ty value;\r | |
5458 | \r | |
5459 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5460 | int res;\r | |
5461 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5462 | if (tmp == NULL) goto failed;\r | |
5463 | res = obj2ast_expr(tmp, &value, arena);\r | |
5464 | if (res != 0) goto failed;\r | |
5465 | Py_XDECREF(tmp);\r | |
5466 | tmp = NULL;\r | |
5467 | } else {\r | |
5468 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");\r | |
5469 | return 1;\r | |
5470 | }\r | |
5471 | *out = Repr(value, lineno, col_offset, arena);\r | |
5472 | if (*out == NULL) goto failed;\r | |
5473 | return 0;\r | |
5474 | }\r | |
5475 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);\r | |
5476 | if (isinstance == -1) {\r | |
5477 | return 1;\r | |
5478 | }\r | |
5479 | if (isinstance) {\r | |
5480 | object n;\r | |
5481 | \r | |
5482 | if (PyObject_HasAttrString(obj, "n")) {\r | |
5483 | int res;\r | |
5484 | tmp = PyObject_GetAttrString(obj, "n");\r | |
5485 | if (tmp == NULL) goto failed;\r | |
5486 | res = obj2ast_object(tmp, &n, arena);\r | |
5487 | if (res != 0) goto failed;\r | |
5488 | Py_XDECREF(tmp);\r | |
5489 | tmp = NULL;\r | |
5490 | } else {\r | |
5491 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");\r | |
5492 | return 1;\r | |
5493 | }\r | |
5494 | *out = Num(n, lineno, col_offset, arena);\r | |
5495 | if (*out == NULL) goto failed;\r | |
5496 | return 0;\r | |
5497 | }\r | |
5498 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);\r | |
5499 | if (isinstance == -1) {\r | |
5500 | return 1;\r | |
5501 | }\r | |
5502 | if (isinstance) {\r | |
5503 | string s;\r | |
5504 | \r | |
5505 | if (PyObject_HasAttrString(obj, "s")) {\r | |
5506 | int res;\r | |
5507 | tmp = PyObject_GetAttrString(obj, "s");\r | |
5508 | if (tmp == NULL) goto failed;\r | |
5509 | res = obj2ast_string(tmp, &s, arena);\r | |
5510 | if (res != 0) goto failed;\r | |
5511 | Py_XDECREF(tmp);\r | |
5512 | tmp = NULL;\r | |
5513 | } else {\r | |
5514 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");\r | |
5515 | return 1;\r | |
5516 | }\r | |
5517 | *out = Str(s, lineno, col_offset, arena);\r | |
5518 | if (*out == NULL) goto failed;\r | |
5519 | return 0;\r | |
5520 | }\r | |
5521 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);\r | |
5522 | if (isinstance == -1) {\r | |
5523 | return 1;\r | |
5524 | }\r | |
5525 | if (isinstance) {\r | |
5526 | expr_ty value;\r | |
5527 | identifier attr;\r | |
5528 | expr_context_ty ctx;\r | |
5529 | \r | |
5530 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5531 | int res;\r | |
5532 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5533 | if (tmp == NULL) goto failed;\r | |
5534 | res = obj2ast_expr(tmp, &value, arena);\r | |
5535 | if (res != 0) goto failed;\r | |
5536 | Py_XDECREF(tmp);\r | |
5537 | tmp = NULL;\r | |
5538 | } else {\r | |
5539 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");\r | |
5540 | return 1;\r | |
5541 | }\r | |
5542 | if (PyObject_HasAttrString(obj, "attr")) {\r | |
5543 | int res;\r | |
5544 | tmp = PyObject_GetAttrString(obj, "attr");\r | |
5545 | if (tmp == NULL) goto failed;\r | |
5546 | res = obj2ast_identifier(tmp, &attr, arena);\r | |
5547 | if (res != 0) goto failed;\r | |
5548 | Py_XDECREF(tmp);\r | |
5549 | tmp = NULL;\r | |
5550 | } else {\r | |
5551 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");\r | |
5552 | return 1;\r | |
5553 | }\r | |
5554 | if (PyObject_HasAttrString(obj, "ctx")) {\r | |
5555 | int res;\r | |
5556 | tmp = PyObject_GetAttrString(obj, "ctx");\r | |
5557 | if (tmp == NULL) goto failed;\r | |
5558 | res = obj2ast_expr_context(tmp, &ctx, arena);\r | |
5559 | if (res != 0) goto failed;\r | |
5560 | Py_XDECREF(tmp);\r | |
5561 | tmp = NULL;\r | |
5562 | } else {\r | |
5563 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");\r | |
5564 | return 1;\r | |
5565 | }\r | |
5566 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena);\r | |
5567 | if (*out == NULL) goto failed;\r | |
5568 | return 0;\r | |
5569 | }\r | |
5570 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);\r | |
5571 | if (isinstance == -1) {\r | |
5572 | return 1;\r | |
5573 | }\r | |
5574 | if (isinstance) {\r | |
5575 | expr_ty value;\r | |
5576 | slice_ty slice;\r | |
5577 | expr_context_ty ctx;\r | |
5578 | \r | |
5579 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5580 | int res;\r | |
5581 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5582 | if (tmp == NULL) goto failed;\r | |
5583 | res = obj2ast_expr(tmp, &value, arena);\r | |
5584 | if (res != 0) goto failed;\r | |
5585 | Py_XDECREF(tmp);\r | |
5586 | tmp = NULL;\r | |
5587 | } else {\r | |
5588 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");\r | |
5589 | return 1;\r | |
5590 | }\r | |
5591 | if (PyObject_HasAttrString(obj, "slice")) {\r | |
5592 | int res;\r | |
5593 | tmp = PyObject_GetAttrString(obj, "slice");\r | |
5594 | if (tmp == NULL) goto failed;\r | |
5595 | res = obj2ast_slice(tmp, &slice, arena);\r | |
5596 | if (res != 0) goto failed;\r | |
5597 | Py_XDECREF(tmp);\r | |
5598 | tmp = NULL;\r | |
5599 | } else {\r | |
5600 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");\r | |
5601 | return 1;\r | |
5602 | }\r | |
5603 | if (PyObject_HasAttrString(obj, "ctx")) {\r | |
5604 | int res;\r | |
5605 | tmp = PyObject_GetAttrString(obj, "ctx");\r | |
5606 | if (tmp == NULL) goto failed;\r | |
5607 | res = obj2ast_expr_context(tmp, &ctx, arena);\r | |
5608 | if (res != 0) goto failed;\r | |
5609 | Py_XDECREF(tmp);\r | |
5610 | tmp = NULL;\r | |
5611 | } else {\r | |
5612 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");\r | |
5613 | return 1;\r | |
5614 | }\r | |
5615 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena);\r | |
5616 | if (*out == NULL) goto failed;\r | |
5617 | return 0;\r | |
5618 | }\r | |
5619 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);\r | |
5620 | if (isinstance == -1) {\r | |
5621 | return 1;\r | |
5622 | }\r | |
5623 | if (isinstance) {\r | |
5624 | identifier id;\r | |
5625 | expr_context_ty ctx;\r | |
5626 | \r | |
5627 | if (PyObject_HasAttrString(obj, "id")) {\r | |
5628 | int res;\r | |
5629 | tmp = PyObject_GetAttrString(obj, "id");\r | |
5630 | if (tmp == NULL) goto failed;\r | |
5631 | res = obj2ast_identifier(tmp, &id, arena);\r | |
5632 | if (res != 0) goto failed;\r | |
5633 | Py_XDECREF(tmp);\r | |
5634 | tmp = NULL;\r | |
5635 | } else {\r | |
5636 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");\r | |
5637 | return 1;\r | |
5638 | }\r | |
5639 | if (PyObject_HasAttrString(obj, "ctx")) {\r | |
5640 | int res;\r | |
5641 | tmp = PyObject_GetAttrString(obj, "ctx");\r | |
5642 | if (tmp == NULL) goto failed;\r | |
5643 | res = obj2ast_expr_context(tmp, &ctx, arena);\r | |
5644 | if (res != 0) goto failed;\r | |
5645 | Py_XDECREF(tmp);\r | |
5646 | tmp = NULL;\r | |
5647 | } else {\r | |
5648 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");\r | |
5649 | return 1;\r | |
5650 | }\r | |
5651 | *out = Name(id, ctx, lineno, col_offset, arena);\r | |
5652 | if (*out == NULL) goto failed;\r | |
5653 | return 0;\r | |
5654 | }\r | |
5655 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);\r | |
5656 | if (isinstance == -1) {\r | |
5657 | return 1;\r | |
5658 | }\r | |
5659 | if (isinstance) {\r | |
5660 | asdl_seq* elts;\r | |
5661 | expr_context_ty ctx;\r | |
5662 | \r | |
5663 | if (PyObject_HasAttrString(obj, "elts")) {\r | |
5664 | int res;\r | |
5665 | Py_ssize_t len;\r | |
5666 | Py_ssize_t i;\r | |
5667 | tmp = PyObject_GetAttrString(obj, "elts");\r | |
5668 | if (tmp == NULL) goto failed;\r | |
5669 | if (!PyList_Check(tmp)) {\r | |
5670 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5671 | goto failed;\r | |
5672 | }\r | |
5673 | len = PyList_GET_SIZE(tmp);\r | |
5674 | elts = asdl_seq_new(len, arena);\r | |
5675 | if (elts == NULL) goto failed;\r | |
5676 | for (i = 0; i < len; i++) {\r | |
5677 | expr_ty value;\r | |
5678 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5679 | if (res != 0) goto failed;\r | |
5680 | asdl_seq_SET(elts, i, value);\r | |
5681 | }\r | |
5682 | Py_XDECREF(tmp);\r | |
5683 | tmp = NULL;\r | |
5684 | } else {\r | |
5685 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");\r | |
5686 | return 1;\r | |
5687 | }\r | |
5688 | if (PyObject_HasAttrString(obj, "ctx")) {\r | |
5689 | int res;\r | |
5690 | tmp = PyObject_GetAttrString(obj, "ctx");\r | |
5691 | if (tmp == NULL) goto failed;\r | |
5692 | res = obj2ast_expr_context(tmp, &ctx, arena);\r | |
5693 | if (res != 0) goto failed;\r | |
5694 | Py_XDECREF(tmp);\r | |
5695 | tmp = NULL;\r | |
5696 | } else {\r | |
5697 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");\r | |
5698 | return 1;\r | |
5699 | }\r | |
5700 | *out = List(elts, ctx, lineno, col_offset, arena);\r | |
5701 | if (*out == NULL) goto failed;\r | |
5702 | return 0;\r | |
5703 | }\r | |
5704 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);\r | |
5705 | if (isinstance == -1) {\r | |
5706 | return 1;\r | |
5707 | }\r | |
5708 | if (isinstance) {\r | |
5709 | asdl_seq* elts;\r | |
5710 | expr_context_ty ctx;\r | |
5711 | \r | |
5712 | if (PyObject_HasAttrString(obj, "elts")) {\r | |
5713 | int res;\r | |
5714 | Py_ssize_t len;\r | |
5715 | Py_ssize_t i;\r | |
5716 | tmp = PyObject_GetAttrString(obj, "elts");\r | |
5717 | if (tmp == NULL) goto failed;\r | |
5718 | if (!PyList_Check(tmp)) {\r | |
5719 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5720 | goto failed;\r | |
5721 | }\r | |
5722 | len = PyList_GET_SIZE(tmp);\r | |
5723 | elts = asdl_seq_new(len, arena);\r | |
5724 | if (elts == NULL) goto failed;\r | |
5725 | for (i = 0; i < len; i++) {\r | |
5726 | expr_ty value;\r | |
5727 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5728 | if (res != 0) goto failed;\r | |
5729 | asdl_seq_SET(elts, i, value);\r | |
5730 | }\r | |
5731 | Py_XDECREF(tmp);\r | |
5732 | tmp = NULL;\r | |
5733 | } else {\r | |
5734 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");\r | |
5735 | return 1;\r | |
5736 | }\r | |
5737 | if (PyObject_HasAttrString(obj, "ctx")) {\r | |
5738 | int res;\r | |
5739 | tmp = PyObject_GetAttrString(obj, "ctx");\r | |
5740 | if (tmp == NULL) goto failed;\r | |
5741 | res = obj2ast_expr_context(tmp, &ctx, arena);\r | |
5742 | if (res != 0) goto failed;\r | |
5743 | Py_XDECREF(tmp);\r | |
5744 | tmp = NULL;\r | |
5745 | } else {\r | |
5746 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");\r | |
5747 | return 1;\r | |
5748 | }\r | |
5749 | *out = Tuple(elts, ctx, lineno, col_offset, arena);\r | |
5750 | if (*out == NULL) goto failed;\r | |
5751 | return 0;\r | |
5752 | }\r | |
5753 | \r | |
5754 | tmp = PyObject_Repr(obj);\r | |
5755 | if (tmp == NULL) goto failed;\r | |
5756 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));\r | |
5757 | failed:\r | |
5758 | Py_XDECREF(tmp);\r | |
5759 | return 1;\r | |
5760 | }\r | |
5761 | \r | |
5762 | int\r | |
5763 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)\r | |
5764 | {\r | |
5765 | PyObject* tmp = NULL;\r | |
5766 | int isinstance;\r | |
5767 | \r | |
5768 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);\r | |
5769 | if (isinstance == -1) {\r | |
5770 | return 1;\r | |
5771 | }\r | |
5772 | if (isinstance) {\r | |
5773 | *out = Load;\r | |
5774 | return 0;\r | |
5775 | }\r | |
5776 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);\r | |
5777 | if (isinstance == -1) {\r | |
5778 | return 1;\r | |
5779 | }\r | |
5780 | if (isinstance) {\r | |
5781 | *out = Store;\r | |
5782 | return 0;\r | |
5783 | }\r | |
5784 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);\r | |
5785 | if (isinstance == -1) {\r | |
5786 | return 1;\r | |
5787 | }\r | |
5788 | if (isinstance) {\r | |
5789 | *out = Del;\r | |
5790 | return 0;\r | |
5791 | }\r | |
5792 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);\r | |
5793 | if (isinstance == -1) {\r | |
5794 | return 1;\r | |
5795 | }\r | |
5796 | if (isinstance) {\r | |
5797 | *out = AugLoad;\r | |
5798 | return 0;\r | |
5799 | }\r | |
5800 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);\r | |
5801 | if (isinstance == -1) {\r | |
5802 | return 1;\r | |
5803 | }\r | |
5804 | if (isinstance) {\r | |
5805 | *out = AugStore;\r | |
5806 | return 0;\r | |
5807 | }\r | |
5808 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);\r | |
5809 | if (isinstance == -1) {\r | |
5810 | return 1;\r | |
5811 | }\r | |
5812 | if (isinstance) {\r | |
5813 | *out = Param;\r | |
5814 | return 0;\r | |
5815 | }\r | |
5816 | \r | |
5817 | tmp = PyObject_Repr(obj);\r | |
5818 | if (tmp == NULL) goto failed;\r | |
5819 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));\r | |
5820 | failed:\r | |
5821 | Py_XDECREF(tmp);\r | |
5822 | return 1;\r | |
5823 | }\r | |
5824 | \r | |
5825 | int\r | |
5826 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)\r | |
5827 | {\r | |
5828 | PyObject* tmp = NULL;\r | |
5829 | int isinstance;\r | |
5830 | \r | |
5831 | \r | |
5832 | if (obj == Py_None) {\r | |
5833 | *out = NULL;\r | |
5834 | return 0;\r | |
5835 | }\r | |
5836 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);\r | |
5837 | if (isinstance == -1) {\r | |
5838 | return 1;\r | |
5839 | }\r | |
5840 | if (isinstance) {\r | |
5841 | \r | |
5842 | *out = Ellipsis(arena);\r | |
5843 | if (*out == NULL) goto failed;\r | |
5844 | return 0;\r | |
5845 | }\r | |
5846 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);\r | |
5847 | if (isinstance == -1) {\r | |
5848 | return 1;\r | |
5849 | }\r | |
5850 | if (isinstance) {\r | |
5851 | expr_ty lower;\r | |
5852 | expr_ty upper;\r | |
5853 | expr_ty step;\r | |
5854 | \r | |
5855 | if (PyObject_HasAttrString(obj, "lower")) {\r | |
5856 | int res;\r | |
5857 | tmp = PyObject_GetAttrString(obj, "lower");\r | |
5858 | if (tmp == NULL) goto failed;\r | |
5859 | res = obj2ast_expr(tmp, &lower, arena);\r | |
5860 | if (res != 0) goto failed;\r | |
5861 | Py_XDECREF(tmp);\r | |
5862 | tmp = NULL;\r | |
5863 | } else {\r | |
5864 | lower = NULL;\r | |
5865 | }\r | |
5866 | if (PyObject_HasAttrString(obj, "upper")) {\r | |
5867 | int res;\r | |
5868 | tmp = PyObject_GetAttrString(obj, "upper");\r | |
5869 | if (tmp == NULL) goto failed;\r | |
5870 | res = obj2ast_expr(tmp, &upper, arena);\r | |
5871 | if (res != 0) goto failed;\r | |
5872 | Py_XDECREF(tmp);\r | |
5873 | tmp = NULL;\r | |
5874 | } else {\r | |
5875 | upper = NULL;\r | |
5876 | }\r | |
5877 | if (PyObject_HasAttrString(obj, "step")) {\r | |
5878 | int res;\r | |
5879 | tmp = PyObject_GetAttrString(obj, "step");\r | |
5880 | if (tmp == NULL) goto failed;\r | |
5881 | res = obj2ast_expr(tmp, &step, arena);\r | |
5882 | if (res != 0) goto failed;\r | |
5883 | Py_XDECREF(tmp);\r | |
5884 | tmp = NULL;\r | |
5885 | } else {\r | |
5886 | step = NULL;\r | |
5887 | }\r | |
5888 | *out = Slice(lower, upper, step, arena);\r | |
5889 | if (*out == NULL) goto failed;\r | |
5890 | return 0;\r | |
5891 | }\r | |
5892 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);\r | |
5893 | if (isinstance == -1) {\r | |
5894 | return 1;\r | |
5895 | }\r | |
5896 | if (isinstance) {\r | |
5897 | asdl_seq* dims;\r | |
5898 | \r | |
5899 | if (PyObject_HasAttrString(obj, "dims")) {\r | |
5900 | int res;\r | |
5901 | Py_ssize_t len;\r | |
5902 | Py_ssize_t i;\r | |
5903 | tmp = PyObject_GetAttrString(obj, "dims");\r | |
5904 | if (tmp == NULL) goto failed;\r | |
5905 | if (!PyList_Check(tmp)) {\r | |
5906 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
5907 | goto failed;\r | |
5908 | }\r | |
5909 | len = PyList_GET_SIZE(tmp);\r | |
5910 | dims = asdl_seq_new(len, arena);\r | |
5911 | if (dims == NULL) goto failed;\r | |
5912 | for (i = 0; i < len; i++) {\r | |
5913 | slice_ty value;\r | |
5914 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
5915 | if (res != 0) goto failed;\r | |
5916 | asdl_seq_SET(dims, i, value);\r | |
5917 | }\r | |
5918 | Py_XDECREF(tmp);\r | |
5919 | tmp = NULL;\r | |
5920 | } else {\r | |
5921 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");\r | |
5922 | return 1;\r | |
5923 | }\r | |
5924 | *out = ExtSlice(dims, arena);\r | |
5925 | if (*out == NULL) goto failed;\r | |
5926 | return 0;\r | |
5927 | }\r | |
5928 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);\r | |
5929 | if (isinstance == -1) {\r | |
5930 | return 1;\r | |
5931 | }\r | |
5932 | if (isinstance) {\r | |
5933 | expr_ty value;\r | |
5934 | \r | |
5935 | if (PyObject_HasAttrString(obj, "value")) {\r | |
5936 | int res;\r | |
5937 | tmp = PyObject_GetAttrString(obj, "value");\r | |
5938 | if (tmp == NULL) goto failed;\r | |
5939 | res = obj2ast_expr(tmp, &value, arena);\r | |
5940 | if (res != 0) goto failed;\r | |
5941 | Py_XDECREF(tmp);\r | |
5942 | tmp = NULL;\r | |
5943 | } else {\r | |
5944 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");\r | |
5945 | return 1;\r | |
5946 | }\r | |
5947 | *out = Index(value, arena);\r | |
5948 | if (*out == NULL) goto failed;\r | |
5949 | return 0;\r | |
5950 | }\r | |
5951 | \r | |
5952 | tmp = PyObject_Repr(obj);\r | |
5953 | if (tmp == NULL) goto failed;\r | |
5954 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));\r | |
5955 | failed:\r | |
5956 | Py_XDECREF(tmp);\r | |
5957 | return 1;\r | |
5958 | }\r | |
5959 | \r | |
5960 | int\r | |
5961 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)\r | |
5962 | {\r | |
5963 | PyObject* tmp = NULL;\r | |
5964 | int isinstance;\r | |
5965 | \r | |
5966 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);\r | |
5967 | if (isinstance == -1) {\r | |
5968 | return 1;\r | |
5969 | }\r | |
5970 | if (isinstance) {\r | |
5971 | *out = And;\r | |
5972 | return 0;\r | |
5973 | }\r | |
5974 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);\r | |
5975 | if (isinstance == -1) {\r | |
5976 | return 1;\r | |
5977 | }\r | |
5978 | if (isinstance) {\r | |
5979 | *out = Or;\r | |
5980 | return 0;\r | |
5981 | }\r | |
5982 | \r | |
5983 | tmp = PyObject_Repr(obj);\r | |
5984 | if (tmp == NULL) goto failed;\r | |
5985 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));\r | |
5986 | failed:\r | |
5987 | Py_XDECREF(tmp);\r | |
5988 | return 1;\r | |
5989 | }\r | |
5990 | \r | |
5991 | int\r | |
5992 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)\r | |
5993 | {\r | |
5994 | PyObject* tmp = NULL;\r | |
5995 | int isinstance;\r | |
5996 | \r | |
5997 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);\r | |
5998 | if (isinstance == -1) {\r | |
5999 | return 1;\r | |
6000 | }\r | |
6001 | if (isinstance) {\r | |
6002 | *out = Add;\r | |
6003 | return 0;\r | |
6004 | }\r | |
6005 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);\r | |
6006 | if (isinstance == -1) {\r | |
6007 | return 1;\r | |
6008 | }\r | |
6009 | if (isinstance) {\r | |
6010 | *out = Sub;\r | |
6011 | return 0;\r | |
6012 | }\r | |
6013 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);\r | |
6014 | if (isinstance == -1) {\r | |
6015 | return 1;\r | |
6016 | }\r | |
6017 | if (isinstance) {\r | |
6018 | *out = Mult;\r | |
6019 | return 0;\r | |
6020 | }\r | |
6021 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);\r | |
6022 | if (isinstance == -1) {\r | |
6023 | return 1;\r | |
6024 | }\r | |
6025 | if (isinstance) {\r | |
6026 | *out = Div;\r | |
6027 | return 0;\r | |
6028 | }\r | |
6029 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);\r | |
6030 | if (isinstance == -1) {\r | |
6031 | return 1;\r | |
6032 | }\r | |
6033 | if (isinstance) {\r | |
6034 | *out = Mod;\r | |
6035 | return 0;\r | |
6036 | }\r | |
6037 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);\r | |
6038 | if (isinstance == -1) {\r | |
6039 | return 1;\r | |
6040 | }\r | |
6041 | if (isinstance) {\r | |
6042 | *out = Pow;\r | |
6043 | return 0;\r | |
6044 | }\r | |
6045 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);\r | |
6046 | if (isinstance == -1) {\r | |
6047 | return 1;\r | |
6048 | }\r | |
6049 | if (isinstance) {\r | |
6050 | *out = LShift;\r | |
6051 | return 0;\r | |
6052 | }\r | |
6053 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);\r | |
6054 | if (isinstance == -1) {\r | |
6055 | return 1;\r | |
6056 | }\r | |
6057 | if (isinstance) {\r | |
6058 | *out = RShift;\r | |
6059 | return 0;\r | |
6060 | }\r | |
6061 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);\r | |
6062 | if (isinstance == -1) {\r | |
6063 | return 1;\r | |
6064 | }\r | |
6065 | if (isinstance) {\r | |
6066 | *out = BitOr;\r | |
6067 | return 0;\r | |
6068 | }\r | |
6069 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);\r | |
6070 | if (isinstance == -1) {\r | |
6071 | return 1;\r | |
6072 | }\r | |
6073 | if (isinstance) {\r | |
6074 | *out = BitXor;\r | |
6075 | return 0;\r | |
6076 | }\r | |
6077 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);\r | |
6078 | if (isinstance == -1) {\r | |
6079 | return 1;\r | |
6080 | }\r | |
6081 | if (isinstance) {\r | |
6082 | *out = BitAnd;\r | |
6083 | return 0;\r | |
6084 | }\r | |
6085 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);\r | |
6086 | if (isinstance == -1) {\r | |
6087 | return 1;\r | |
6088 | }\r | |
6089 | if (isinstance) {\r | |
6090 | *out = FloorDiv;\r | |
6091 | return 0;\r | |
6092 | }\r | |
6093 | \r | |
6094 | tmp = PyObject_Repr(obj);\r | |
6095 | if (tmp == NULL) goto failed;\r | |
6096 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));\r | |
6097 | failed:\r | |
6098 | Py_XDECREF(tmp);\r | |
6099 | return 1;\r | |
6100 | }\r | |
6101 | \r | |
6102 | int\r | |
6103 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)\r | |
6104 | {\r | |
6105 | PyObject* tmp = NULL;\r | |
6106 | int isinstance;\r | |
6107 | \r | |
6108 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);\r | |
6109 | if (isinstance == -1) {\r | |
6110 | return 1;\r | |
6111 | }\r | |
6112 | if (isinstance) {\r | |
6113 | *out = Invert;\r | |
6114 | return 0;\r | |
6115 | }\r | |
6116 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);\r | |
6117 | if (isinstance == -1) {\r | |
6118 | return 1;\r | |
6119 | }\r | |
6120 | if (isinstance) {\r | |
6121 | *out = Not;\r | |
6122 | return 0;\r | |
6123 | }\r | |
6124 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);\r | |
6125 | if (isinstance == -1) {\r | |
6126 | return 1;\r | |
6127 | }\r | |
6128 | if (isinstance) {\r | |
6129 | *out = UAdd;\r | |
6130 | return 0;\r | |
6131 | }\r | |
6132 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);\r | |
6133 | if (isinstance == -1) {\r | |
6134 | return 1;\r | |
6135 | }\r | |
6136 | if (isinstance) {\r | |
6137 | *out = USub;\r | |
6138 | return 0;\r | |
6139 | }\r | |
6140 | \r | |
6141 | tmp = PyObject_Repr(obj);\r | |
6142 | if (tmp == NULL) goto failed;\r | |
6143 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));\r | |
6144 | failed:\r | |
6145 | Py_XDECREF(tmp);\r | |
6146 | return 1;\r | |
6147 | }\r | |
6148 | \r | |
6149 | int\r | |
6150 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)\r | |
6151 | {\r | |
6152 | PyObject* tmp = NULL;\r | |
6153 | int isinstance;\r | |
6154 | \r | |
6155 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);\r | |
6156 | if (isinstance == -1) {\r | |
6157 | return 1;\r | |
6158 | }\r | |
6159 | if (isinstance) {\r | |
6160 | *out = Eq;\r | |
6161 | return 0;\r | |
6162 | }\r | |
6163 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);\r | |
6164 | if (isinstance == -1) {\r | |
6165 | return 1;\r | |
6166 | }\r | |
6167 | if (isinstance) {\r | |
6168 | *out = NotEq;\r | |
6169 | return 0;\r | |
6170 | }\r | |
6171 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);\r | |
6172 | if (isinstance == -1) {\r | |
6173 | return 1;\r | |
6174 | }\r | |
6175 | if (isinstance) {\r | |
6176 | *out = Lt;\r | |
6177 | return 0;\r | |
6178 | }\r | |
6179 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);\r | |
6180 | if (isinstance == -1) {\r | |
6181 | return 1;\r | |
6182 | }\r | |
6183 | if (isinstance) {\r | |
6184 | *out = LtE;\r | |
6185 | return 0;\r | |
6186 | }\r | |
6187 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);\r | |
6188 | if (isinstance == -1) {\r | |
6189 | return 1;\r | |
6190 | }\r | |
6191 | if (isinstance) {\r | |
6192 | *out = Gt;\r | |
6193 | return 0;\r | |
6194 | }\r | |
6195 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);\r | |
6196 | if (isinstance == -1) {\r | |
6197 | return 1;\r | |
6198 | }\r | |
6199 | if (isinstance) {\r | |
6200 | *out = GtE;\r | |
6201 | return 0;\r | |
6202 | }\r | |
6203 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);\r | |
6204 | if (isinstance == -1) {\r | |
6205 | return 1;\r | |
6206 | }\r | |
6207 | if (isinstance) {\r | |
6208 | *out = Is;\r | |
6209 | return 0;\r | |
6210 | }\r | |
6211 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);\r | |
6212 | if (isinstance == -1) {\r | |
6213 | return 1;\r | |
6214 | }\r | |
6215 | if (isinstance) {\r | |
6216 | *out = IsNot;\r | |
6217 | return 0;\r | |
6218 | }\r | |
6219 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);\r | |
6220 | if (isinstance == -1) {\r | |
6221 | return 1;\r | |
6222 | }\r | |
6223 | if (isinstance) {\r | |
6224 | *out = In;\r | |
6225 | return 0;\r | |
6226 | }\r | |
6227 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);\r | |
6228 | if (isinstance == -1) {\r | |
6229 | return 1;\r | |
6230 | }\r | |
6231 | if (isinstance) {\r | |
6232 | *out = NotIn;\r | |
6233 | return 0;\r | |
6234 | }\r | |
6235 | \r | |
6236 | tmp = PyObject_Repr(obj);\r | |
6237 | if (tmp == NULL) goto failed;\r | |
6238 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));\r | |
6239 | failed:\r | |
6240 | Py_XDECREF(tmp);\r | |
6241 | return 1;\r | |
6242 | }\r | |
6243 | \r | |
6244 | int\r | |
6245 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)\r | |
6246 | {\r | |
6247 | PyObject* tmp = NULL;\r | |
6248 | expr_ty target;\r | |
6249 | expr_ty iter;\r | |
6250 | asdl_seq* ifs;\r | |
6251 | \r | |
6252 | if (PyObject_HasAttrString(obj, "target")) {\r | |
6253 | int res;\r | |
6254 | tmp = PyObject_GetAttrString(obj, "target");\r | |
6255 | if (tmp == NULL) goto failed;\r | |
6256 | res = obj2ast_expr(tmp, &target, arena);\r | |
6257 | if (res != 0) goto failed;\r | |
6258 | Py_XDECREF(tmp);\r | |
6259 | tmp = NULL;\r | |
6260 | } else {\r | |
6261 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");\r | |
6262 | return 1;\r | |
6263 | }\r | |
6264 | if (PyObject_HasAttrString(obj, "iter")) {\r | |
6265 | int res;\r | |
6266 | tmp = PyObject_GetAttrString(obj, "iter");\r | |
6267 | if (tmp == NULL) goto failed;\r | |
6268 | res = obj2ast_expr(tmp, &iter, arena);\r | |
6269 | if (res != 0) goto failed;\r | |
6270 | Py_XDECREF(tmp);\r | |
6271 | tmp = NULL;\r | |
6272 | } else {\r | |
6273 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");\r | |
6274 | return 1;\r | |
6275 | }\r | |
6276 | if (PyObject_HasAttrString(obj, "ifs")) {\r | |
6277 | int res;\r | |
6278 | Py_ssize_t len;\r | |
6279 | Py_ssize_t i;\r | |
6280 | tmp = PyObject_GetAttrString(obj, "ifs");\r | |
6281 | if (tmp == NULL) goto failed;\r | |
6282 | if (!PyList_Check(tmp)) {\r | |
6283 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
6284 | goto failed;\r | |
6285 | }\r | |
6286 | len = PyList_GET_SIZE(tmp);\r | |
6287 | ifs = asdl_seq_new(len, arena);\r | |
6288 | if (ifs == NULL) goto failed;\r | |
6289 | for (i = 0; i < len; i++) {\r | |
6290 | expr_ty value;\r | |
6291 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
6292 | if (res != 0) goto failed;\r | |
6293 | asdl_seq_SET(ifs, i, value);\r | |
6294 | }\r | |
6295 | Py_XDECREF(tmp);\r | |
6296 | tmp = NULL;\r | |
6297 | } else {\r | |
6298 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");\r | |
6299 | return 1;\r | |
6300 | }\r | |
6301 | *out = comprehension(target, iter, ifs, arena);\r | |
6302 | return 0;\r | |
6303 | failed:\r | |
6304 | Py_XDECREF(tmp);\r | |
6305 | return 1;\r | |
6306 | }\r | |
6307 | \r | |
6308 | int\r | |
6309 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)\r | |
6310 | {\r | |
6311 | PyObject* tmp = NULL;\r | |
6312 | int isinstance;\r | |
6313 | \r | |
6314 | int lineno;\r | |
6315 | int col_offset;\r | |
6316 | \r | |
6317 | if (obj == Py_None) {\r | |
6318 | *out = NULL;\r | |
6319 | return 0;\r | |
6320 | }\r | |
6321 | if (PyObject_HasAttrString(obj, "lineno")) {\r | |
6322 | int res;\r | |
6323 | tmp = PyObject_GetAttrString(obj, "lineno");\r | |
6324 | if (tmp == NULL) goto failed;\r | |
6325 | res = obj2ast_int(tmp, &lineno, arena);\r | |
6326 | if (res != 0) goto failed;\r | |
6327 | Py_XDECREF(tmp);\r | |
6328 | tmp = NULL;\r | |
6329 | } else {\r | |
6330 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");\r | |
6331 | return 1;\r | |
6332 | }\r | |
6333 | if (PyObject_HasAttrString(obj, "col_offset")) {\r | |
6334 | int res;\r | |
6335 | tmp = PyObject_GetAttrString(obj, "col_offset");\r | |
6336 | if (tmp == NULL) goto failed;\r | |
6337 | res = obj2ast_int(tmp, &col_offset, arena);\r | |
6338 | if (res != 0) goto failed;\r | |
6339 | Py_XDECREF(tmp);\r | |
6340 | tmp = NULL;\r | |
6341 | } else {\r | |
6342 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");\r | |
6343 | return 1;\r | |
6344 | }\r | |
6345 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);\r | |
6346 | if (isinstance == -1) {\r | |
6347 | return 1;\r | |
6348 | }\r | |
6349 | if (isinstance) {\r | |
6350 | expr_ty type;\r | |
6351 | expr_ty name;\r | |
6352 | asdl_seq* body;\r | |
6353 | \r | |
6354 | if (PyObject_HasAttrString(obj, "type")) {\r | |
6355 | int res;\r | |
6356 | tmp = PyObject_GetAttrString(obj, "type");\r | |
6357 | if (tmp == NULL) goto failed;\r | |
6358 | res = obj2ast_expr(tmp, &type, arena);\r | |
6359 | if (res != 0) goto failed;\r | |
6360 | Py_XDECREF(tmp);\r | |
6361 | tmp = NULL;\r | |
6362 | } else {\r | |
6363 | type = NULL;\r | |
6364 | }\r | |
6365 | if (PyObject_HasAttrString(obj, "name")) {\r | |
6366 | int res;\r | |
6367 | tmp = PyObject_GetAttrString(obj, "name");\r | |
6368 | if (tmp == NULL) goto failed;\r | |
6369 | res = obj2ast_expr(tmp, &name, arena);\r | |
6370 | if (res != 0) goto failed;\r | |
6371 | Py_XDECREF(tmp);\r | |
6372 | tmp = NULL;\r | |
6373 | } else {\r | |
6374 | name = NULL;\r | |
6375 | }\r | |
6376 | if (PyObject_HasAttrString(obj, "body")) {\r | |
6377 | int res;\r | |
6378 | Py_ssize_t len;\r | |
6379 | Py_ssize_t i;\r | |
6380 | tmp = PyObject_GetAttrString(obj, "body");\r | |
6381 | if (tmp == NULL) goto failed;\r | |
6382 | if (!PyList_Check(tmp)) {\r | |
6383 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
6384 | goto failed;\r | |
6385 | }\r | |
6386 | len = PyList_GET_SIZE(tmp);\r | |
6387 | body = asdl_seq_new(len, arena);\r | |
6388 | if (body == NULL) goto failed;\r | |
6389 | for (i = 0; i < len; i++) {\r | |
6390 | stmt_ty value;\r | |
6391 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
6392 | if (res != 0) goto failed;\r | |
6393 | asdl_seq_SET(body, i, value);\r | |
6394 | }\r | |
6395 | Py_XDECREF(tmp);\r | |
6396 | tmp = NULL;\r | |
6397 | } else {\r | |
6398 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");\r | |
6399 | return 1;\r | |
6400 | }\r | |
6401 | *out = ExceptHandler(type, name, body, lineno, col_offset,\r | |
6402 | arena);\r | |
6403 | if (*out == NULL) goto failed;\r | |
6404 | return 0;\r | |
6405 | }\r | |
6406 | \r | |
6407 | tmp = PyObject_Repr(obj);\r | |
6408 | if (tmp == NULL) goto failed;\r | |
6409 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));\r | |
6410 | failed:\r | |
6411 | Py_XDECREF(tmp);\r | |
6412 | return 1;\r | |
6413 | }\r | |
6414 | \r | |
6415 | int\r | |
6416 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)\r | |
6417 | {\r | |
6418 | PyObject* tmp = NULL;\r | |
6419 | asdl_seq* args;\r | |
6420 | identifier vararg;\r | |
6421 | identifier kwarg;\r | |
6422 | asdl_seq* defaults;\r | |
6423 | \r | |
6424 | if (PyObject_HasAttrString(obj, "args")) {\r | |
6425 | int res;\r | |
6426 | Py_ssize_t len;\r | |
6427 | Py_ssize_t i;\r | |
6428 | tmp = PyObject_GetAttrString(obj, "args");\r | |
6429 | if (tmp == NULL) goto failed;\r | |
6430 | if (!PyList_Check(tmp)) {\r | |
6431 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
6432 | goto failed;\r | |
6433 | }\r | |
6434 | len = PyList_GET_SIZE(tmp);\r | |
6435 | args = asdl_seq_new(len, arena);\r | |
6436 | if (args == NULL) goto failed;\r | |
6437 | for (i = 0; i < len; i++) {\r | |
6438 | expr_ty value;\r | |
6439 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
6440 | if (res != 0) goto failed;\r | |
6441 | asdl_seq_SET(args, i, value);\r | |
6442 | }\r | |
6443 | Py_XDECREF(tmp);\r | |
6444 | tmp = NULL;\r | |
6445 | } else {\r | |
6446 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");\r | |
6447 | return 1;\r | |
6448 | }\r | |
6449 | if (PyObject_HasAttrString(obj, "vararg")) {\r | |
6450 | int res;\r | |
6451 | tmp = PyObject_GetAttrString(obj, "vararg");\r | |
6452 | if (tmp == NULL) goto failed;\r | |
6453 | res = obj2ast_identifier(tmp, &vararg, arena);\r | |
6454 | if (res != 0) goto failed;\r | |
6455 | Py_XDECREF(tmp);\r | |
6456 | tmp = NULL;\r | |
6457 | } else {\r | |
6458 | vararg = NULL;\r | |
6459 | }\r | |
6460 | if (PyObject_HasAttrString(obj, "kwarg")) {\r | |
6461 | int res;\r | |
6462 | tmp = PyObject_GetAttrString(obj, "kwarg");\r | |
6463 | if (tmp == NULL) goto failed;\r | |
6464 | res = obj2ast_identifier(tmp, &kwarg, arena);\r | |
6465 | if (res != 0) goto failed;\r | |
6466 | Py_XDECREF(tmp);\r | |
6467 | tmp = NULL;\r | |
6468 | } else {\r | |
6469 | kwarg = NULL;\r | |
6470 | }\r | |
6471 | if (PyObject_HasAttrString(obj, "defaults")) {\r | |
6472 | int res;\r | |
6473 | Py_ssize_t len;\r | |
6474 | Py_ssize_t i;\r | |
6475 | tmp = PyObject_GetAttrString(obj, "defaults");\r | |
6476 | if (tmp == NULL) goto failed;\r | |
6477 | if (!PyList_Check(tmp)) {\r | |
6478 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r | |
6479 | goto failed;\r | |
6480 | }\r | |
6481 | len = PyList_GET_SIZE(tmp);\r | |
6482 | defaults = asdl_seq_new(len, arena);\r | |
6483 | if (defaults == NULL) goto failed;\r | |
6484 | for (i = 0; i < len; i++) {\r | |
6485 | expr_ty value;\r | |
6486 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r | |
6487 | if (res != 0) goto failed;\r | |
6488 | asdl_seq_SET(defaults, i, value);\r | |
6489 | }\r | |
6490 | Py_XDECREF(tmp);\r | |
6491 | tmp = NULL;\r | |
6492 | } else {\r | |
6493 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");\r | |
6494 | return 1;\r | |
6495 | }\r | |
6496 | *out = arguments(args, vararg, kwarg, defaults, arena);\r | |
6497 | return 0;\r | |
6498 | failed:\r | |
6499 | Py_XDECREF(tmp);\r | |
6500 | return 1;\r | |
6501 | }\r | |
6502 | \r | |
6503 | int\r | |
6504 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)\r | |
6505 | {\r | |
6506 | PyObject* tmp = NULL;\r | |
6507 | identifier arg;\r | |
6508 | expr_ty value;\r | |
6509 | \r | |
6510 | if (PyObject_HasAttrString(obj, "arg")) {\r | |
6511 | int res;\r | |
6512 | tmp = PyObject_GetAttrString(obj, "arg");\r | |
6513 | if (tmp == NULL) goto failed;\r | |
6514 | res = obj2ast_identifier(tmp, &arg, arena);\r | |
6515 | if (res != 0) goto failed;\r | |
6516 | Py_XDECREF(tmp);\r | |
6517 | tmp = NULL;\r | |
6518 | } else {\r | |
6519 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");\r | |
6520 | return 1;\r | |
6521 | }\r | |
6522 | if (PyObject_HasAttrString(obj, "value")) {\r | |
6523 | int res;\r | |
6524 | tmp = PyObject_GetAttrString(obj, "value");\r | |
6525 | if (tmp == NULL) goto failed;\r | |
6526 | res = obj2ast_expr(tmp, &value, arena);\r | |
6527 | if (res != 0) goto failed;\r | |
6528 | Py_XDECREF(tmp);\r | |
6529 | tmp = NULL;\r | |
6530 | } else {\r | |
6531 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");\r | |
6532 | return 1;\r | |
6533 | }\r | |
6534 | *out = keyword(arg, value, arena);\r | |
6535 | return 0;\r | |
6536 | failed:\r | |
6537 | Py_XDECREF(tmp);\r | |
6538 | return 1;\r | |
6539 | }\r | |
6540 | \r | |
6541 | int\r | |
6542 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)\r | |
6543 | {\r | |
6544 | PyObject* tmp = NULL;\r | |
6545 | identifier name;\r | |
6546 | identifier asname;\r | |
6547 | \r | |
6548 | if (PyObject_HasAttrString(obj, "name")) {\r | |
6549 | int res;\r | |
6550 | tmp = PyObject_GetAttrString(obj, "name");\r | |
6551 | if (tmp == NULL) goto failed;\r | |
6552 | res = obj2ast_identifier(tmp, &name, arena);\r | |
6553 | if (res != 0) goto failed;\r | |
6554 | Py_XDECREF(tmp);\r | |
6555 | tmp = NULL;\r | |
6556 | } else {\r | |
6557 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");\r | |
6558 | return 1;\r | |
6559 | }\r | |
6560 | if (PyObject_HasAttrString(obj, "asname")) {\r | |
6561 | int res;\r | |
6562 | tmp = PyObject_GetAttrString(obj, "asname");\r | |
6563 | if (tmp == NULL) goto failed;\r | |
6564 | res = obj2ast_identifier(tmp, &asname, arena);\r | |
6565 | if (res != 0) goto failed;\r | |
6566 | Py_XDECREF(tmp);\r | |
6567 | tmp = NULL;\r | |
6568 | } else {\r | |
6569 | asname = NULL;\r | |
6570 | }\r | |
6571 | *out = alias(name, asname, arena);\r | |
6572 | return 0;\r | |
6573 | failed:\r | |
6574 | Py_XDECREF(tmp);\r | |
6575 | return 1;\r | |
6576 | }\r | |
6577 | \r | |
6578 | \r | |
6579 | PyMODINIT_FUNC\r | |
6580 | init_ast(void)\r | |
6581 | {\r | |
6582 | PyObject *m, *d;\r | |
6583 | if (!init_types()) return;\r | |
6584 | m = Py_InitModule3("_ast", NULL, NULL);\r | |
6585 | if (!m) return;\r | |
6586 | d = PyModule_GetDict(m);\r | |
6587 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;\r | |
6588 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)\r | |
6589 | return;\r | |
6590 | if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)\r | |
6591 | return;\r | |
6592 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;\r | |
6593 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)\r | |
6594 | return;\r | |
6595 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)\r | |
6596 | < 0) return;\r | |
6597 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <\r | |
6598 | 0) return;\r | |
6599 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;\r | |
6600 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;\r | |
6601 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)\r | |
6602 | < 0) return;\r | |
6603 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)\r | |
6604 | return;\r | |
6605 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)\r | |
6606 | return;\r | |
6607 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)\r | |
6608 | return;\r | |
6609 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)\r | |
6610 | return;\r | |
6611 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <\r | |
6612 | 0) return;\r | |
6613 | if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;\r | |
6614 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;\r | |
6615 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;\r | |
6616 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;\r | |
6617 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;\r | |
6618 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;\r | |
6619 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <\r | |
6620 | 0) return;\r | |
6621 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <\r | |
6622 | 0) return;\r | |
6623 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)\r | |
6624 | return;\r | |
6625 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)\r | |
6626 | return;\r | |
6627 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <\r | |
6628 | 0) return;\r | |
6629 | if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;\r | |
6630 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)\r | |
6631 | return;\r | |
6632 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;\r | |
6633 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;\r | |
6634 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;\r | |
6635 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)\r | |
6636 | return;\r | |
6637 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;\r | |
6638 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)\r | |
6639 | return;\r | |
6640 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;\r | |
6641 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)\r | |
6642 | return;\r | |
6643 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)\r | |
6644 | return;\r | |
6645 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;\r | |
6646 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;\r | |
6647 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;\r | |
6648 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)\r | |
6649 | return;\r | |
6650 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)\r | |
6651 | return;\r | |
6652 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)\r | |
6653 | return;\r | |
6654 | if (PyDict_SetItemString(d, "GeneratorExp",\r | |
6655 | (PyObject*)GeneratorExp_type) < 0) return;\r | |
6656 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;\r | |
6657 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)\r | |
6658 | return;\r | |
6659 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;\r | |
6660 | if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;\r | |
6661 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;\r | |
6662 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;\r | |
6663 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <\r | |
6664 | 0) return;\r | |
6665 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <\r | |
6666 | 0) return;\r | |
6667 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;\r | |
6668 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;\r | |
6669 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;\r | |
6670 | if (PyDict_SetItemString(d, "expr_context",\r | |
6671 | (PyObject*)expr_context_type) < 0) return;\r | |
6672 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;\r | |
6673 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;\r | |
6674 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;\r | |
6675 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)\r | |
6676 | return;\r | |
6677 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)\r | |
6678 | return;\r | |
6679 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;\r | |
6680 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;\r | |
6681 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)\r | |
6682 | return;\r | |
6683 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;\r | |
6684 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)\r | |
6685 | return;\r | |
6686 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;\r | |
6687 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)\r | |
6688 | return;\r | |
6689 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;\r | |
6690 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;\r | |
6691 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)\r | |
6692 | return;\r | |
6693 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;\r | |
6694 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;\r | |
6695 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;\r | |
6696 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;\r | |
6697 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;\r | |
6698 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;\r | |
6699 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)\r | |
6700 | return;\r | |
6701 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)\r | |
6702 | return;\r | |
6703 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;\r | |
6704 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)\r | |
6705 | return;\r | |
6706 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)\r | |
6707 | return;\r | |
6708 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)\r | |
6709 | return;\r | |
6710 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)\r | |
6711 | return;\r | |
6712 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)\r | |
6713 | return;\r | |
6714 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;\r | |
6715 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;\r | |
6716 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;\r | |
6717 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;\r | |
6718 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;\r | |
6719 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;\r | |
6720 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;\r | |
6721 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;\r | |
6722 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;\r | |
6723 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;\r | |
6724 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;\r | |
6725 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;\r | |
6726 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;\r | |
6727 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;\r | |
6728 | if (PyDict_SetItemString(d, "comprehension",\r | |
6729 | (PyObject*)comprehension_type) < 0) return;\r | |
6730 | if (PyDict_SetItemString(d, "excepthandler",\r | |
6731 | (PyObject*)excepthandler_type) < 0) return;\r | |
6732 | if (PyDict_SetItemString(d, "ExceptHandler",\r | |
6733 | (PyObject*)ExceptHandler_type) < 0) return;\r | |
6734 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <\r | |
6735 | 0) return;\r | |
6736 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)\r | |
6737 | return;\r | |
6738 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;\r | |
6739 | }\r | |
6740 | \r | |
6741 | \r | |
6742 | PyObject* PyAST_mod2obj(mod_ty t)\r | |
6743 | {\r | |
6744 | init_types();\r | |
6745 | return ast2obj_mod(t);\r | |
6746 | }\r | |
6747 | \r | |
6748 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */\r | |
6749 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)\r | |
6750 | {\r | |
6751 | mod_ty res;\r | |
6752 | PyObject *req_type[3];\r | |
6753 | char *req_name[3];\r | |
6754 | int isinstance;\r | |
6755 | \r | |
6756 | req_type[0] = (PyObject*)Module_type;\r | |
6757 | req_type[1] = (PyObject*)Expression_type;\r | |
6758 | req_type[2] = (PyObject*)Interactive_type;\r | |
6759 | \r | |
6760 | req_name[0] = "Module";\r | |
6761 | req_name[1] = "Expression";\r | |
6762 | req_name[2] = "Interactive";\r | |
6763 | \r | |
6764 | assert(0 <= mode && mode <= 2);\r | |
6765 | \r | |
6766 | init_types();\r | |
6767 | \r | |
6768 | isinstance = PyObject_IsInstance(ast, req_type[mode]);\r | |
6769 | if (isinstance == -1)\r | |
6770 | return NULL;\r | |
6771 | if (!isinstance) {\r | |
6772 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",\r | |
6773 | req_name[mode], Py_TYPE(ast)->tp_name);\r | |
6774 | return NULL;\r | |
6775 | }\r | |
6776 | if (obj2ast_mod(ast, &res, arena) != 0)\r | |
6777 | return NULL;\r | |
6778 | else\r | |
6779 | return res;\r | |
6780 | }\r | |
6781 | \r | |
6782 | int PyAST_Check(PyObject* obj)\r | |
6783 | {\r | |
6784 | init_types();\r | |
6785 | return PyObject_IsInstance(obj, (PyObject*)&AST_type);\r | |
6786 | }\r | |
6787 | \r | |
6788 | \r |