ยปCore Development>Code coverage>Python/Python-ast.c

Python code coverage for Python/Python-ast.c

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