Coverage Report

Created: 2025-07-11 06:59

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