Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Python/Python-ast.c
Line
Count
Source
1
// File automatically generated by Parser/asdl_c.py.
2
3
#include "Python.h"
4
#include "pycore_ast.h"
5
#include "pycore_ast_state.h"     // struct ast_state
6
#include "pycore_ceval.h"         // _Py_EnterRecursiveCall()
7
#include "pycore_lock.h"          // _PyOnceFlag
8
#include "pycore_modsupport.h"    // _PyArg_NoPositional()
9
#include "pycore_pystate.h"       // _PyInterpreterState_GET()
10
#include "pycore_runtime.h"       // _Py_ID()
11
#include "pycore_setobject.h"     // _PySet_NextEntry()
12
#include "pycore_unionobject.h"   // _Py_union_type_or
13
14
#include <stddef.h>               // offsetof()
15
16
17
// Forward declaration
18
static int init_types(void *arg);
19
20
static struct ast_state*
21
get_ast_state(void)
22
72.1k
{
23
72.1k
    PyInterpreterState *interp = _PyInterpreterState_GET();
24
72.1k
    struct ast_state *state = &interp->ast;
25
72.1k
    assert(!state->finalized);
26
72.1k
    if (_PyOnceFlag_CallOnce(&state->once, (_Py_once_fn_t *)&init_types, state) < 0) {
27
0
        return NULL;
28
0
    }
29
72.1k
    return state;
30
72.1k
}
31
32
void _PyAST_Fini(PyInterpreterState *interp)
33
0
{
34
0
    struct ast_state *state = &interp->ast;
35
36
0
    static const size_t offsets[] = {
37
0
        offsetof(struct ast_state, AST_type),
38
0
        offsetof(struct ast_state, Add_singleton),
39
0
        offsetof(struct ast_state, Add_type),
40
0
        offsetof(struct ast_state, And_singleton),
41
0
        offsetof(struct ast_state, And_type),
42
0
        offsetof(struct ast_state, AnnAssign_type),
43
0
        offsetof(struct ast_state, Assert_type),
44
0
        offsetof(struct ast_state, Assign_type),
45
0
        offsetof(struct ast_state, AsyncFor_type),
46
0
        offsetof(struct ast_state, AsyncFunctionDef_type),
47
0
        offsetof(struct ast_state, AsyncWith_type),
48
0
        offsetof(struct ast_state, Attribute_type),
49
0
        offsetof(struct ast_state, AugAssign_type),
50
0
        offsetof(struct ast_state, Await_type),
51
0
        offsetof(struct ast_state, BinOp_type),
52
0
        offsetof(struct ast_state, BitAnd_singleton),
53
0
        offsetof(struct ast_state, BitAnd_type),
54
0
        offsetof(struct ast_state, BitOr_singleton),
55
0
        offsetof(struct ast_state, BitOr_type),
56
0
        offsetof(struct ast_state, BitXor_singleton),
57
0
        offsetof(struct ast_state, BitXor_type),
58
0
        offsetof(struct ast_state, BoolOp_type),
59
0
        offsetof(struct ast_state, Break_type),
60
0
        offsetof(struct ast_state, Call_type),
61
0
        offsetof(struct ast_state, ClassDef_type),
62
0
        offsetof(struct ast_state, Compare_type),
63
0
        offsetof(struct ast_state, Constant_type),
64
0
        offsetof(struct ast_state, Continue_type),
65
0
        offsetof(struct ast_state, Del_singleton),
66
0
        offsetof(struct ast_state, Del_type),
67
0
        offsetof(struct ast_state, Delete_type),
68
0
        offsetof(struct ast_state, DictComp_type),
69
0
        offsetof(struct ast_state, Dict_type),
70
0
        offsetof(struct ast_state, Div_singleton),
71
0
        offsetof(struct ast_state, Div_type),
72
0
        offsetof(struct ast_state, Eq_singleton),
73
0
        offsetof(struct ast_state, Eq_type),
74
0
        offsetof(struct ast_state, ExceptHandler_type),
75
0
        offsetof(struct ast_state, Expr_type),
76
0
        offsetof(struct ast_state, Expression_type),
77
0
        offsetof(struct ast_state, FloorDiv_singleton),
78
0
        offsetof(struct ast_state, FloorDiv_type),
79
0
        offsetof(struct ast_state, For_type),
80
0
        offsetof(struct ast_state, FormattedValue_type),
81
0
        offsetof(struct ast_state, FunctionDef_type),
82
0
        offsetof(struct ast_state, FunctionType_type),
83
0
        offsetof(struct ast_state, GeneratorExp_type),
84
0
        offsetof(struct ast_state, Global_type),
85
0
        offsetof(struct ast_state, GtE_singleton),
86
0
        offsetof(struct ast_state, GtE_type),
87
0
        offsetof(struct ast_state, Gt_singleton),
88
0
        offsetof(struct ast_state, Gt_type),
89
0
        offsetof(struct ast_state, IfExp_type),
90
0
        offsetof(struct ast_state, If_type),
91
0
        offsetof(struct ast_state, ImportFrom_type),
92
0
        offsetof(struct ast_state, Import_type),
93
0
        offsetof(struct ast_state, In_singleton),
94
0
        offsetof(struct ast_state, In_type),
95
0
        offsetof(struct ast_state, Interactive_type),
96
0
        offsetof(struct ast_state, Interpolation_type),
97
0
        offsetof(struct ast_state, Invert_singleton),
98
0
        offsetof(struct ast_state, Invert_type),
99
0
        offsetof(struct ast_state, IsNot_singleton),
100
0
        offsetof(struct ast_state, IsNot_type),
101
0
        offsetof(struct ast_state, Is_singleton),
102
0
        offsetof(struct ast_state, Is_type),
103
0
        offsetof(struct ast_state, JoinedStr_type),
104
0
        offsetof(struct ast_state, LShift_singleton),
105
0
        offsetof(struct ast_state, LShift_type),
106
0
        offsetof(struct ast_state, Lambda_type),
107
0
        offsetof(struct ast_state, ListComp_type),
108
0
        offsetof(struct ast_state, List_type),
109
0
        offsetof(struct ast_state, Load_singleton),
110
0
        offsetof(struct ast_state, Load_type),
111
0
        offsetof(struct ast_state, LtE_singleton),
112
0
        offsetof(struct ast_state, LtE_type),
113
0
        offsetof(struct ast_state, Lt_singleton),
114
0
        offsetof(struct ast_state, Lt_type),
115
0
        offsetof(struct ast_state, MatMult_singleton),
116
0
        offsetof(struct ast_state, MatMult_type),
117
0
        offsetof(struct ast_state, MatchAs_type),
118
0
        offsetof(struct ast_state, MatchClass_type),
119
0
        offsetof(struct ast_state, MatchMapping_type),
120
0
        offsetof(struct ast_state, MatchOr_type),
121
0
        offsetof(struct ast_state, MatchSequence_type),
122
0
        offsetof(struct ast_state, MatchSingleton_type),
123
0
        offsetof(struct ast_state, MatchStar_type),
124
0
        offsetof(struct ast_state, MatchValue_type),
125
0
        offsetof(struct ast_state, Match_type),
126
0
        offsetof(struct ast_state, Mod_singleton),
127
0
        offsetof(struct ast_state, Mod_type),
128
0
        offsetof(struct ast_state, Module_type),
129
0
        offsetof(struct ast_state, Mult_singleton),
130
0
        offsetof(struct ast_state, Mult_type),
131
0
        offsetof(struct ast_state, Name_type),
132
0
        offsetof(struct ast_state, NamedExpr_type),
133
0
        offsetof(struct ast_state, Nonlocal_type),
134
0
        offsetof(struct ast_state, NotEq_singleton),
135
0
        offsetof(struct ast_state, NotEq_type),
136
0
        offsetof(struct ast_state, NotIn_singleton),
137
0
        offsetof(struct ast_state, NotIn_type),
138
0
        offsetof(struct ast_state, Not_singleton),
139
0
        offsetof(struct ast_state, Not_type),
140
0
        offsetof(struct ast_state, Or_singleton),
141
0
        offsetof(struct ast_state, Or_type),
142
0
        offsetof(struct ast_state, ParamSpec_type),
143
0
        offsetof(struct ast_state, Pass_type),
144
0
        offsetof(struct ast_state, Pow_singleton),
145
0
        offsetof(struct ast_state, Pow_type),
146
0
        offsetof(struct ast_state, RShift_singleton),
147
0
        offsetof(struct ast_state, RShift_type),
148
0
        offsetof(struct ast_state, Raise_type),
149
0
        offsetof(struct ast_state, Return_type),
150
0
        offsetof(struct ast_state, SetComp_type),
151
0
        offsetof(struct ast_state, Set_type),
152
0
        offsetof(struct ast_state, Slice_type),
153
0
        offsetof(struct ast_state, Starred_type),
154
0
        offsetof(struct ast_state, Store_singleton),
155
0
        offsetof(struct ast_state, Store_type),
156
0
        offsetof(struct ast_state, Sub_singleton),
157
0
        offsetof(struct ast_state, Sub_type),
158
0
        offsetof(struct ast_state, Subscript_type),
159
0
        offsetof(struct ast_state, TemplateStr_type),
160
0
        offsetof(struct ast_state, TryStar_type),
161
0
        offsetof(struct ast_state, Try_type),
162
0
        offsetof(struct ast_state, Tuple_type),
163
0
        offsetof(struct ast_state, TypeAlias_type),
164
0
        offsetof(struct ast_state, TypeIgnore_type),
165
0
        offsetof(struct ast_state, TypeVarTuple_type),
166
0
        offsetof(struct ast_state, TypeVar_type),
167
0
        offsetof(struct ast_state, UAdd_singleton),
168
0
        offsetof(struct ast_state, UAdd_type),
169
0
        offsetof(struct ast_state, USub_singleton),
170
0
        offsetof(struct ast_state, USub_type),
171
0
        offsetof(struct ast_state, UnaryOp_type),
172
0
        offsetof(struct ast_state, While_type),
173
0
        offsetof(struct ast_state, With_type),
174
0
        offsetof(struct ast_state, YieldFrom_type),
175
0
        offsetof(struct ast_state, Yield_type),
176
0
        offsetof(struct ast_state, __dict__),
177
0
        offsetof(struct ast_state, __doc__),
178
0
        offsetof(struct ast_state, __match_args__),
179
0
        offsetof(struct ast_state, __module__),
180
0
        offsetof(struct ast_state, _attributes),
181
0
        offsetof(struct ast_state, _fields),
182
0
        offsetof(struct ast_state, abstract_types),
183
0
        offsetof(struct ast_state, alias_type),
184
0
        offsetof(struct ast_state, annotation),
185
0
        offsetof(struct ast_state, arg),
186
0
        offsetof(struct ast_state, arg_type),
187
0
        offsetof(struct ast_state, args),
188
0
        offsetof(struct ast_state, argtypes),
189
0
        offsetof(struct ast_state, arguments_type),
190
0
        offsetof(struct ast_state, asname),
191
0
        offsetof(struct ast_state, ast),
192
0
        offsetof(struct ast_state, attr),
193
0
        offsetof(struct ast_state, bases),
194
0
        offsetof(struct ast_state, body),
195
0
        offsetof(struct ast_state, boolop_type),
196
0
        offsetof(struct ast_state, bound),
197
0
        offsetof(struct ast_state, cases),
198
0
        offsetof(struct ast_state, cause),
199
0
        offsetof(struct ast_state, cls),
200
0
        offsetof(struct ast_state, cmpop_type),
201
0
        offsetof(struct ast_state, col_offset),
202
0
        offsetof(struct ast_state, comparators),
203
0
        offsetof(struct ast_state, comprehension_type),
204
0
        offsetof(struct ast_state, context_expr),
205
0
        offsetof(struct ast_state, conversion),
206
0
        offsetof(struct ast_state, ctx),
207
0
        offsetof(struct ast_state, decorator_list),
208
0
        offsetof(struct ast_state, default_value),
209
0
        offsetof(struct ast_state, defaults),
210
0
        offsetof(struct ast_state, elt),
211
0
        offsetof(struct ast_state, elts),
212
0
        offsetof(struct ast_state, end_col_offset),
213
0
        offsetof(struct ast_state, end_lineno),
214
0
        offsetof(struct ast_state, exc),
215
0
        offsetof(struct ast_state, excepthandler_type),
216
0
        offsetof(struct ast_state, expr_context_type),
217
0
        offsetof(struct ast_state, expr_type),
218
0
        offsetof(struct ast_state, finalbody),
219
0
        offsetof(struct ast_state, format_spec),
220
0
        offsetof(struct ast_state, func),
221
0
        offsetof(struct ast_state, generators),
222
0
        offsetof(struct ast_state, guard),
223
0
        offsetof(struct ast_state, handlers),
224
0
        offsetof(struct ast_state, id),
225
0
        offsetof(struct ast_state, ifs),
226
0
        offsetof(struct ast_state, is_async),
227
0
        offsetof(struct ast_state, is_lazy),
228
0
        offsetof(struct ast_state, items),
229
0
        offsetof(struct ast_state, iter),
230
0
        offsetof(struct ast_state, key),
231
0
        offsetof(struct ast_state, keys),
232
0
        offsetof(struct ast_state, keyword_type),
233
0
        offsetof(struct ast_state, keywords),
234
0
        offsetof(struct ast_state, kind),
235
0
        offsetof(struct ast_state, kw_defaults),
236
0
        offsetof(struct ast_state, kwarg),
237
0
        offsetof(struct ast_state, kwd_attrs),
238
0
        offsetof(struct ast_state, kwd_patterns),
239
0
        offsetof(struct ast_state, kwonlyargs),
240
0
        offsetof(struct ast_state, left),
241
0
        offsetof(struct ast_state, level),
242
0
        offsetof(struct ast_state, lineno),
243
0
        offsetof(struct ast_state, lower),
244
0
        offsetof(struct ast_state, match_case_type),
245
0
        offsetof(struct ast_state, mod_type),
246
0
        offsetof(struct ast_state, module),
247
0
        offsetof(struct ast_state, msg),
248
0
        offsetof(struct ast_state, name),
249
0
        offsetof(struct ast_state, names),
250
0
        offsetof(struct ast_state, op),
251
0
        offsetof(struct ast_state, operand),
252
0
        offsetof(struct ast_state, operator_type),
253
0
        offsetof(struct ast_state, ops),
254
0
        offsetof(struct ast_state, optional_vars),
255
0
        offsetof(struct ast_state, orelse),
256
0
        offsetof(struct ast_state, pattern),
257
0
        offsetof(struct ast_state, pattern_type),
258
0
        offsetof(struct ast_state, patterns),
259
0
        offsetof(struct ast_state, posonlyargs),
260
0
        offsetof(struct ast_state, rest),
261
0
        offsetof(struct ast_state, returns),
262
0
        offsetof(struct ast_state, right),
263
0
        offsetof(struct ast_state, simple),
264
0
        offsetof(struct ast_state, slice),
265
0
        offsetof(struct ast_state, step),
266
0
        offsetof(struct ast_state, stmt_type),
267
0
        offsetof(struct ast_state, str),
268
0
        offsetof(struct ast_state, subject),
269
0
        offsetof(struct ast_state, tag),
270
0
        offsetof(struct ast_state, target),
271
0
        offsetof(struct ast_state, targets),
272
0
        offsetof(struct ast_state, test),
273
0
        offsetof(struct ast_state, type),
274
0
        offsetof(struct ast_state, type_comment),
275
0
        offsetof(struct ast_state, type_ignore_type),
276
0
        offsetof(struct ast_state, type_ignores),
277
0
        offsetof(struct ast_state, type_param_type),
278
0
        offsetof(struct ast_state, type_params),
279
0
        offsetof(struct ast_state, unaryop_type),
280
0
        offsetof(struct ast_state, upper),
281
0
        offsetof(struct ast_state, value),
282
0
        offsetof(struct ast_state, values),
283
0
        offsetof(struct ast_state, vararg),
284
0
        offsetof(struct ast_state, withitem_type),
285
0
    };
286
287
0
    for (size_t i = 0; i < Py_ARRAY_LENGTH(offsets); i++) {
288
0
        PyObject **field = (PyObject **)((char *)state + offsets[i]);
289
0
        Py_CLEAR(*field);
290
0
    }
291
0
    state->finalized = 1;
292
0
    state->once = (_PyOnceFlag){0};
293
0
}
294
295
static int init_identifiers(struct ast_state *state)
296
17
{
297
17
    if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return -1;
298
17
    if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return -1;
299
17
    if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return -1;
300
17
    if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return -1;
301
17
    if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return -1;
302
17
    if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return -1;
303
17
    if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return -1;
304
17
    if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return -1;
305
17
    if ((state->args = PyUnicode_InternFromString("args")) == NULL) return -1;
306
17
    if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return -1;
307
17
    if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return -1;
308
17
    if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return -1;
309
17
    if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return -1;
310
17
    if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return -1;
311
17
    if ((state->body = PyUnicode_InternFromString("body")) == NULL) return -1;
312
17
    if ((state->bound = PyUnicode_InternFromString("bound")) == NULL) return -1;
313
17
    if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return -1;
314
17
    if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return -1;
315
17
    if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return -1;
316
17
    if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return -1;
317
17
    if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return -1;
318
17
    if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return -1;
319
17
    if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return -1;
320
17
    if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return -1;
321
17
    if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return -1;
322
17
    if ((state->default_value = PyUnicode_InternFromString("default_value")) == NULL) return -1;
323
17
    if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return -1;
324
17
    if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return -1;
325
17
    if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return -1;
326
17
    if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return -1;
327
17
    if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return -1;
328
17
    if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return -1;
329
17
    if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return -1;
330
17
    if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return -1;
331
17
    if ((state->func = PyUnicode_InternFromString("func")) == NULL) return -1;
332
17
    if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return -1;
333
17
    if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return -1;
334
17
    if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return -1;
335
17
    if ((state->id = PyUnicode_InternFromString("id")) == NULL) return -1;
336
17
    if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return -1;
337
17
    if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return -1;
338
17
    if ((state->is_lazy = PyUnicode_InternFromString("is_lazy")) == NULL) return -1;
339
17
    if ((state->items = PyUnicode_InternFromString("items")) == NULL) return -1;
340
17
    if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return -1;
341
17
    if ((state->key = PyUnicode_InternFromString("key")) == NULL) return -1;
342
17
    if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return -1;
343
17
    if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return -1;
344
17
    if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return -1;
345
17
    if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return -1;
346
17
    if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return -1;
347
17
    if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return -1;
348
17
    if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return -1;
349
17
    if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return -1;
350
17
    if ((state->left = PyUnicode_InternFromString("left")) == NULL) return -1;
351
17
    if ((state->level = PyUnicode_InternFromString("level")) == NULL) return -1;
352
17
    if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return -1;
353
17
    if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return -1;
354
17
    if ((state->module = PyUnicode_InternFromString("module")) == NULL) return -1;
355
17
    if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return -1;
356
17
    if ((state->name = PyUnicode_InternFromString("name")) == NULL) return -1;
357
17
    if ((state->names = PyUnicode_InternFromString("names")) == NULL) return -1;
358
17
    if ((state->op = PyUnicode_InternFromString("op")) == NULL) return -1;
359
17
    if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return -1;
360
17
    if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return -1;
361
17
    if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return -1;
362
17
    if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return -1;
363
17
    if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return -1;
364
17
    if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return -1;
365
17
    if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return -1;
366
17
    if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return -1;
367
17
    if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return -1;
368
17
    if ((state->right = PyUnicode_InternFromString("right")) == NULL) return -1;
369
17
    if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return -1;
370
17
    if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return -1;
371
17
    if ((state->step = PyUnicode_InternFromString("step")) == NULL) return -1;
372
17
    if ((state->str = PyUnicode_InternFromString("str")) == NULL) return -1;
373
17
    if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return -1;
374
17
    if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return -1;
375
17
    if ((state->target = PyUnicode_InternFromString("target")) == NULL) return -1;
376
17
    if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return -1;
377
17
    if ((state->test = PyUnicode_InternFromString("test")) == NULL) return -1;
378
17
    if ((state->type = PyUnicode_InternFromString("type")) == NULL) return -1;
379
17
    if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return -1;
380
17
    if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return -1;
381
17
    if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return -1;
382
17
    if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return -1;
383
17
    if ((state->value = PyUnicode_InternFromString("value")) == NULL) return -1;
384
17
    if ((state->values = PyUnicode_InternFromString("values")) == NULL) return -1;
385
17
    if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return -1;
386
17
    return 0;
387
17
};
388
389
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
390
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
391
455k
GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
392
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
393
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
394
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
395
563k
GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
396
9.88k
GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
397
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
398
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
399
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
400
1.59k
GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
401
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
402
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(type_param, type_param_ty)
403
404
static PyObject* ast2obj_mod(struct ast_state *state, void*);
405
static const char * const Module_fields[]={
406
    "body",
407
    "type_ignores",
408
};
409
static const char * const Interactive_fields[]={
410
    "body",
411
};
412
static const char * const Expression_fields[]={
413
    "body",
414
};
415
static const char * const FunctionType_fields[]={
416
    "argtypes",
417
    "returns",
418
};
419
static const char * const stmt_attributes[] = {
420
    "lineno",
421
    "col_offset",
422
    "end_lineno",
423
    "end_col_offset",
424
};
425
static PyObject* ast2obj_stmt(struct ast_state *state, void*);
426
static const char * const FunctionDef_fields[]={
427
    "name",
428
    "args",
429
    "body",
430
    "decorator_list",
431
    "returns",
432
    "type_comment",
433
    "type_params",
434
};
435
static const char * const AsyncFunctionDef_fields[]={
436
    "name",
437
    "args",
438
    "body",
439
    "decorator_list",
440
    "returns",
441
    "type_comment",
442
    "type_params",
443
};
444
static const char * const ClassDef_fields[]={
445
    "name",
446
    "bases",
447
    "keywords",
448
    "body",
449
    "decorator_list",
450
    "type_params",
451
};
452
static const char * const Return_fields[]={
453
    "value",
454
};
455
static const char * const Delete_fields[]={
456
    "targets",
457
};
458
static const char * const Assign_fields[]={
459
    "targets",
460
    "value",
461
    "type_comment",
462
};
463
static const char * const TypeAlias_fields[]={
464
    "name",
465
    "type_params",
466
    "value",
467
};
468
static const char * const AugAssign_fields[]={
469
    "target",
470
    "op",
471
    "value",
472
};
473
static const char * const AnnAssign_fields[]={
474
    "target",
475
    "annotation",
476
    "value",
477
    "simple",
478
};
479
static const char * const For_fields[]={
480
    "target",
481
    "iter",
482
    "body",
483
    "orelse",
484
    "type_comment",
485
};
486
static const char * const AsyncFor_fields[]={
487
    "target",
488
    "iter",
489
    "body",
490
    "orelse",
491
    "type_comment",
492
};
493
static const char * const While_fields[]={
494
    "test",
495
    "body",
496
    "orelse",
497
};
498
static const char * const If_fields[]={
499
    "test",
500
    "body",
501
    "orelse",
502
};
503
static const char * const With_fields[]={
504
    "items",
505
    "body",
506
    "type_comment",
507
};
508
static const char * const AsyncWith_fields[]={
509
    "items",
510
    "body",
511
    "type_comment",
512
};
513
static const char * const Match_fields[]={
514
    "subject",
515
    "cases",
516
};
517
static const char * const Raise_fields[]={
518
    "exc",
519
    "cause",
520
};
521
static const char * const Try_fields[]={
522
    "body",
523
    "handlers",
524
    "orelse",
525
    "finalbody",
526
};
527
static const char * const TryStar_fields[]={
528
    "body",
529
    "handlers",
530
    "orelse",
531
    "finalbody",
532
};
533
static const char * const Assert_fields[]={
534
    "test",
535
    "msg",
536
};
537
static const char * const Import_fields[]={
538
    "names",
539
    "is_lazy",
540
};
541
static const char * const ImportFrom_fields[]={
542
    "module",
543
    "names",
544
    "level",
545
    "is_lazy",
546
};
547
static const char * const Global_fields[]={
548
    "names",
549
};
550
static const char * const Nonlocal_fields[]={
551
    "names",
552
};
553
static const char * const Expr_fields[]={
554
    "value",
555
};
556
static const char * const expr_attributes[] = {
557
    "lineno",
558
    "col_offset",
559
    "end_lineno",
560
    "end_col_offset",
561
};
562
static PyObject* ast2obj_expr(struct ast_state *state, void*);
563
static const char * const BoolOp_fields[]={
564
    "op",
565
    "values",
566
};
567
static const char * const NamedExpr_fields[]={
568
    "target",
569
    "value",
570
};
571
static const char * const BinOp_fields[]={
572
    "left",
573
    "op",
574
    "right",
575
};
576
static const char * const UnaryOp_fields[]={
577
    "op",
578
    "operand",
579
};
580
static const char * const Lambda_fields[]={
581
    "args",
582
    "body",
583
};
584
static const char * const IfExp_fields[]={
585
    "test",
586
    "body",
587
    "orelse",
588
};
589
static const char * const Dict_fields[]={
590
    "keys",
591
    "values",
592
};
593
static const char * const Set_fields[]={
594
    "elts",
595
};
596
static const char * const ListComp_fields[]={
597
    "elt",
598
    "generators",
599
};
600
static const char * const SetComp_fields[]={
601
    "elt",
602
    "generators",
603
};
604
static const char * const DictComp_fields[]={
605
    "key",
606
    "value",
607
    "generators",
608
};
609
static const char * const GeneratorExp_fields[]={
610
    "elt",
611
    "generators",
612
};
613
static const char * const Await_fields[]={
614
    "value",
615
};
616
static const char * const Yield_fields[]={
617
    "value",
618
};
619
static const char * const YieldFrom_fields[]={
620
    "value",
621
};
622
static const char * const Compare_fields[]={
623
    "left",
624
    "ops",
625
    "comparators",
626
};
627
static const char * const Call_fields[]={
628
    "func",
629
    "args",
630
    "keywords",
631
};
632
static const char * const FormattedValue_fields[]={
633
    "value",
634
    "conversion",
635
    "format_spec",
636
};
637
static const char * const Interpolation_fields[]={
638
    "value",
639
    "str",
640
    "conversion",
641
    "format_spec",
642
};
643
static const char * const JoinedStr_fields[]={
644
    "values",
645
};
646
static const char * const TemplateStr_fields[]={
647
    "values",
648
};
649
static const char * const Constant_fields[]={
650
    "value",
651
    "kind",
652
};
653
static const char * const Attribute_fields[]={
654
    "value",
655
    "attr",
656
    "ctx",
657
};
658
static const char * const Subscript_fields[]={
659
    "value",
660
    "slice",
661
    "ctx",
662
};
663
static const char * const Starred_fields[]={
664
    "value",
665
    "ctx",
666
};
667
static const char * const Name_fields[]={
668
    "id",
669
    "ctx",
670
};
671
static const char * const List_fields[]={
672
    "elts",
673
    "ctx",
674
};
675
static const char * const Tuple_fields[]={
676
    "elts",
677
    "ctx",
678
};
679
static const char * const Slice_fields[]={
680
    "lower",
681
    "upper",
682
    "step",
683
};
684
static PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty);
685
static PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty);
686
static PyObject* ast2obj_operator(struct ast_state *state, operator_ty);
687
static PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty);
688
static PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty);
689
static PyObject* ast2obj_comprehension(struct ast_state *state, void*);
690
static const char * const comprehension_fields[]={
691
    "target",
692
    "iter",
693
    "ifs",
694
    "is_async",
695
};
696
static const char * const excepthandler_attributes[] = {
697
    "lineno",
698
    "col_offset",
699
    "end_lineno",
700
    "end_col_offset",
701
};
702
static PyObject* ast2obj_excepthandler(struct ast_state *state, void*);
703
static const char * const ExceptHandler_fields[]={
704
    "type",
705
    "name",
706
    "body",
707
};
708
static PyObject* ast2obj_arguments(struct ast_state *state, void*);
709
static const char * const arguments_fields[]={
710
    "posonlyargs",
711
    "args",
712
    "vararg",
713
    "kwonlyargs",
714
    "kw_defaults",
715
    "kwarg",
716
    "defaults",
717
};
718
static PyObject* ast2obj_arg(struct ast_state *state, void*);
719
static const char * const arg_attributes[] = {
720
    "lineno",
721
    "col_offset",
722
    "end_lineno",
723
    "end_col_offset",
724
};
725
static const char * const arg_fields[]={
726
    "arg",
727
    "annotation",
728
    "type_comment",
729
};
730
static PyObject* ast2obj_keyword(struct ast_state *state, void*);
731
static const char * const keyword_attributes[] = {
732
    "lineno",
733
    "col_offset",
734
    "end_lineno",
735
    "end_col_offset",
736
};
737
static const char * const keyword_fields[]={
738
    "arg",
739
    "value",
740
};
741
static PyObject* ast2obj_alias(struct ast_state *state, void*);
742
static const char * const alias_attributes[] = {
743
    "lineno",
744
    "col_offset",
745
    "end_lineno",
746
    "end_col_offset",
747
};
748
static const char * const alias_fields[]={
749
    "name",
750
    "asname",
751
};
752
static PyObject* ast2obj_withitem(struct ast_state *state, void*);
753
static const char * const withitem_fields[]={
754
    "context_expr",
755
    "optional_vars",
756
};
757
static PyObject* ast2obj_match_case(struct ast_state *state, void*);
758
static const char * const match_case_fields[]={
759
    "pattern",
760
    "guard",
761
    "body",
762
};
763
static const char * const pattern_attributes[] = {
764
    "lineno",
765
    "col_offset",
766
    "end_lineno",
767
    "end_col_offset",
768
};
769
static PyObject* ast2obj_pattern(struct ast_state *state, void*);
770
static const char * const MatchValue_fields[]={
771
    "value",
772
};
773
static const char * const MatchSingleton_fields[]={
774
    "value",
775
};
776
static const char * const MatchSequence_fields[]={
777
    "patterns",
778
};
779
static const char * const MatchMapping_fields[]={
780
    "keys",
781
    "patterns",
782
    "rest",
783
};
784
static const char * const MatchClass_fields[]={
785
    "cls",
786
    "patterns",
787
    "kwd_attrs",
788
    "kwd_patterns",
789
};
790
static const char * const MatchStar_fields[]={
791
    "name",
792
};
793
static const char * const MatchAs_fields[]={
794
    "pattern",
795
    "name",
796
};
797
static const char * const MatchOr_fields[]={
798
    "patterns",
799
};
800
static PyObject* ast2obj_type_ignore(struct ast_state *state, void*);
801
static const char * const TypeIgnore_fields[]={
802
    "lineno",
803
    "tag",
804
};
805
static const char * const type_param_attributes[] = {
806
    "lineno",
807
    "col_offset",
808
    "end_lineno",
809
    "end_col_offset",
810
};
811
static PyObject* ast2obj_type_param(struct ast_state *state, void*);
812
static const char * const TypeVar_fields[]={
813
    "name",
814
    "bound",
815
    "default_value",
816
};
817
static const char * const ParamSpec_fields[]={
818
    "name",
819
    "default_value",
820
};
821
static const char * const TypeVarTuple_fields[]={
822
    "name",
823
    "default_value",
824
};
825
826
827
static int
828
add_ast_annotations(struct ast_state *state)
829
17
{
830
17
    enum {
831
17
        FIELD_OPTIONAL = 1,
832
17
        FIELD_SEQUENCE = 2,
833
17
        FIELD_BUILTIN = 4,
834
17
    };
835
17
    PyTypeObject *const builtin_types[] = {
836
17
        &PyUnicode_Type,
837
17
        &PyLong_Type,
838
17
        &PyBaseObject_Type,
839
17
    };
840
    // Offsets refer to this interpreter's AST state, not global types.
841
17
    static_assert(sizeof(struct ast_state) <= UINT16_MAX,
842
17
                  "ast_state offsets must fit in uint16_t");
843
17
    static const struct {
844
17
        uint16_t name_offset;
845
17
        uint16_t type_offset;  // An index into builtin_types for builtins.
846
17
        uint8_t flags;
847
17
    } fields[] = {
848
17
        {offsetof(struct ast_state, body),
849
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
850
17
        {offsetof(struct ast_state, type_ignores),
851
17
         offsetof(struct ast_state, type_ignore_type), FIELD_SEQUENCE},
852
17
        {offsetof(struct ast_state, body),
853
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
854
17
        {offsetof(struct ast_state, body),
855
17
         offsetof(struct ast_state, expr_type), 0},
856
17
        {offsetof(struct ast_state, argtypes),
857
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
858
17
        {offsetof(struct ast_state, returns),
859
17
         offsetof(struct ast_state, expr_type), 0},
860
17
        {offsetof(struct ast_state, name),
861
17
         0, FIELD_BUILTIN},
862
17
        {offsetof(struct ast_state, args),
863
17
         offsetof(struct ast_state, arguments_type), 0},
864
17
        {offsetof(struct ast_state, body),
865
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
866
17
        {offsetof(struct ast_state, decorator_list),
867
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
868
17
        {offsetof(struct ast_state, returns),
869
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
870
17
        {offsetof(struct ast_state, type_comment),
871
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
872
17
        {offsetof(struct ast_state, type_params),
873
17
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
874
17
        {offsetof(struct ast_state, name),
875
17
         0, FIELD_BUILTIN},
876
17
        {offsetof(struct ast_state, args),
877
17
         offsetof(struct ast_state, arguments_type), 0},
878
17
        {offsetof(struct ast_state, body),
879
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
880
17
        {offsetof(struct ast_state, decorator_list),
881
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
882
17
        {offsetof(struct ast_state, returns),
883
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
884
17
        {offsetof(struct ast_state, type_comment),
885
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
886
17
        {offsetof(struct ast_state, type_params),
887
17
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
888
17
        {offsetof(struct ast_state, name),
889
17
         0, FIELD_BUILTIN},
890
17
        {offsetof(struct ast_state, bases),
891
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
892
17
        {offsetof(struct ast_state, keywords),
893
17
         offsetof(struct ast_state, keyword_type), FIELD_SEQUENCE},
894
17
        {offsetof(struct ast_state, body),
895
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
896
17
        {offsetof(struct ast_state, decorator_list),
897
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
898
17
        {offsetof(struct ast_state, type_params),
899
17
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
900
17
        {offsetof(struct ast_state, value),
901
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
902
17
        {offsetof(struct ast_state, targets),
903
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
904
17
        {offsetof(struct ast_state, targets),
905
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
906
17
        {offsetof(struct ast_state, value),
907
17
         offsetof(struct ast_state, expr_type), 0},
908
17
        {offsetof(struct ast_state, type_comment),
909
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
910
17
        {offsetof(struct ast_state, name),
911
17
         offsetof(struct ast_state, expr_type), 0},
912
17
        {offsetof(struct ast_state, type_params),
913
17
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
914
17
        {offsetof(struct ast_state, value),
915
17
         offsetof(struct ast_state, expr_type), 0},
916
17
        {offsetof(struct ast_state, target),
917
17
         offsetof(struct ast_state, expr_type), 0},
918
17
        {offsetof(struct ast_state, op),
919
17
         offsetof(struct ast_state, operator_type), 0},
920
17
        {offsetof(struct ast_state, value),
921
17
         offsetof(struct ast_state, expr_type), 0},
922
17
        {offsetof(struct ast_state, target),
923
17
         offsetof(struct ast_state, expr_type), 0},
924
17
        {offsetof(struct ast_state, annotation),
925
17
         offsetof(struct ast_state, expr_type), 0},
926
17
        {offsetof(struct ast_state, value),
927
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
928
17
        {offsetof(struct ast_state, simple),
929
17
         1, FIELD_BUILTIN},
930
17
        {offsetof(struct ast_state, target),
931
17
         offsetof(struct ast_state, expr_type), 0},
932
17
        {offsetof(struct ast_state, iter),
933
17
         offsetof(struct ast_state, expr_type), 0},
934
17
        {offsetof(struct ast_state, body),
935
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
936
17
        {offsetof(struct ast_state, orelse),
937
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
938
17
        {offsetof(struct ast_state, type_comment),
939
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
940
17
        {offsetof(struct ast_state, target),
941
17
         offsetof(struct ast_state, expr_type), 0},
942
17
        {offsetof(struct ast_state, iter),
943
17
         offsetof(struct ast_state, expr_type), 0},
944
17
        {offsetof(struct ast_state, body),
945
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
946
17
        {offsetof(struct ast_state, orelse),
947
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
948
17
        {offsetof(struct ast_state, type_comment),
949
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
950
17
        {offsetof(struct ast_state, test),
951
17
         offsetof(struct ast_state, expr_type), 0},
952
17
        {offsetof(struct ast_state, body),
953
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
954
17
        {offsetof(struct ast_state, orelse),
955
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
956
17
        {offsetof(struct ast_state, test),
957
17
         offsetof(struct ast_state, expr_type), 0},
958
17
        {offsetof(struct ast_state, body),
959
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
960
17
        {offsetof(struct ast_state, orelse),
961
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
962
17
        {offsetof(struct ast_state, items),
963
17
         offsetof(struct ast_state, withitem_type), FIELD_SEQUENCE},
964
17
        {offsetof(struct ast_state, body),
965
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
966
17
        {offsetof(struct ast_state, type_comment),
967
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
968
17
        {offsetof(struct ast_state, items),
969
17
         offsetof(struct ast_state, withitem_type), FIELD_SEQUENCE},
970
17
        {offsetof(struct ast_state, body),
971
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
972
17
        {offsetof(struct ast_state, type_comment),
973
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
974
17
        {offsetof(struct ast_state, subject),
975
17
         offsetof(struct ast_state, expr_type), 0},
976
17
        {offsetof(struct ast_state, cases),
977
17
         offsetof(struct ast_state, match_case_type), FIELD_SEQUENCE},
978
17
        {offsetof(struct ast_state, exc),
979
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
980
17
        {offsetof(struct ast_state, cause),
981
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
982
17
        {offsetof(struct ast_state, body),
983
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
984
17
        {offsetof(struct ast_state, handlers),
985
17
         offsetof(struct ast_state, excepthandler_type), FIELD_SEQUENCE},
986
17
        {offsetof(struct ast_state, orelse),
987
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
988
17
        {offsetof(struct ast_state, finalbody),
989
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
990
17
        {offsetof(struct ast_state, body),
991
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
992
17
        {offsetof(struct ast_state, handlers),
993
17
         offsetof(struct ast_state, excepthandler_type), FIELD_SEQUENCE},
994
17
        {offsetof(struct ast_state, orelse),
995
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
996
17
        {offsetof(struct ast_state, finalbody),
997
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
998
17
        {offsetof(struct ast_state, test),
999
17
         offsetof(struct ast_state, expr_type), 0},
1000
17
        {offsetof(struct ast_state, msg),
1001
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1002
17
        {offsetof(struct ast_state, names),
1003
17
         offsetof(struct ast_state, alias_type), FIELD_SEQUENCE},
1004
17
        {offsetof(struct ast_state, is_lazy),
1005
17
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1006
17
        {offsetof(struct ast_state, module),
1007
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1008
17
        {offsetof(struct ast_state, names),
1009
17
         offsetof(struct ast_state, alias_type), FIELD_SEQUENCE},
1010
17
        {offsetof(struct ast_state, level),
1011
17
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1012
17
        {offsetof(struct ast_state, is_lazy),
1013
17
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1014
17
        {offsetof(struct ast_state, names),
1015
17
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1016
17
        {offsetof(struct ast_state, names),
1017
17
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1018
17
        {offsetof(struct ast_state, value),
1019
17
         offsetof(struct ast_state, expr_type), 0},
1020
17
        {offsetof(struct ast_state, op),
1021
17
         offsetof(struct ast_state, boolop_type), 0},
1022
17
        {offsetof(struct ast_state, values),
1023
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1024
17
        {offsetof(struct ast_state, target),
1025
17
         offsetof(struct ast_state, expr_type), 0},
1026
17
        {offsetof(struct ast_state, value),
1027
17
         offsetof(struct ast_state, expr_type), 0},
1028
17
        {offsetof(struct ast_state, left),
1029
17
         offsetof(struct ast_state, expr_type), 0},
1030
17
        {offsetof(struct ast_state, op),
1031
17
         offsetof(struct ast_state, operator_type), 0},
1032
17
        {offsetof(struct ast_state, right),
1033
17
         offsetof(struct ast_state, expr_type), 0},
1034
17
        {offsetof(struct ast_state, op),
1035
17
         offsetof(struct ast_state, unaryop_type), 0},
1036
17
        {offsetof(struct ast_state, operand),
1037
17
         offsetof(struct ast_state, expr_type), 0},
1038
17
        {offsetof(struct ast_state, args),
1039
17
         offsetof(struct ast_state, arguments_type), 0},
1040
17
        {offsetof(struct ast_state, body),
1041
17
         offsetof(struct ast_state, expr_type), 0},
1042
17
        {offsetof(struct ast_state, test),
1043
17
         offsetof(struct ast_state, expr_type), 0},
1044
17
        {offsetof(struct ast_state, body),
1045
17
         offsetof(struct ast_state, expr_type), 0},
1046
17
        {offsetof(struct ast_state, orelse),
1047
17
         offsetof(struct ast_state, expr_type), 0},
1048
17
        {offsetof(struct ast_state, keys),
1049
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1050
17
        {offsetof(struct ast_state, values),
1051
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1052
17
        {offsetof(struct ast_state, elts),
1053
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1054
17
        {offsetof(struct ast_state, elt),
1055
17
         offsetof(struct ast_state, expr_type), 0},
1056
17
        {offsetof(struct ast_state, generators),
1057
17
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1058
17
        {offsetof(struct ast_state, elt),
1059
17
         offsetof(struct ast_state, expr_type), 0},
1060
17
        {offsetof(struct ast_state, generators),
1061
17
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1062
17
        {offsetof(struct ast_state, key),
1063
17
         offsetof(struct ast_state, expr_type), 0},
1064
17
        {offsetof(struct ast_state, value),
1065
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1066
17
        {offsetof(struct ast_state, generators),
1067
17
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1068
17
        {offsetof(struct ast_state, elt),
1069
17
         offsetof(struct ast_state, expr_type), 0},
1070
17
        {offsetof(struct ast_state, generators),
1071
17
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1072
17
        {offsetof(struct ast_state, value),
1073
17
         offsetof(struct ast_state, expr_type), 0},
1074
17
        {offsetof(struct ast_state, value),
1075
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1076
17
        {offsetof(struct ast_state, value),
1077
17
         offsetof(struct ast_state, expr_type), 0},
1078
17
        {offsetof(struct ast_state, left),
1079
17
         offsetof(struct ast_state, expr_type), 0},
1080
17
        {offsetof(struct ast_state, ops),
1081
17
         offsetof(struct ast_state, cmpop_type), FIELD_SEQUENCE},
1082
17
        {offsetof(struct ast_state, comparators),
1083
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1084
17
        {offsetof(struct ast_state, func),
1085
17
         offsetof(struct ast_state, expr_type), 0},
1086
17
        {offsetof(struct ast_state, args),
1087
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1088
17
        {offsetof(struct ast_state, keywords),
1089
17
         offsetof(struct ast_state, keyword_type), FIELD_SEQUENCE},
1090
17
        {offsetof(struct ast_state, value),
1091
17
         offsetof(struct ast_state, expr_type), 0},
1092
17
        {offsetof(struct ast_state, conversion),
1093
17
         1, FIELD_BUILTIN},
1094
17
        {offsetof(struct ast_state, format_spec),
1095
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1096
17
        {offsetof(struct ast_state, value),
1097
17
         offsetof(struct ast_state, expr_type), 0},
1098
17
        {offsetof(struct ast_state, str),
1099
17
         2, FIELD_BUILTIN},
1100
17
        {offsetof(struct ast_state, conversion),
1101
17
         1, FIELD_BUILTIN},
1102
17
        {offsetof(struct ast_state, format_spec),
1103
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1104
17
        {offsetof(struct ast_state, values),
1105
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1106
17
        {offsetof(struct ast_state, values),
1107
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1108
17
        {offsetof(struct ast_state, value),
1109
17
         2, FIELD_BUILTIN},
1110
17
        {offsetof(struct ast_state, kind),
1111
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1112
17
        {offsetof(struct ast_state, value),
1113
17
         offsetof(struct ast_state, expr_type), 0},
1114
17
        {offsetof(struct ast_state, attr),
1115
17
         0, FIELD_BUILTIN},
1116
17
        {offsetof(struct ast_state, ctx),
1117
17
         offsetof(struct ast_state, expr_context_type), 0},
1118
17
        {offsetof(struct ast_state, value),
1119
17
         offsetof(struct ast_state, expr_type), 0},
1120
17
        {offsetof(struct ast_state, slice),
1121
17
         offsetof(struct ast_state, expr_type), 0},
1122
17
        {offsetof(struct ast_state, ctx),
1123
17
         offsetof(struct ast_state, expr_context_type), 0},
1124
17
        {offsetof(struct ast_state, value),
1125
17
         offsetof(struct ast_state, expr_type), 0},
1126
17
        {offsetof(struct ast_state, ctx),
1127
17
         offsetof(struct ast_state, expr_context_type), 0},
1128
17
        {offsetof(struct ast_state, id),
1129
17
         0, FIELD_BUILTIN},
1130
17
        {offsetof(struct ast_state, ctx),
1131
17
         offsetof(struct ast_state, expr_context_type), 0},
1132
17
        {offsetof(struct ast_state, elts),
1133
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1134
17
        {offsetof(struct ast_state, ctx),
1135
17
         offsetof(struct ast_state, expr_context_type), 0},
1136
17
        {offsetof(struct ast_state, elts),
1137
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1138
17
        {offsetof(struct ast_state, ctx),
1139
17
         offsetof(struct ast_state, expr_context_type), 0},
1140
17
        {offsetof(struct ast_state, lower),
1141
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1142
17
        {offsetof(struct ast_state, upper),
1143
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1144
17
        {offsetof(struct ast_state, step),
1145
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1146
17
        {offsetof(struct ast_state, target),
1147
17
         offsetof(struct ast_state, expr_type), 0},
1148
17
        {offsetof(struct ast_state, iter),
1149
17
         offsetof(struct ast_state, expr_type), 0},
1150
17
        {offsetof(struct ast_state, ifs),
1151
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1152
17
        {offsetof(struct ast_state, is_async),
1153
17
         1, FIELD_BUILTIN},
1154
17
        {offsetof(struct ast_state, type),
1155
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1156
17
        {offsetof(struct ast_state, name),
1157
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1158
17
        {offsetof(struct ast_state, body),
1159
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
1160
17
        {offsetof(struct ast_state, posonlyargs),
1161
17
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1162
17
        {offsetof(struct ast_state, args),
1163
17
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1164
17
        {offsetof(struct ast_state, vararg),
1165
17
         offsetof(struct ast_state, arg_type), FIELD_OPTIONAL},
1166
17
        {offsetof(struct ast_state, kwonlyargs),
1167
17
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1168
17
        {offsetof(struct ast_state, kw_defaults),
1169
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1170
17
        {offsetof(struct ast_state, kwarg),
1171
17
         offsetof(struct ast_state, arg_type), FIELD_OPTIONAL},
1172
17
        {offsetof(struct ast_state, defaults),
1173
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1174
17
        {offsetof(struct ast_state, arg),
1175
17
         0, FIELD_BUILTIN},
1176
17
        {offsetof(struct ast_state, annotation),
1177
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1178
17
        {offsetof(struct ast_state, type_comment),
1179
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1180
17
        {offsetof(struct ast_state, arg),
1181
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1182
17
        {offsetof(struct ast_state, value),
1183
17
         offsetof(struct ast_state, expr_type), 0},
1184
17
        {offsetof(struct ast_state, name),
1185
17
         0, FIELD_BUILTIN},
1186
17
        {offsetof(struct ast_state, asname),
1187
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1188
17
        {offsetof(struct ast_state, context_expr),
1189
17
         offsetof(struct ast_state, expr_type), 0},
1190
17
        {offsetof(struct ast_state, optional_vars),
1191
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1192
17
        {offsetof(struct ast_state, pattern),
1193
17
         offsetof(struct ast_state, pattern_type), 0},
1194
17
        {offsetof(struct ast_state, guard),
1195
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1196
17
        {offsetof(struct ast_state, body),
1197
17
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
1198
17
        {offsetof(struct ast_state, value),
1199
17
         offsetof(struct ast_state, expr_type), 0},
1200
17
        {offsetof(struct ast_state, value),
1201
17
         2, FIELD_BUILTIN},
1202
17
        {offsetof(struct ast_state, patterns),
1203
17
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1204
17
        {offsetof(struct ast_state, keys),
1205
17
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1206
17
        {offsetof(struct ast_state, patterns),
1207
17
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1208
17
        {offsetof(struct ast_state, rest),
1209
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1210
17
        {offsetof(struct ast_state, cls),
1211
17
         offsetof(struct ast_state, expr_type), 0},
1212
17
        {offsetof(struct ast_state, patterns),
1213
17
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1214
17
        {offsetof(struct ast_state, kwd_attrs),
1215
17
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1216
17
        {offsetof(struct ast_state, kwd_patterns),
1217
17
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1218
17
        {offsetof(struct ast_state, name),
1219
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1220
17
        {offsetof(struct ast_state, pattern),
1221
17
         offsetof(struct ast_state, pattern_type), FIELD_OPTIONAL},
1222
17
        {offsetof(struct ast_state, name),
1223
17
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1224
17
        {offsetof(struct ast_state, patterns),
1225
17
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1226
17
        {offsetof(struct ast_state, lineno),
1227
17
         1, FIELD_BUILTIN},
1228
17
        {offsetof(struct ast_state, tag),
1229
17
         0, FIELD_BUILTIN},
1230
17
        {offsetof(struct ast_state, name),
1231
17
         0, FIELD_BUILTIN},
1232
17
        {offsetof(struct ast_state, bound),
1233
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1234
17
        {offsetof(struct ast_state, default_value),
1235
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1236
17
        {offsetof(struct ast_state, name),
1237
17
         0, FIELD_BUILTIN},
1238
17
        {offsetof(struct ast_state, default_value),
1239
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1240
17
        {offsetof(struct ast_state, name),
1241
17
         0, FIELD_BUILTIN},
1242
17
        {offsetof(struct ast_state, default_value),
1243
17
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1244
17
    };
1245
17
    static const struct {
1246
17
        uint16_t type_offset;
1247
17
        uint16_t first_field;
1248
17
        uint16_t nfields;
1249
17
    } nodes[] = {
1250
17
        {offsetof(struct ast_state, Module_type), 0, 2},
1251
17
        {offsetof(struct ast_state, Interactive_type), 2, 1},
1252
17
        {offsetof(struct ast_state, Expression_type), 3, 1},
1253
17
        {offsetof(struct ast_state, FunctionType_type), 4, 2},
1254
17
        {offsetof(struct ast_state, FunctionDef_type), 6, 7},
1255
17
        {offsetof(struct ast_state, AsyncFunctionDef_type), 13, 7},
1256
17
        {offsetof(struct ast_state, ClassDef_type), 20, 6},
1257
17
        {offsetof(struct ast_state, Return_type), 26, 1},
1258
17
        {offsetof(struct ast_state, Delete_type), 27, 1},
1259
17
        {offsetof(struct ast_state, Assign_type), 28, 3},
1260
17
        {offsetof(struct ast_state, TypeAlias_type), 31, 3},
1261
17
        {offsetof(struct ast_state, AugAssign_type), 34, 3},
1262
17
        {offsetof(struct ast_state, AnnAssign_type), 37, 4},
1263
17
        {offsetof(struct ast_state, For_type), 41, 5},
1264
17
        {offsetof(struct ast_state, AsyncFor_type), 46, 5},
1265
17
        {offsetof(struct ast_state, While_type), 51, 3},
1266
17
        {offsetof(struct ast_state, If_type), 54, 3},
1267
17
        {offsetof(struct ast_state, With_type), 57, 3},
1268
17
        {offsetof(struct ast_state, AsyncWith_type), 60, 3},
1269
17
        {offsetof(struct ast_state, Match_type), 63, 2},
1270
17
        {offsetof(struct ast_state, Raise_type), 65, 2},
1271
17
        {offsetof(struct ast_state, Try_type), 67, 4},
1272
17
        {offsetof(struct ast_state, TryStar_type), 71, 4},
1273
17
        {offsetof(struct ast_state, Assert_type), 75, 2},
1274
17
        {offsetof(struct ast_state, Import_type), 77, 2},
1275
17
        {offsetof(struct ast_state, ImportFrom_type), 79, 4},
1276
17
        {offsetof(struct ast_state, Global_type), 83, 1},
1277
17
        {offsetof(struct ast_state, Nonlocal_type), 84, 1},
1278
17
        {offsetof(struct ast_state, Expr_type), 85, 1},
1279
17
        {offsetof(struct ast_state, Pass_type), 86, 0},
1280
17
        {offsetof(struct ast_state, Break_type), 86, 0},
1281
17
        {offsetof(struct ast_state, Continue_type), 86, 0},
1282
17
        {offsetof(struct ast_state, BoolOp_type), 86, 2},
1283
17
        {offsetof(struct ast_state, NamedExpr_type), 88, 2},
1284
17
        {offsetof(struct ast_state, BinOp_type), 90, 3},
1285
17
        {offsetof(struct ast_state, UnaryOp_type), 93, 2},
1286
17
        {offsetof(struct ast_state, Lambda_type), 95, 2},
1287
17
        {offsetof(struct ast_state, IfExp_type), 97, 3},
1288
17
        {offsetof(struct ast_state, Dict_type), 100, 2},
1289
17
        {offsetof(struct ast_state, Set_type), 102, 1},
1290
17
        {offsetof(struct ast_state, ListComp_type), 103, 2},
1291
17
        {offsetof(struct ast_state, SetComp_type), 105, 2},
1292
17
        {offsetof(struct ast_state, DictComp_type), 107, 3},
1293
17
        {offsetof(struct ast_state, GeneratorExp_type), 110, 2},
1294
17
        {offsetof(struct ast_state, Await_type), 112, 1},
1295
17
        {offsetof(struct ast_state, Yield_type), 113, 1},
1296
17
        {offsetof(struct ast_state, YieldFrom_type), 114, 1},
1297
17
        {offsetof(struct ast_state, Compare_type), 115, 3},
1298
17
        {offsetof(struct ast_state, Call_type), 118, 3},
1299
17
        {offsetof(struct ast_state, FormattedValue_type), 121, 3},
1300
17
        {offsetof(struct ast_state, Interpolation_type), 124, 4},
1301
17
        {offsetof(struct ast_state, JoinedStr_type), 128, 1},
1302
17
        {offsetof(struct ast_state, TemplateStr_type), 129, 1},
1303
17
        {offsetof(struct ast_state, Constant_type), 130, 2},
1304
17
        {offsetof(struct ast_state, Attribute_type), 132, 3},
1305
17
        {offsetof(struct ast_state, Subscript_type), 135, 3},
1306
17
        {offsetof(struct ast_state, Starred_type), 138, 2},
1307
17
        {offsetof(struct ast_state, Name_type), 140, 2},
1308
17
        {offsetof(struct ast_state, List_type), 142, 2},
1309
17
        {offsetof(struct ast_state, Tuple_type), 144, 2},
1310
17
        {offsetof(struct ast_state, Slice_type), 146, 3},
1311
17
        {offsetof(struct ast_state, Load_type), 149, 0},
1312
17
        {offsetof(struct ast_state, Store_type), 149, 0},
1313
17
        {offsetof(struct ast_state, Del_type), 149, 0},
1314
17
        {offsetof(struct ast_state, And_type), 149, 0},
1315
17
        {offsetof(struct ast_state, Or_type), 149, 0},
1316
17
        {offsetof(struct ast_state, Add_type), 149, 0},
1317
17
        {offsetof(struct ast_state, Sub_type), 149, 0},
1318
17
        {offsetof(struct ast_state, Mult_type), 149, 0},
1319
17
        {offsetof(struct ast_state, MatMult_type), 149, 0},
1320
17
        {offsetof(struct ast_state, Div_type), 149, 0},
1321
17
        {offsetof(struct ast_state, Mod_type), 149, 0},
1322
17
        {offsetof(struct ast_state, Pow_type), 149, 0},
1323
17
        {offsetof(struct ast_state, LShift_type), 149, 0},
1324
17
        {offsetof(struct ast_state, RShift_type), 149, 0},
1325
17
        {offsetof(struct ast_state, BitOr_type), 149, 0},
1326
17
        {offsetof(struct ast_state, BitXor_type), 149, 0},
1327
17
        {offsetof(struct ast_state, BitAnd_type), 149, 0},
1328
17
        {offsetof(struct ast_state, FloorDiv_type), 149, 0},
1329
17
        {offsetof(struct ast_state, Invert_type), 149, 0},
1330
17
        {offsetof(struct ast_state, Not_type), 149, 0},
1331
17
        {offsetof(struct ast_state, UAdd_type), 149, 0},
1332
17
        {offsetof(struct ast_state, USub_type), 149, 0},
1333
17
        {offsetof(struct ast_state, Eq_type), 149, 0},
1334
17
        {offsetof(struct ast_state, NotEq_type), 149, 0},
1335
17
        {offsetof(struct ast_state, Lt_type), 149, 0},
1336
17
        {offsetof(struct ast_state, LtE_type), 149, 0},
1337
17
        {offsetof(struct ast_state, Gt_type), 149, 0},
1338
17
        {offsetof(struct ast_state, GtE_type), 149, 0},
1339
17
        {offsetof(struct ast_state, Is_type), 149, 0},
1340
17
        {offsetof(struct ast_state, IsNot_type), 149, 0},
1341
17
        {offsetof(struct ast_state, In_type), 149, 0},
1342
17
        {offsetof(struct ast_state, NotIn_type), 149, 0},
1343
17
        {offsetof(struct ast_state, comprehension_type), 149, 4},
1344
17
        {offsetof(struct ast_state, ExceptHandler_type), 153, 3},
1345
17
        {offsetof(struct ast_state, arguments_type), 156, 7},
1346
17
        {offsetof(struct ast_state, arg_type), 163, 3},
1347
17
        {offsetof(struct ast_state, keyword_type), 166, 2},
1348
17
        {offsetof(struct ast_state, alias_type), 168, 2},
1349
17
        {offsetof(struct ast_state, withitem_type), 170, 2},
1350
17
        {offsetof(struct ast_state, match_case_type), 172, 3},
1351
17
        {offsetof(struct ast_state, MatchValue_type), 175, 1},
1352
17
        {offsetof(struct ast_state, MatchSingleton_type), 176, 1},
1353
17
        {offsetof(struct ast_state, MatchSequence_type), 177, 1},
1354
17
        {offsetof(struct ast_state, MatchMapping_type), 178, 3},
1355
17
        {offsetof(struct ast_state, MatchClass_type), 181, 4},
1356
17
        {offsetof(struct ast_state, MatchStar_type), 185, 1},
1357
17
        {offsetof(struct ast_state, MatchAs_type), 186, 2},
1358
17
        {offsetof(struct ast_state, MatchOr_type), 188, 1},
1359
17
        {offsetof(struct ast_state, TypeIgnore_type), 189, 2},
1360
17
        {offsetof(struct ast_state, TypeVar_type), 191, 3},
1361
17
        {offsetof(struct ast_state, ParamSpec_type), 194, 2},
1362
17
        {offsetof(struct ast_state, TypeVarTuple_type), 196, 2},
1363
17
    };
1364
17
    char *base = (char *)state;
1365
17
    PyObject *annotations = NULL;
1366
1.93k
    for (size_t i = 0; i < Py_ARRAY_LENGTH(nodes); i++) {
1367
1.92k
        annotations = PyDict_New();
1368
1.92k
        if (annotations == NULL) {
1369
0
            goto error;
1370
0
        }
1371
1.92k
        size_t end = nodes[i].first_field + nodes[i].nfields;
1372
5.28k
        for (size_t j = nodes[i].first_field; j < end; j++) {
1373
3.36k
            PyObject *name = *(PyObject **)(base + fields[j].name_offset);
1374
3.36k
            PyObject *type;
1375
3.36k
            if (fields[j].flags & FIELD_BUILTIN) {
1376
697
                type = (PyObject *)builtin_types[fields[j].type_offset];
1377
697
            }
1378
2.66k
            else {
1379
2.66k
                type = *(PyObject **)(base + fields[j].type_offset);
1380
2.66k
            }
1381
3.36k
            if (fields[j].flags & FIELD_OPTIONAL) {
1382
748
                type = _Py_union_type_or(type, Py_None);
1383
748
            }
1384
2.61k
            else if (fields[j].flags & FIELD_SEQUENCE) {
1385
1.25k
                type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1386
1.25k
            }
1387
1.36k
            else {
1388
1.36k
                Py_INCREF(type);
1389
1.36k
            }
1390
3.36k
            if (type == NULL) {
1391
0
                goto error;
1392
0
            }
1393
3.36k
            int res = PyDict_SetItem(annotations, name, type);
1394
3.36k
            Py_DECREF(type);
1395
3.36k
            if (res < 0) {
1396
0
                goto error;
1397
0
            }
1398
3.36k
        }
1399
1.92k
        PyObject *node = *(PyObject **)(base + nodes[i].type_offset);
1400
1.92k
        if (PyObject_SetAttrString(node, "_field_types", annotations) < 0 ||
1401
1.92k
            PyObject_SetAttrString(node, "__annotations__", annotations) < 0)
1402
0
        {
1403
0
            goto error;
1404
0
        }
1405
1.92k
        Py_CLEAR(annotations);
1406
1.92k
    }
1407
17
    return 1;
1408
0
error:
1409
0
    Py_XDECREF(annotations);
1410
0
    return 0;
1411
17
}
1412
1413
1414
1415
typedef struct {
1416
    PyObject_HEAD
1417
    PyObject *dict;
1418
} AST_object;
1419
1420
static void
1421
ast_dealloc(PyObject *op)
1422
423k
{
1423
423k
    AST_object *self = (AST_object*)op;
1424
    /* bpo-31095: UnTrack is needed before calling any callbacks */
1425
423k
    PyTypeObject *tp = Py_TYPE(self);
1426
423k
    PyObject_GC_UnTrack(self);
1427
423k
    Py_CLEAR(self->dict);
1428
423k
    freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1429
423k
    assert(free_func != NULL);
1430
423k
    free_func(self);
1431
423k
    Py_DECREF(tp);
1432
423k
}
1433
1434
static int
1435
ast_traverse(PyObject *op, visitproc visit, void *arg)
1436
336k
{
1437
336k
    AST_object *self = (AST_object*)op;
1438
336k
    Py_VISIT(Py_TYPE(self));
1439
336k
    Py_VISIT(self->dict);
1440
336k
    return 0;
1441
336k
}
1442
1443
static int
1444
ast_clear(PyObject *op)
1445
0
{
1446
0
    AST_object *self = (AST_object*)op;
1447
0
    Py_CLEAR(self->dict);
1448
0
    return 0;
1449
0
}
1450
1451
/*
1452
 * Format the names in the set 'missing' into a natural language list,
1453
 * sorted in the order in which they appear in 'fields'.
1454
 *
1455
 * Similar to format_missing() from 'Python/ceval.c'.
1456
 *
1457
 * Parameters
1458
 *
1459
 *      missing     Set of missing field names to render.
1460
 *      fields      Sequence of AST node field names (self._fields).
1461
 */
1462
static PyObject *
1463
format_missing(PyObject *missing, PyObject *fields)
1464
0
{
1465
0
    Py_ssize_t num_fields, num_total, num_left;
1466
0
    num_fields = PySequence_Size(fields);
1467
0
    if (num_fields == -1) {
1468
0
        return NULL;
1469
0
    }
1470
0
    num_total = num_left = PySet_GET_SIZE(missing);
1471
0
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
1472
0
    if (writer == NULL) {
1473
0
        goto error;
1474
0
    }
1475
    // Iterate all AST node fields in order so that the missing positional
1476
    // arguments are rendered in the order in which __init__ expects them.
1477
0
    for (Py_ssize_t i = 0; i < num_fields; i++) {
1478
0
        PyObject *name = PySequence_GetItem(fields, i);
1479
0
        if (name == NULL) {
1480
0
            goto error;
1481
0
        }
1482
0
        int contains = PySet_Contains(missing, name);
1483
0
        if (contains == -1) {
1484
0
            Py_DECREF(name);
1485
0
            goto error;
1486
0
        }
1487
0
        else if (contains == 1) {
1488
0
            const char* fmt = NULL;
1489
0
            if (num_left == 1) {
1490
0
                fmt = "'%U'";
1491
0
            }
1492
0
            else if (num_total == 2) {
1493
0
                fmt = "'%U' and ";
1494
0
            }
1495
0
            else if (num_left == 2) {
1496
0
                fmt = "'%U', and ";
1497
0
            }
1498
0
            else {
1499
0
                fmt = "'%U', ";
1500
0
            }
1501
0
            num_left--;
1502
0
            if (PyUnicodeWriter_Format(writer, fmt, name) < 0) {
1503
0
                Py_DECREF(name);
1504
0
                goto error;
1505
0
            }
1506
0
        }
1507
0
        Py_DECREF(name);
1508
0
    }
1509
0
    return PyUnicodeWriter_Finish(writer);
1510
0
error:
1511
0
    PyUnicodeWriter_Discard(writer);
1512
0
    return NULL;
1513
0
}
1514
1515
static int
1516
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1517
245
{
1518
245
    struct ast_state *state = get_ast_state();
1519
245
    if (state == NULL) {
1520
0
        return -1;
1521
0
    }
1522
1523
245
    int contains = PySet_Contains(state->abstract_types, (PyObject *)Py_TYPE(self));
1524
245
    if (contains == -1) {
1525
0
        return -1;
1526
0
    }
1527
245
    else if (contains == 1) {
1528
0
        if (PyErr_WarnFormat(
1529
0
                PyExc_DeprecationWarning, 1,
1530
0
                "Instantiating abstract AST node class %T is deprecated. "
1531
0
                "This will become an error in Python 3.20", self) < 0) {
1532
0
            return -1;
1533
0
        }
1534
0
    }
1535
1536
245
    Py_ssize_t i, numfields = 0;
1537
245
    int res = -1;
1538
245
    PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL;
1539
1540
245
    fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields);
1541
245
    if (fields == NULL) {
1542
0
        goto cleanup;
1543
0
    }
1544
1545
245
    numfields = PySequence_Size(fields);
1546
245
    if (numfields == -1) {
1547
0
        goto cleanup;
1548
0
    }
1549
245
    remaining_fields = PySet_New(fields);
1550
245
    if (remaining_fields == NULL) {
1551
0
        goto cleanup;
1552
0
    }
1553
1554
245
    res = 0; /* if no error occurs, this stays 0 to the end */
1555
245
    if (numfields < PyTuple_GET_SIZE(args)) {
1556
0
        PyErr_Format(PyExc_TypeError, "%T constructor takes at most "
1557
0
                     "%zd positional argument%s",
1558
0
                     self, numfields, numfields == 1 ? "" : "s");
1559
0
        res = -1;
1560
0
        goto cleanup;
1561
0
    }
1562
245
    for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1563
        /* cannot be reached when fields is NULL */
1564
0
        PyObject *name = PySequence_GetItem(fields, i);
1565
0
        if (!name) {
1566
0
            res = -1;
1567
0
            goto cleanup;
1568
0
        }
1569
0
        res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1570
0
        if (PySet_Discard(remaining_fields, name) < 0) {
1571
0
            res = -1;
1572
0
            Py_DECREF(name);
1573
0
            goto cleanup;
1574
0
        }
1575
0
        Py_DECREF(name);
1576
0
        if (res < 0) {
1577
0
            goto cleanup;
1578
0
        }
1579
0
    }
1580
245
    if (kw) {
1581
0
        i = 0;  /* needed by PyDict_Next */
1582
0
        while (PyDict_Next(kw, &i, &key, &value)) {
1583
0
            int contains = PySequence_Contains(fields, key);
1584
0
            if (contains == -1) {
1585
0
                res = -1;
1586
0
                goto cleanup;
1587
0
            }
1588
0
            else if (contains == 1) {
1589
0
                int p = PySet_Discard(remaining_fields, key);
1590
0
                if (p == -1) {
1591
0
                    res = -1;
1592
0
                    goto cleanup;
1593
0
                }
1594
0
                if (p == 0) {
1595
0
                    PyErr_Format(PyExc_TypeError,
1596
0
                        "%T got multiple values for argument %R",
1597
0
                        self, key);
1598
0
                    res = -1;
1599
0
                    goto cleanup;
1600
0
                }
1601
0
            }
1602
0
            else {
1603
                // Lazily initialize "attributes"
1604
0
                if (attributes == NULL) {
1605
0
                    attributes = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_attributes);
1606
0
                    if (attributes == NULL) {
1607
0
                        res = -1;
1608
0
                        goto cleanup;
1609
0
                    }
1610
0
                }
1611
0
                int contains = PySequence_Contains(attributes, key);
1612
0
                if (contains == -1) {
1613
0
                    res = -1;
1614
0
                    goto cleanup;
1615
0
                }
1616
0
                else if (contains == 0) {
1617
0
                    PyErr_Format(PyExc_TypeError,
1618
0
                        "%T.__init__ got an unexpected keyword argument %R",
1619
0
                        self, key);
1620
0
                    res = -1;
1621
0
                    goto cleanup;
1622
0
                }
1623
0
            }
1624
0
            res = PyObject_SetAttr(self, key, value);
1625
0
            if (res < 0) {
1626
0
                goto cleanup;
1627
0
            }
1628
0
        }
1629
0
    }
1630
245
    Py_ssize_t size = PySet_Size(remaining_fields);
1631
245
    PyObject *field_types = NULL, *remaining_list = NULL, *missing_names = NULL;
1632
245
    if (size > 0) {
1633
0
        if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
1634
0
                                     &field_types) < 0) {
1635
0
            res = -1;
1636
0
            goto cleanup;
1637
0
        }
1638
0
        if (field_types == NULL) {
1639
            // Probably a user-defined subclass of AST that lacks _field_types.
1640
            // This will continue to work as it did before 3.13; i.e., attributes
1641
            // that are not passed in simply do not exist on the instance.
1642
0
            goto cleanup;
1643
0
        }
1644
0
        remaining_list = PySequence_List(remaining_fields);
1645
0
        if (!remaining_list) {
1646
0
            goto set_remaining_cleanup;
1647
0
        }
1648
0
        missing_names = PySet_New(NULL);
1649
0
        if (!missing_names) {
1650
0
            goto set_remaining_cleanup;
1651
0
        }
1652
0
        for (Py_ssize_t i = 0; i < size; i++) {
1653
0
            PyObject *name = PyList_GET_ITEM(remaining_list, i);
1654
0
            PyObject *type = PyDict_GetItemWithError(field_types, name);
1655
0
            if (!type) {
1656
0
                if (PyErr_Occurred()) {
1657
0
                    goto set_remaining_cleanup;
1658
0
                }
1659
0
                else {
1660
0
                    PyErr_Format(PyExc_TypeError,
1661
0
                        "Field %R is missing from %T._field_types",
1662
0
                        name, self);
1663
0
                    goto set_remaining_cleanup;
1664
0
                }
1665
0
            }
1666
0
            else if (_PyUnion_Check(type)) {
1667
                // optional field
1668
                // do nothing, we'll have set a None default on the class
1669
0
            }
1670
0
            else if (Py_IS_TYPE(type, &Py_GenericAliasType)) {
1671
                // list field
1672
0
                PyObject *empty = PyList_New(0);
1673
0
                if (!empty) {
1674
0
                    goto set_remaining_cleanup;
1675
0
                }
1676
0
                res = PyObject_SetAttr(self, name, empty);
1677
0
                Py_DECREF(empty);
1678
0
                if (res < 0) {
1679
0
                    goto set_remaining_cleanup;
1680
0
                }
1681
0
            }
1682
0
            else if (type == state->expr_context_type) {
1683
                // special case for expr_context: default to Load()
1684
0
                res = PyObject_SetAttr(self, name, state->Load_singleton);
1685
0
                if (res < 0) {
1686
0
                    goto set_remaining_cleanup;
1687
0
                }
1688
0
            }
1689
0
            else {
1690
                // simple field (e.g., identifier)
1691
0
                res = PySet_Add(missing_names, name);
1692
0
                if (res < 0) {
1693
0
                    goto set_remaining_cleanup;
1694
0
                }
1695
0
            }
1696
0
        }
1697
0
        Py_ssize_t num_missing = PySet_GET_SIZE(missing_names);
1698
0
        if (num_missing > 0) {
1699
0
            PyObject *name_str = format_missing(missing_names, fields);
1700
0
            if (!name_str) {
1701
0
                goto set_remaining_cleanup;
1702
0
            }
1703
0
            PyErr_Format(PyExc_TypeError,
1704
0
                "%T.__init__ missing %d required positional argument%s: %U",
1705
0
                self, num_missing, num_missing == 1 ? "" : "s", name_str);
1706
0
            Py_DECREF(name_str);
1707
0
            goto set_remaining_cleanup;
1708
0
        }
1709
0
        Py_DECREF(missing_names);
1710
0
        Py_DECREF(remaining_list);
1711
0
        Py_DECREF(field_types);
1712
0
    }
1713
245
  cleanup:
1714
245
    Py_XDECREF(attributes);
1715
245
    Py_XDECREF(fields);
1716
245
    Py_XDECREF(remaining_fields);
1717
245
    return res;
1718
0
  set_remaining_cleanup:
1719
0
    Py_XDECREF(missing_names);
1720
0
    Py_XDECREF(remaining_list);
1721
0
    Py_XDECREF(field_types);
1722
0
    res = -1;
1723
0
    goto cleanup;
1724
245
}
1725
1726
/* Pickling support */
1727
static PyObject *
1728
ast_type_reduce(PyObject *self, PyObject *unused)
1729
0
{
1730
0
    struct ast_state *state = get_ast_state();
1731
0
    if (state == NULL) {
1732
0
        return NULL;
1733
0
    }
1734
1735
0
    PyObject *dict = NULL, *fields = NULL, *positional_args = NULL;
1736
0
    if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
1737
0
        return NULL;
1738
0
    }
1739
0
    PyObject *result = NULL;
1740
0
    if (dict) {
1741
        // Unpickling (or copying) works as follows:
1742
        // - Construct the object with only positional arguments
1743
        // - Set the fields from the dict
1744
        // We have two constraints:
1745
        // - We must set all the required fields in the initial constructor call,
1746
        //   or the unpickling or deepcopying of the object will trigger DeprecationWarnings.
1747
        // - We must not include child nodes in the positional args, because
1748
        //   that may trigger runaway recursion during copying (gh-120108).
1749
        // To satisfy both constraints, we set all the fields to None in the
1750
        // initial list of positional args, and then set the fields from the dict.
1751
0
        if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
1752
0
            goto cleanup;
1753
0
        }
1754
0
        if (fields) {
1755
0
            Py_ssize_t numfields = PySequence_Size(fields);
1756
0
            if (numfields == -1) {
1757
0
                Py_DECREF(dict);
1758
0
                goto cleanup;
1759
0
            }
1760
0
            positional_args = PyList_New(0);
1761
0
            if (!positional_args) {
1762
0
                goto cleanup;
1763
0
            }
1764
0
            for (Py_ssize_t i = 0; i < numfields; i++) {
1765
0
                PyObject *name = PySequence_GetItem(fields, i);
1766
0
                if (!name) {
1767
0
                    goto cleanup;
1768
0
                }
1769
0
                PyObject *value;
1770
0
                int rc = PyDict_GetItemRef(dict, name, &value);
1771
0
                Py_DECREF(name);
1772
0
                if (rc < 0) {
1773
0
                    goto cleanup;
1774
0
                }
1775
0
                if (!value) {
1776
0
                    break;
1777
0
                }
1778
0
                rc = PyList_Append(positional_args, Py_None);
1779
0
                Py_DECREF(value);
1780
0
                if (rc < 0) {
1781
0
                    goto cleanup;
1782
0
                }
1783
0
            }
1784
0
            PyObject *args_tuple = PyList_AsTuple(positional_args);
1785
0
            if (!args_tuple) {
1786
0
                goto cleanup;
1787
0
            }
1788
0
            result = Py_BuildValue("ONN", Py_TYPE(self), args_tuple, dict);
1789
0
        }
1790
0
        else {
1791
0
            result = Py_BuildValue("O()N", Py_TYPE(self), dict);
1792
0
        }
1793
0
    }
1794
0
    else {
1795
0
        result = Py_BuildValue("O()", Py_TYPE(self));
1796
0
    }
1797
0
cleanup:
1798
0
    Py_XDECREF(fields);
1799
0
    Py_XDECREF(positional_args);
1800
0
    return result;
1801
0
}
1802
1803
/*
1804
 * Python equivalent:
1805
 *
1806
 *   for key in keys:
1807
 *       if hasattr(self, key):
1808
 *           payload[key] = getattr(self, key)
1809
 *
1810
 * The 'keys' argument is a sequence corresponding to
1811
 * the '_fields' or the '_attributes' of an AST node.
1812
 *
1813
 * This returns -1 if an error occurs and 0 otherwise.
1814
 *
1815
 * Parameters
1816
 *
1817
 *      payload   A dictionary to fill.
1818
 *      keys      A sequence of keys or NULL for an empty sequence.
1819
 *      dict      The AST node instance dictionary (must not be NULL).
1820
 */
1821
static inline int
1822
ast_type_replace_update_payload(PyObject *payload,
1823
                                PyObject *keys,
1824
                                PyObject *dict)
1825
0
{
1826
0
    assert(dict != NULL);
1827
0
    if (keys == NULL) {
1828
0
        return 0;
1829
0
    }
1830
0
    Py_ssize_t n = PySequence_Size(keys);
1831
0
    if (n == -1) {
1832
0
        return -1;
1833
0
    }
1834
0
    for (Py_ssize_t i = 0; i < n; i++) {
1835
0
        PyObject *key = PySequence_GetItem(keys, i);
1836
0
        if (key == NULL) {
1837
0
            return -1;
1838
0
        }
1839
0
        PyObject *value;
1840
0
        if (PyDict_GetItemRef(dict, key, &value) < 0) {
1841
0
            Py_DECREF(key);
1842
0
            return -1;
1843
0
        }
1844
0
        if (value == NULL) {
1845
0
            Py_DECREF(key);
1846
            // If a field or attribute is not present at runtime, it should
1847
            // be explicitly given in 'kwargs'. If not, the constructor will
1848
            // issue a warning (which becomes an error in 3.15).
1849
0
            continue;
1850
0
        }
1851
0
        int rc = PyDict_SetItem(payload, key, value);
1852
0
        Py_DECREF(key);
1853
0
        Py_DECREF(value);
1854
0
        if (rc < 0) {
1855
0
            return -1;
1856
0
        }
1857
0
    }
1858
0
    return 0;
1859
0
}
1860
1861
/* copy.replace() support (shallow copy) */
1862
static PyObject *
1863
ast_type_replace(PyObject *self, PyObject *args, PyObject *kwargs)
1864
0
{
1865
0
    if (!_PyArg_NoPositional("__replace__", args)) {
1866
0
        return NULL;
1867
0
    }
1868
1869
0
    struct ast_state *state = get_ast_state();
1870
0
    if (state == NULL) {
1871
0
        return NULL;
1872
0
    }
1873
1874
0
    PyObject *result = NULL;
1875
    // known AST class fields and attributes
1876
0
    PyObject *fields = NULL, *attributes = NULL;
1877
    // current instance dictionary
1878
0
    PyObject *dict = NULL;
1879
    // constructor positional and keyword arguments
1880
0
    PyObject *empty_tuple = NULL, *payload = NULL;
1881
1882
0
    PyObject *type = (PyObject *)Py_TYPE(self);
1883
0
    if (PyObject_GetOptionalAttr(type, state->_fields, &fields) < 0) {
1884
0
        goto cleanup;
1885
0
    }
1886
0
    if (PyObject_GetOptionalAttr(type, state->_attributes, &attributes) < 0) {
1887
0
        goto cleanup;
1888
0
    }
1889
0
    if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
1890
0
        goto cleanup;
1891
0
    }
1892
0
    empty_tuple = PyTuple_New(0);
1893
0
    if (empty_tuple == NULL) {
1894
0
        goto cleanup;
1895
0
    }
1896
0
    payload = PyDict_New();
1897
0
    if (payload == NULL) {
1898
0
        goto cleanup;
1899
0
    }
1900
0
    if (dict) { // in case __dict__ is missing (for some obscure reason)
1901
        // copy the instance's fields (possibly NULL)
1902
0
        if (ast_type_replace_update_payload(payload, fields, dict) < 0) {
1903
0
            goto cleanup;
1904
0
        }
1905
        // copy the instance's attributes (possibly NULL)
1906
0
        if (ast_type_replace_update_payload(payload, attributes, dict) < 0) {
1907
0
            goto cleanup;
1908
0
        }
1909
0
    }
1910
0
    if (kwargs && PyDict_Update(payload, kwargs) < 0) {
1911
0
        goto cleanup;
1912
0
    }
1913
0
    result = PyObject_Call(type, empty_tuple, payload);
1914
0
cleanup:
1915
0
    Py_XDECREF(payload);
1916
0
    Py_XDECREF(empty_tuple);
1917
0
    Py_XDECREF(dict);
1918
0
    Py_XDECREF(attributes);
1919
0
    Py_XDECREF(fields);
1920
0
    return result;
1921
0
}
1922
1923
static PyMemberDef ast_type_members[] = {
1924
    {"__dictoffset__", Py_T_PYSSIZET, offsetof(AST_object, dict), Py_READONLY},
1925
    {NULL}  /* Sentinel */
1926
};
1927
1928
static PyMethodDef ast_type_methods[] = {
1929
    {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1930
    {"__replace__", _PyCFunction_CAST(ast_type_replace), METH_VARARGS | METH_KEYWORDS,
1931
     PyDoc_STR("__replace__($self, /, **fields)\n--\n\n"
1932
               "Return a copy of the AST node with new values "
1933
               "for the specified fields.")},
1934
    {NULL}
1935
};
1936
1937
static PyGetSetDef ast_type_getsets[] = {
1938
    {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1939
    {NULL}
1940
};
1941
1942
static PyObject *
1943
ast_repr_max_depth(AST_object *self, int depth);
1944
1945
/* Format list and tuple properties of AST nodes.
1946
   Note that, only the first and last elements are shown.
1947
   Anything in between is represented with an ellipsis ('...').
1948
   For example, the list [1, 2, 3] is formatted as
1949
   'List(elts=[Constant(1), ..., Constant(3)])'. */
1950
static PyObject *
1951
ast_repr_list(PyObject *list, int depth)
1952
0
{
1953
0
    assert(PyList_Check(list) || PyTuple_Check(list));
1954
1955
0
    struct ast_state *state = get_ast_state();
1956
0
    if (state == NULL) {
1957
0
        return NULL;
1958
0
    }
1959
1960
0
    Py_ssize_t length = PySequence_Size(list);
1961
0
    if (length < 0) {
1962
0
        return NULL;
1963
0
    }
1964
0
    else if (length == 0) {
1965
0
        return PyObject_Repr(list);
1966
0
    }
1967
1968
0
    PyObject *items[2] = {NULL, NULL};
1969
0
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
1970
0
    if (writer == NULL) {
1971
0
        goto error;
1972
0
    }
1973
1974
0
    items[0] = PySequence_GetItem(list, 0);
1975
0
    if (!items[0]) {
1976
0
        goto error;
1977
0
    }
1978
0
    if (length > 1) {
1979
0
        items[1] = PySequence_GetItem(list, length - 1);
1980
0
        if (!items[1]) {
1981
0
            goto error;
1982
0
        }
1983
0
    }
1984
1985
0
    bool is_list = PyList_Check(list);
1986
0
    if (PyUnicodeWriter_WriteChar(writer, is_list ? '[' : '(') < 0) {
1987
0
        goto error;
1988
0
    }
1989
1990
0
    for (Py_ssize_t i = 0; i < Py_MIN(length, 2); i++) {
1991
0
        if (i > 0) {
1992
0
            if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
1993
0
                goto error;
1994
0
            }
1995
0
        }
1996
1997
0
        PyObject *item = items[i];
1998
0
        if (PyType_IsSubtype(Py_TYPE(item), (PyTypeObject *)state->AST_type)) {
1999
0
            PyObject *item_repr;
2000
0
            item_repr = ast_repr_max_depth((AST_object*)item, depth - 1);
2001
0
            if (!item_repr) {
2002
0
                goto error;
2003
0
            }
2004
0
            if (PyUnicodeWriter_WriteStr(writer, item_repr) < 0) {
2005
0
                Py_DECREF(item_repr);
2006
0
                goto error;
2007
0
            }
2008
0
            Py_DECREF(item_repr);
2009
0
        } else {
2010
0
            if (PyUnicodeWriter_WriteRepr(writer, item) < 0) {
2011
0
                goto error;
2012
0
            }
2013
0
        }
2014
2015
0
        if (i == 0 && length > 2) {
2016
0
            if (PyUnicodeWriter_WriteASCII(writer, ", ...", 5) < 0) {
2017
0
                goto error;
2018
0
            }
2019
0
        }
2020
0
    }
2021
2022
0
    if (PyUnicodeWriter_WriteChar(writer, is_list ? ']' : ')') < 0) {
2023
0
        goto error;
2024
0
    }
2025
2026
0
    Py_XDECREF(items[0]);
2027
0
    Py_XDECREF(items[1]);
2028
0
    return PyUnicodeWriter_Finish(writer);
2029
2030
0
error:
2031
0
    Py_XDECREF(items[0]);
2032
0
    Py_XDECREF(items[1]);
2033
0
    PyUnicodeWriter_Discard(writer);
2034
0
    return NULL;
2035
0
}
2036
2037
static PyObject *
2038
ast_repr_max_depth(AST_object *self, int depth)
2039
0
{
2040
0
    struct ast_state *state = get_ast_state();
2041
0
    if (state == NULL) {
2042
0
        return NULL;
2043
0
    }
2044
2045
0
    PyObject *fields = PyObject_GetAttr((PyObject *)Py_TYPE(self), state->_fields);
2046
0
    if (!fields) {
2047
0
        return NULL;
2048
0
    }
2049
2050
0
    Py_ssize_t numfields = PySequence_Size(fields);
2051
0
    if (numfields < 0) {
2052
0
        Py_DECREF(fields);
2053
0
        return NULL;
2054
0
    }
2055
2056
0
    if (numfields == 0) {
2057
0
        Py_DECREF(fields);
2058
0
        return PyUnicode_FromFormat("%s()", Py_TYPE(self)->tp_name);
2059
0
    }
2060
2061
0
    if (depth <= 0) {
2062
0
        Py_DECREF(fields);
2063
0
        return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
2064
0
    }
2065
2066
0
    int status = Py_ReprEnter((PyObject *)self);
2067
0
    if (status != 0) {
2068
0
        Py_DECREF(fields);
2069
0
        if (status < 0) {
2070
0
            return NULL;
2071
0
        }
2072
0
        return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
2073
0
    }
2074
2075
0
    const char* tp_name = Py_TYPE(self)->tp_name;
2076
0
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
2077
0
    if (writer == NULL) {
2078
0
        goto error;
2079
0
    }
2080
2081
0
    if (PyUnicodeWriter_WriteUTF8(writer, tp_name, -1) < 0) {
2082
0
        goto error;
2083
0
    }
2084
0
    if (PyUnicodeWriter_WriteChar(writer, '(') < 0) {
2085
0
        goto error;
2086
0
    }
2087
2088
0
    for (Py_ssize_t i = 0; i < numfields; i++) {
2089
0
        PyObject *name = PySequence_GetItem(fields, i);
2090
0
        if (!name) {
2091
0
            goto error;
2092
0
        }
2093
2094
0
        PyObject *value = PyObject_GetAttr((PyObject *)self, name);
2095
0
        if (!value) {
2096
0
            Py_DECREF(name);
2097
0
            goto error;
2098
0
        }
2099
2100
0
        PyObject *value_repr;
2101
0
        if (PyList_Check(value) || PyTuple_Check(value)) {
2102
0
            value_repr = ast_repr_list(value, depth);
2103
0
        }
2104
0
        else if (PyType_IsSubtype(Py_TYPE(value), (PyTypeObject *)state->AST_type)) {
2105
0
            value_repr = ast_repr_max_depth((AST_object*)value, depth - 1);
2106
0
        }
2107
0
        else {
2108
0
            value_repr = PyObject_Repr(value);
2109
0
        }
2110
2111
0
        Py_DECREF(value);
2112
2113
0
        if (!value_repr) {
2114
0
            Py_DECREF(name);
2115
0
            goto error;
2116
0
        }
2117
2118
0
        if (i > 0) {
2119
0
            if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
2120
0
                Py_DECREF(name);
2121
0
                Py_DECREF(value_repr);
2122
0
                goto error;
2123
0
            }
2124
0
        }
2125
0
        if (PyUnicodeWriter_WriteStr(writer, name) < 0) {
2126
0
            Py_DECREF(name);
2127
0
            Py_DECREF(value_repr);
2128
0
            goto error;
2129
0
        }
2130
2131
0
        Py_DECREF(name);
2132
2133
0
        if (PyUnicodeWriter_WriteChar(writer, '=') < 0) {
2134
0
            Py_DECREF(value_repr);
2135
0
            goto error;
2136
0
        }
2137
0
        if (PyUnicodeWriter_WriteStr(writer, value_repr) < 0) {
2138
0
            Py_DECREF(value_repr);
2139
0
            goto error;
2140
0
        }
2141
2142
0
        Py_DECREF(value_repr);
2143
0
    }
2144
2145
0
    if (PyUnicodeWriter_WriteChar(writer, ')') < 0) {
2146
0
        goto error;
2147
0
    }
2148
0
    Py_ReprLeave((PyObject *)self);
2149
0
    Py_DECREF(fields);
2150
0
    return PyUnicodeWriter_Finish(writer);
2151
2152
0
error:
2153
0
    Py_ReprLeave((PyObject *)self);
2154
0
    Py_DECREF(fields);
2155
0
    PyUnicodeWriter_Discard(writer);
2156
0
    return NULL;
2157
0
}
2158
2159
static PyObject *
2160
ast_repr(PyObject *self)
2161
0
{
2162
0
    return ast_repr_max_depth((AST_object*)self, 3);
2163
0
}
2164
2165
static PyType_Slot AST_type_slots[] = {
2166
    {Py_tp_dealloc, ast_dealloc},
2167
    {Py_tp_repr, ast_repr},
2168
    {Py_tp_getattro, PyObject_GenericGetAttr},
2169
    {Py_tp_setattro, PyObject_GenericSetAttr},
2170
    {Py_tp_traverse, ast_traverse},
2171
    {Py_tp_clear, ast_clear},
2172
    {Py_tp_members, ast_type_members},
2173
    {Py_tp_methods, ast_type_methods},
2174
    {Py_tp_getset, ast_type_getsets},
2175
    {Py_tp_init, ast_type_init},
2176
    {Py_tp_alloc, PyType_GenericAlloc},
2177
    {Py_tp_new, PyType_GenericNew},
2178
    {Py_tp_free, PyObject_GC_Del},
2179
    {0, 0},
2180
};
2181
2182
static PyType_Spec AST_type_spec = {
2183
    "ast.AST",
2184
    sizeof(AST_object),
2185
    0,
2186
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
2187
    AST_type_slots
2188
};
2189
2190
static PyObject *
2191
make_type(struct ast_state *state, const char *type, PyObject* base,
2192
          const char* const* fields, int num_fields, const char *doc)
2193
2.12k
{
2194
2.12k
    PyObject *fnames, *result;
2195
2.12k
    int i;
2196
2.12k
    fnames = PyTuple_New(num_fields);
2197
2.12k
    if (!fnames) return NULL;
2198
5.49k
    for (i = 0; i < num_fields; i++) {
2199
3.36k
        PyObject *field = PyUnicode_InternFromString(fields[i]);
2200
3.36k
        if (!field) {
2201
0
            Py_DECREF(fnames);
2202
0
            return NULL;
2203
0
        }
2204
3.36k
        PyTuple_SET_ITEM(fnames, i, field);
2205
3.36k
    }
2206
2.12k
    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
2207
2.12k
                    type, base,
2208
2.12k
                    state->_fields, fnames,
2209
2.12k
                    state->__match_args__, fnames,
2210
2.12k
                    state->__module__,
2211
2.12k
                    state->ast,
2212
2.12k
                    state->__doc__, doc);
2213
2.12k
    Py_DECREF(fnames);
2214
2.12k
    return result;
2215
2.12k
}
2216
2217
static int
2218
add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
2219
323
{
2220
323
    int i, result;
2221
323
    PyObject *s, *l = PyTuple_New(num_fields);
2222
323
    if (!l)
2223
0
        return -1;
2224
867
    for (i = 0; i < num_fields; i++) {
2225
544
        s = PyUnicode_InternFromString(attrs[i]);
2226
544
        if (!s) {
2227
0
            Py_DECREF(l);
2228
0
            return -1;
2229
0
        }
2230
544
        PyTuple_SET_ITEM(l, i, s);
2231
544
    }
2232
323
    result = PyObject_SetAttr(type, state->_attributes, l);
2233
323
    Py_DECREF(l);
2234
323
    return result;
2235
323
}
2236
2237
/* Conversion AST -> Python */
2238
2239
static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq,
2240
                              PyObject* (*func)(struct ast_state *state, void*))
2241
96.2k
{
2242
96.2k
    Py_ssize_t i, n = asdl_seq_LEN(seq);
2243
96.2k
    PyObject *result = PyList_New(n);
2244
96.2k
    PyObject *value;
2245
96.2k
    if (!result)
2246
0
        return NULL;
2247
255k
    for (i = 0; i < n; i++) {
2248
158k
        value = func(state, asdl_seq_GET_UNTYPED(seq, i));
2249
158k
        if (!value) {
2250
0
            Py_DECREF(result);
2251
0
            return NULL;
2252
0
        }
2253
158k
        PyList_SET_ITEM(result, i, value);
2254
158k
    }
2255
96.2k
    return result;
2256
96.2k
}
2257
2258
static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
2259
258k
{
2260
258k
    PyObject *op = (PyObject*)o;
2261
258k
    if (!op) {
2262
86.3k
        op = Py_None;
2263
86.3k
    }
2264
258k
    return Py_NewRef(op);
2265
258k
}
2266
61.7k
#define ast2obj_constant ast2obj_object
2267
120k
#define ast2obj_identifier ast2obj_object
2268
75.0k
#define ast2obj_string ast2obj_object
2269
2270
static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
2271
1.65M
{
2272
1.65M
    return PyLong_FromLong(b);
2273
1.65M
}
2274
2275
/* Conversion Python -> AST */
2276
2277
static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj,
2278
                          PyObject** out,
2279
                          const char* Py_UNUSED(field), PyArena* arena)
2280
0
{
2281
0
    if (obj == Py_None)
2282
0
        obj = NULL;
2283
0
    if (obj) {
2284
0
        if (_PyArena_AddPyObject(arena, obj) < 0) {
2285
0
            *out = NULL;
2286
0
            return -1;
2287
0
        }
2288
0
        *out = Py_NewRef(obj);
2289
0
    }
2290
0
    else {
2291
0
        *out = NULL;
2292
0
    }
2293
0
    return 0;
2294
0
}
2295
2296
static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj,
2297
                            PyObject** out,
2298
                            const char* Py_UNUSED(field), PyArena* arena)
2299
0
{
2300
0
    if (_PyArena_AddPyObject(arena, obj) < 0) {
2301
0
        *out = NULL;
2302
0
        return -1;
2303
0
    }
2304
0
    *out = Py_NewRef(obj);
2305
0
    return 0;
2306
0
}
2307
2308
static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
2309
0
{
2310
0
    if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
2311
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string object, got %T", field, obj);
2312
0
        return -1;
2313
0
    }
2314
0
    return obj2ast_object(state, obj, out, field, arena);
2315
0
}
2316
2317
static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
2318
0
{
2319
0
    if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
2320
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string or bytes object, got %T", field, obj);
2321
0
        return -1;
2322
0
    }
2323
0
    return obj2ast_object(state, obj, out, field, arena);
2324
0
}
2325
2326
static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, const char* field, PyArena* arena)
2327
0
{
2328
0
    int i;
2329
0
    if (!PyLong_Check(obj)) {
2330
0
        PyErr_Format(PyExc_ValueError, "field \"%s\" got an invalid integer value: %R", field, obj);
2331
0
        return -1;
2332
0
    }
2333
2334
0
    i = PyLong_AsInt(obj);
2335
0
    if (i == -1 && PyErr_Occurred())
2336
0
        return -1;
2337
0
    *out = i;
2338
0
    return 0;
2339
0
}
2340
2341
static int add_ast_fields(struct ast_state *state)
2342
17
{
2343
17
    PyObject *empty_tuple;
2344
17
    empty_tuple = PyTuple_New(0);
2345
17
    if (!empty_tuple ||
2346
17
        PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
2347
17
        PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
2348
17
        PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
2349
0
        Py_XDECREF(empty_tuple);
2350
0
        return -1;
2351
0
    }
2352
17
    Py_DECREF(empty_tuple);
2353
17
    return 0;
2354
17
}
2355
2356
2357
2358
static int
2359
init_types(void *arg)
2360
17
{
2361
17
    struct ast_state *state = arg;
2362
17
    if (init_identifiers(state) < 0) {
2363
0
        return -1;
2364
0
    }
2365
17
    state->AST_type = PyType_FromSpec(&AST_type_spec);
2366
17
    if (!state->AST_type) {
2367
0
        return -1;
2368
0
    }
2369
17
    state->abstract_types = PySet_New(NULL);
2370
17
    if (!state->abstract_types) {
2371
0
        return -1;
2372
0
    }
2373
17
    if (PySet_Add(state->abstract_types, state->AST_type) < 0) {
2374
0
        return -1;
2375
0
    }
2376
17
    if (add_ast_fields(state) < 0) {
2377
0
        return -1;
2378
0
    }
2379
17
    state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
2380
17
        "mod = Module(stmt* body, type_ignore* type_ignores)\n"
2381
17
        "    | Interactive(stmt* body)\n"
2382
17
        "    | Expression(expr body)\n"
2383
17
        "    | FunctionType(expr* argtypes, expr returns)");
2384
17
    if (!state->mod_type) return -1;
2385
17
    if (add_attributes(state, state->mod_type, NULL, 0) < 0) return -1;
2386
17
    if (PySet_Add(state->abstract_types, state->mod_type) < 0) return -1;
2387
17
    state->Module_type = make_type(state, "Module", state->mod_type,
2388
17
                                   Module_fields, 2,
2389
17
        "Module(stmt* body, type_ignore* type_ignores)");
2390
17
    if (!state->Module_type) return -1;
2391
17
    state->Interactive_type = make_type(state, "Interactive", state->mod_type,
2392
17
                                        Interactive_fields, 1,
2393
17
        "Interactive(stmt* body)");
2394
17
    if (!state->Interactive_type) return -1;
2395
17
    state->Expression_type = make_type(state, "Expression", state->mod_type,
2396
17
                                       Expression_fields, 1,
2397
17
        "Expression(expr body)");
2398
17
    if (!state->Expression_type) return -1;
2399
17
    state->FunctionType_type = make_type(state, "FunctionType",
2400
17
                                         state->mod_type, FunctionType_fields,
2401
17
                                         2,
2402
17
        "FunctionType(expr* argtypes, expr returns)");
2403
17
    if (!state->FunctionType_type) return -1;
2404
17
    state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
2405
17
        "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
2406
17
        "     | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
2407
17
        "     | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
2408
17
        "     | Return(expr? value)\n"
2409
17
        "     | Delete(expr* targets)\n"
2410
17
        "     | Assign(expr* targets, expr value, string? type_comment)\n"
2411
17
        "     | TypeAlias(expr name, type_param* type_params, expr value)\n"
2412
17
        "     | AugAssign(expr target, operator op, expr value)\n"
2413
17
        "     | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
2414
17
        "     | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
2415
17
        "     | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
2416
17
        "     | While(expr test, stmt* body, stmt* orelse)\n"
2417
17
        "     | If(expr test, stmt* body, stmt* orelse)\n"
2418
17
        "     | With(withitem* items, stmt* body, string? type_comment)\n"
2419
17
        "     | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
2420
17
        "     | Match(expr subject, match_case* cases)\n"
2421
17
        "     | Raise(expr? exc, expr? cause)\n"
2422
17
        "     | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
2423
17
        "     | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
2424
17
        "     | Assert(expr test, expr? msg)\n"
2425
17
        "     | Import(alias* names, int? is_lazy)\n"
2426
17
        "     | ImportFrom(identifier? module, alias* names, int? level, int? is_lazy)\n"
2427
17
        "     | Global(identifier* names)\n"
2428
17
        "     | Nonlocal(identifier* names)\n"
2429
17
        "     | Expr(expr value)\n"
2430
17
        "     | Pass\n"
2431
17
        "     | Break\n"
2432
17
        "     | Continue");
2433
17
    if (!state->stmt_type) return -1;
2434
17
    if (add_attributes(state, state->stmt_type, stmt_attributes, 4) < 0) return
2435
0
        -1;
2436
17
    if (PySet_Add(state->abstract_types, state->stmt_type) < 0) return -1;
2437
17
    if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
2438
0
        return -1;
2439
17
    if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
2440
17
        -1)
2441
0
        return -1;
2442
17
    state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
2443
17
                                        FunctionDef_fields, 7,
2444
17
        "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
2445
17
    if (!state->FunctionDef_type) return -1;
2446
17
    if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
2447
17
        -1)
2448
0
        return -1;
2449
17
    if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
2450
17
        == -1)
2451
0
        return -1;
2452
17
    state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
2453
17
                                             state->stmt_type,
2454
17
                                             AsyncFunctionDef_fields, 7,
2455
17
        "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
2456
17
    if (!state->AsyncFunctionDef_type) return -1;
2457
17
    if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
2458
17
        == -1)
2459
0
        return -1;
2460
17
    if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
2461
17
        Py_None) == -1)
2462
0
        return -1;
2463
17
    state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
2464
17
                                     ClassDef_fields, 6,
2465
17
        "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
2466
17
    if (!state->ClassDef_type) return -1;
2467
17
    state->Return_type = make_type(state, "Return", state->stmt_type,
2468
17
                                   Return_fields, 1,
2469
17
        "Return(expr? value)");
2470
17
    if (!state->Return_type) return -1;
2471
17
    if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
2472
0
        return -1;
2473
17
    state->Delete_type = make_type(state, "Delete", state->stmt_type,
2474
17
                                   Delete_fields, 1,
2475
17
        "Delete(expr* targets)");
2476
17
    if (!state->Delete_type) return -1;
2477
17
    state->Assign_type = make_type(state, "Assign", state->stmt_type,
2478
17
                                   Assign_fields, 3,
2479
17
        "Assign(expr* targets, expr value, string? type_comment)");
2480
17
    if (!state->Assign_type) return -1;
2481
17
    if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
2482
17
        -1)
2483
0
        return -1;
2484
17
    state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
2485
17
                                      TypeAlias_fields, 3,
2486
17
        "TypeAlias(expr name, type_param* type_params, expr value)");
2487
17
    if (!state->TypeAlias_type) return -1;
2488
17
    state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
2489
17
                                      AugAssign_fields, 3,
2490
17
        "AugAssign(expr target, operator op, expr value)");
2491
17
    if (!state->AugAssign_type) return -1;
2492
17
    state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
2493
17
                                      AnnAssign_fields, 4,
2494
17
        "AnnAssign(expr target, expr annotation, expr? value, int simple)");
2495
17
    if (!state->AnnAssign_type) return -1;
2496
17
    if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
2497
0
        return -1;
2498
17
    state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
2499
17
        "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
2500
17
    if (!state->For_type) return -1;
2501
17
    if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
2502
0
        return -1;
2503
17
    state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
2504
17
                                     AsyncFor_fields, 5,
2505
17
        "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
2506
17
    if (!state->AsyncFor_type) return -1;
2507
17
    if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
2508
17
        -1)
2509
0
        return -1;
2510
17
    state->While_type = make_type(state, "While", state->stmt_type,
2511
17
                                  While_fields, 3,
2512
17
        "While(expr test, stmt* body, stmt* orelse)");
2513
17
    if (!state->While_type) return -1;
2514
17
    state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
2515
17
        "If(expr test, stmt* body, stmt* orelse)");
2516
17
    if (!state->If_type) return -1;
2517
17
    state->With_type = make_type(state, "With", state->stmt_type, With_fields,
2518
17
                                 3,
2519
17
        "With(withitem* items, stmt* body, string? type_comment)");
2520
17
    if (!state->With_type) return -1;
2521
17
    if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
2522
0
        return -1;
2523
17
    state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
2524
17
                                      AsyncWith_fields, 3,
2525
17
        "AsyncWith(withitem* items, stmt* body, string? type_comment)");
2526
17
    if (!state->AsyncWith_type) return -1;
2527
17
    if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
2528
17
        == -1)
2529
0
        return -1;
2530
17
    state->Match_type = make_type(state, "Match", state->stmt_type,
2531
17
                                  Match_fields, 2,
2532
17
        "Match(expr subject, match_case* cases)");
2533
17
    if (!state->Match_type) return -1;
2534
17
    state->Raise_type = make_type(state, "Raise", state->stmt_type,
2535
17
                                  Raise_fields, 2,
2536
17
        "Raise(expr? exc, expr? cause)");
2537
17
    if (!state->Raise_type) return -1;
2538
17
    if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
2539
0
        return -1;
2540
17
    if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
2541
0
        return -1;
2542
17
    state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
2543
17
        "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
2544
17
    if (!state->Try_type) return -1;
2545
17
    state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
2546
17
                                    TryStar_fields, 4,
2547
17
        "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
2548
17
    if (!state->TryStar_type) return -1;
2549
17
    state->Assert_type = make_type(state, "Assert", state->stmt_type,
2550
17
                                   Assert_fields, 2,
2551
17
        "Assert(expr test, expr? msg)");
2552
17
    if (!state->Assert_type) return -1;
2553
17
    if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
2554
0
        return -1;
2555
17
    state->Import_type = make_type(state, "Import", state->stmt_type,
2556
17
                                   Import_fields, 2,
2557
17
        "Import(alias* names, int? is_lazy)");
2558
17
    if (!state->Import_type) return -1;
2559
17
    if (PyObject_SetAttr(state->Import_type, state->is_lazy, Py_None) == -1)
2560
0
        return -1;
2561
17
    state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
2562
17
                                       ImportFrom_fields, 4,
2563
17
        "ImportFrom(identifier? module, alias* names, int? level, int? is_lazy)");
2564
17
    if (!state->ImportFrom_type) return -1;
2565
17
    if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
2566
0
        return -1;
2567
17
    if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
2568
0
        return -1;
2569
17
    if (PyObject_SetAttr(state->ImportFrom_type, state->is_lazy, Py_None) == -1)
2570
0
        return -1;
2571
17
    state->Global_type = make_type(state, "Global", state->stmt_type,
2572
17
                                   Global_fields, 1,
2573
17
        "Global(identifier* names)");
2574
17
    if (!state->Global_type) return -1;
2575
17
    state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
2576
17
                                     Nonlocal_fields, 1,
2577
17
        "Nonlocal(identifier* names)");
2578
17
    if (!state->Nonlocal_type) return -1;
2579
17
    state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
2580
17
                                 1,
2581
17
        "Expr(expr value)");
2582
17
    if (!state->Expr_type) return -1;
2583
17
    state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
2584
17
        "Pass");
2585
17
    if (!state->Pass_type) return -1;
2586
17
    state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
2587
17
        "Break");
2588
17
    if (!state->Break_type) return -1;
2589
17
    state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
2590
17
                                     0,
2591
17
        "Continue");
2592
17
    if (!state->Continue_type) return -1;
2593
17
    state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
2594
17
        "expr = BoolOp(boolop op, expr* values)\n"
2595
17
        "     | NamedExpr(expr target, expr value)\n"
2596
17
        "     | BinOp(expr left, operator op, expr right)\n"
2597
17
        "     | UnaryOp(unaryop op, expr operand)\n"
2598
17
        "     | Lambda(arguments args, expr body)\n"
2599
17
        "     | IfExp(expr test, expr body, expr orelse)\n"
2600
17
        "     | Dict(expr?* keys, expr* values)\n"
2601
17
        "     | Set(expr* elts)\n"
2602
17
        "     | ListComp(expr elt, comprehension* generators)\n"
2603
17
        "     | SetComp(expr elt, comprehension* generators)\n"
2604
17
        "     | DictComp(expr key, expr? value, comprehension* generators)\n"
2605
17
        "     | GeneratorExp(expr elt, comprehension* generators)\n"
2606
17
        "     | Await(expr value)\n"
2607
17
        "     | Yield(expr? value)\n"
2608
17
        "     | YieldFrom(expr value)\n"
2609
17
        "     | Compare(expr left, cmpop* ops, expr* comparators)\n"
2610
17
        "     | Call(expr func, expr* args, keyword* keywords)\n"
2611
17
        "     | FormattedValue(expr value, int conversion, expr? format_spec)\n"
2612
17
        "     | Interpolation(expr value, constant str, int conversion, expr? format_spec)\n"
2613
17
        "     | JoinedStr(expr* values)\n"
2614
17
        "     | TemplateStr(expr* values)\n"
2615
17
        "     | Constant(constant value, string? kind)\n"
2616
17
        "     | Attribute(expr value, identifier attr, expr_context ctx)\n"
2617
17
        "     | Subscript(expr value, expr slice, expr_context ctx)\n"
2618
17
        "     | Starred(expr value, expr_context ctx)\n"
2619
17
        "     | Name(identifier id, expr_context ctx)\n"
2620
17
        "     | List(expr* elts, expr_context ctx)\n"
2621
17
        "     | Tuple(expr* elts, expr_context ctx)\n"
2622
17
        "     | Slice(expr? lower, expr? upper, expr? step)");
2623
17
    if (!state->expr_type) return -1;
2624
17
    if (add_attributes(state, state->expr_type, expr_attributes, 4) < 0) return
2625
0
        -1;
2626
17
    if (PySet_Add(state->abstract_types, state->expr_type) < 0) return -1;
2627
17
    if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
2628
0
        return -1;
2629
17
    if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
2630
17
        -1)
2631
0
        return -1;
2632
17
    state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
2633
17
                                   BoolOp_fields, 2,
2634
17
        "BoolOp(boolop op, expr* values)");
2635
17
    if (!state->BoolOp_type) return -1;
2636
17
    state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
2637
17
                                      NamedExpr_fields, 2,
2638
17
        "NamedExpr(expr target, expr value)");
2639
17
    if (!state->NamedExpr_type) return -1;
2640
17
    state->BinOp_type = make_type(state, "BinOp", state->expr_type,
2641
17
                                  BinOp_fields, 3,
2642
17
        "BinOp(expr left, operator op, expr right)");
2643
17
    if (!state->BinOp_type) return -1;
2644
17
    state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
2645
17
                                    UnaryOp_fields, 2,
2646
17
        "UnaryOp(unaryop op, expr operand)");
2647
17
    if (!state->UnaryOp_type) return -1;
2648
17
    state->Lambda_type = make_type(state, "Lambda", state->expr_type,
2649
17
                                   Lambda_fields, 2,
2650
17
        "Lambda(arguments args, expr body)");
2651
17
    if (!state->Lambda_type) return -1;
2652
17
    state->IfExp_type = make_type(state, "IfExp", state->expr_type,
2653
17
                                  IfExp_fields, 3,
2654
17
        "IfExp(expr test, expr body, expr orelse)");
2655
17
    if (!state->IfExp_type) return -1;
2656
17
    state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
2657
17
                                 2,
2658
17
        "Dict(expr?* keys, expr* values)");
2659
17
    if (!state->Dict_type) return -1;
2660
17
    state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
2661
17
        "Set(expr* elts)");
2662
17
    if (!state->Set_type) return -1;
2663
17
    state->ListComp_type = make_type(state, "ListComp", state->expr_type,
2664
17
                                     ListComp_fields, 2,
2665
17
        "ListComp(expr elt, comprehension* generators)");
2666
17
    if (!state->ListComp_type) return -1;
2667
17
    state->SetComp_type = make_type(state, "SetComp", state->expr_type,
2668
17
                                    SetComp_fields, 2,
2669
17
        "SetComp(expr elt, comprehension* generators)");
2670
17
    if (!state->SetComp_type) return -1;
2671
17
    state->DictComp_type = make_type(state, "DictComp", state->expr_type,
2672
17
                                     DictComp_fields, 3,
2673
17
        "DictComp(expr key, expr? value, comprehension* generators)");
2674
17
    if (!state->DictComp_type) return -1;
2675
17
    if (PyObject_SetAttr(state->DictComp_type, state->value, Py_None) == -1)
2676
0
        return -1;
2677
17
    state->GeneratorExp_type = make_type(state, "GeneratorExp",
2678
17
                                         state->expr_type, GeneratorExp_fields,
2679
17
                                         2,
2680
17
        "GeneratorExp(expr elt, comprehension* generators)");
2681
17
    if (!state->GeneratorExp_type) return -1;
2682
17
    state->Await_type = make_type(state, "Await", state->expr_type,
2683
17
                                  Await_fields, 1,
2684
17
        "Await(expr value)");
2685
17
    if (!state->Await_type) return -1;
2686
17
    state->Yield_type = make_type(state, "Yield", state->expr_type,
2687
17
                                  Yield_fields, 1,
2688
17
        "Yield(expr? value)");
2689
17
    if (!state->Yield_type) return -1;
2690
17
    if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
2691
0
        return -1;
2692
17
    state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
2693
17
                                      YieldFrom_fields, 1,
2694
17
        "YieldFrom(expr value)");
2695
17
    if (!state->YieldFrom_type) return -1;
2696
17
    state->Compare_type = make_type(state, "Compare", state->expr_type,
2697
17
                                    Compare_fields, 3,
2698
17
        "Compare(expr left, cmpop* ops, expr* comparators)");
2699
17
    if (!state->Compare_type) return -1;
2700
17
    state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
2701
17
                                 3,
2702
17
        "Call(expr func, expr* args, keyword* keywords)");
2703
17
    if (!state->Call_type) return -1;
2704
17
    state->FormattedValue_type = make_type(state, "FormattedValue",
2705
17
                                           state->expr_type,
2706
17
                                           FormattedValue_fields, 3,
2707
17
        "FormattedValue(expr value, int conversion, expr? format_spec)");
2708
17
    if (!state->FormattedValue_type) return -1;
2709
17
    if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
2710
17
        Py_None) == -1)
2711
0
        return -1;
2712
17
    state->Interpolation_type = make_type(state, "Interpolation",
2713
17
                                          state->expr_type,
2714
17
                                          Interpolation_fields, 4,
2715
17
        "Interpolation(expr value, constant str, int conversion, expr? format_spec)");
2716
17
    if (!state->Interpolation_type) return -1;
2717
17
    if (PyObject_SetAttr(state->Interpolation_type, state->format_spec,
2718
17
        Py_None) == -1)
2719
0
        return -1;
2720
17
    state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
2721
17
                                      JoinedStr_fields, 1,
2722
17
        "JoinedStr(expr* values)");
2723
17
    if (!state->JoinedStr_type) return -1;
2724
17
    state->TemplateStr_type = make_type(state, "TemplateStr", state->expr_type,
2725
17
                                        TemplateStr_fields, 1,
2726
17
        "TemplateStr(expr* values)");
2727
17
    if (!state->TemplateStr_type) return -1;
2728
17
    state->Constant_type = make_type(state, "Constant", state->expr_type,
2729
17
                                     Constant_fields, 2,
2730
17
        "Constant(constant value, string? kind)");
2731
17
    if (!state->Constant_type) return -1;
2732
17
    if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
2733
0
        return -1;
2734
17
    state->Attribute_type = make_type(state, "Attribute", state->expr_type,
2735
17
                                      Attribute_fields, 3,
2736
17
        "Attribute(expr value, identifier attr, expr_context ctx)");
2737
17
    if (!state->Attribute_type) return -1;
2738
17
    state->Subscript_type = make_type(state, "Subscript", state->expr_type,
2739
17
                                      Subscript_fields, 3,
2740
17
        "Subscript(expr value, expr slice, expr_context ctx)");
2741
17
    if (!state->Subscript_type) return -1;
2742
17
    state->Starred_type = make_type(state, "Starred", state->expr_type,
2743
17
                                    Starred_fields, 2,
2744
17
        "Starred(expr value, expr_context ctx)");
2745
17
    if (!state->Starred_type) return -1;
2746
17
    state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
2747
17
                                 2,
2748
17
        "Name(identifier id, expr_context ctx)");
2749
17
    if (!state->Name_type) return -1;
2750
17
    state->List_type = make_type(state, "List", state->expr_type, List_fields,
2751
17
                                 2,
2752
17
        "List(expr* elts, expr_context ctx)");
2753
17
    if (!state->List_type) return -1;
2754
17
    state->Tuple_type = make_type(state, "Tuple", state->expr_type,
2755
17
                                  Tuple_fields, 2,
2756
17
        "Tuple(expr* elts, expr_context ctx)");
2757
17
    if (!state->Tuple_type) return -1;
2758
17
    state->Slice_type = make_type(state, "Slice", state->expr_type,
2759
17
                                  Slice_fields, 3,
2760
17
        "Slice(expr? lower, expr? upper, expr? step)");
2761
17
    if (!state->Slice_type) return -1;
2762
17
    if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
2763
0
        return -1;
2764
17
    if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
2765
0
        return -1;
2766
17
    if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
2767
0
        return -1;
2768
17
    state->expr_context_type = make_type(state, "expr_context",
2769
17
                                         state->AST_type, NULL, 0,
2770
17
        "expr_context = Load | Store | Del");
2771
17
    if (!state->expr_context_type) return -1;
2772
17
    if (add_attributes(state, state->expr_context_type, NULL, 0) < 0) return -1;
2773
17
    if (PySet_Add(state->abstract_types, state->expr_context_type) < 0) return
2774
0
        -1;
2775
17
    state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
2776
17
                                 0,
2777
17
        "Load");
2778
17
    if (!state->Load_type) return -1;
2779
17
    state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
2780
17
                                              NULL, NULL);
2781
17
    if (!state->Load_singleton) return -1;
2782
17
    state->Store_type = make_type(state, "Store", state->expr_context_type,
2783
17
                                  NULL, 0,
2784
17
        "Store");
2785
17
    if (!state->Store_type) return -1;
2786
17
    state->Store_singleton = PyType_GenericNew((PyTypeObject
2787
17
                                               *)state->Store_type, NULL, NULL);
2788
17
    if (!state->Store_singleton) return -1;
2789
17
    state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
2790
17
        "Del");
2791
17
    if (!state->Del_type) return -1;
2792
17
    state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
2793
17
                                             NULL, NULL);
2794
17
    if (!state->Del_singleton) return -1;
2795
17
    state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
2796
17
        "boolop = And | Or");
2797
17
    if (!state->boolop_type) return -1;
2798
17
    if (add_attributes(state, state->boolop_type, NULL, 0) < 0) return -1;
2799
17
    if (PySet_Add(state->abstract_types, state->boolop_type) < 0) return -1;
2800
17
    state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
2801
17
        "And");
2802
17
    if (!state->And_type) return -1;
2803
17
    state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
2804
17
                                             NULL, NULL);
2805
17
    if (!state->And_singleton) return -1;
2806
17
    state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
2807
17
        "Or");
2808
17
    if (!state->Or_type) return -1;
2809
17
    state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
2810
17
                                            NULL, NULL);
2811
17
    if (!state->Or_singleton) return -1;
2812
17
    state->operator_type = make_type(state, "operator", state->AST_type, NULL,
2813
17
                                     0,
2814
17
        "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
2815
17
    if (!state->operator_type) return -1;
2816
17
    if (add_attributes(state, state->operator_type, NULL, 0) < 0) return -1;
2817
17
    if (PySet_Add(state->abstract_types, state->operator_type) < 0) return -1;
2818
17
    state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
2819
17
        "Add");
2820
17
    if (!state->Add_type) return -1;
2821
17
    state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
2822
17
                                             NULL, NULL);
2823
17
    if (!state->Add_singleton) return -1;
2824
17
    state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
2825
17
        "Sub");
2826
17
    if (!state->Sub_type) return -1;
2827
17
    state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
2828
17
                                             NULL, NULL);
2829
17
    if (!state->Sub_singleton) return -1;
2830
17
    state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
2831
17
        "Mult");
2832
17
    if (!state->Mult_type) return -1;
2833
17
    state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
2834
17
                                              NULL, NULL);
2835
17
    if (!state->Mult_singleton) return -1;
2836
17
    state->MatMult_type = make_type(state, "MatMult", state->operator_type,
2837
17
                                    NULL, 0,
2838
17
        "MatMult");
2839
17
    if (!state->MatMult_type) return -1;
2840
17
    state->MatMult_singleton = PyType_GenericNew((PyTypeObject
2841
17
                                                 *)state->MatMult_type, NULL,
2842
17
                                                 NULL);
2843
17
    if (!state->MatMult_singleton) return -1;
2844
17
    state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
2845
17
        "Div");
2846
17
    if (!state->Div_type) return -1;
2847
17
    state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
2848
17
                                             NULL, NULL);
2849
17
    if (!state->Div_singleton) return -1;
2850
17
    state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
2851
17
        "Mod");
2852
17
    if (!state->Mod_type) return -1;
2853
17
    state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
2854
17
                                             NULL, NULL);
2855
17
    if (!state->Mod_singleton) return -1;
2856
17
    state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
2857
17
        "Pow");
2858
17
    if (!state->Pow_type) return -1;
2859
17
    state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
2860
17
                                             NULL, NULL);
2861
17
    if (!state->Pow_singleton) return -1;
2862
17
    state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
2863
17
                                   0,
2864
17
        "LShift");
2865
17
    if (!state->LShift_type) return -1;
2866
17
    state->LShift_singleton = PyType_GenericNew((PyTypeObject
2867
17
                                                *)state->LShift_type, NULL,
2868
17
                                                NULL);
2869
17
    if (!state->LShift_singleton) return -1;
2870
17
    state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
2871
17
                                   0,
2872
17
        "RShift");
2873
17
    if (!state->RShift_type) return -1;
2874
17
    state->RShift_singleton = PyType_GenericNew((PyTypeObject
2875
17
                                                *)state->RShift_type, NULL,
2876
17
                                                NULL);
2877
17
    if (!state->RShift_singleton) return -1;
2878
17
    state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
2879
17
        "BitOr");
2880
17
    if (!state->BitOr_type) return -1;
2881
17
    state->BitOr_singleton = PyType_GenericNew((PyTypeObject
2882
17
                                               *)state->BitOr_type, NULL, NULL);
2883
17
    if (!state->BitOr_singleton) return -1;
2884
17
    state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
2885
17
                                   0,
2886
17
        "BitXor");
2887
17
    if (!state->BitXor_type) return -1;
2888
17
    state->BitXor_singleton = PyType_GenericNew((PyTypeObject
2889
17
                                                *)state->BitXor_type, NULL,
2890
17
                                                NULL);
2891
17
    if (!state->BitXor_singleton) return -1;
2892
17
    state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
2893
17
                                   0,
2894
17
        "BitAnd");
2895
17
    if (!state->BitAnd_type) return -1;
2896
17
    state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
2897
17
                                                *)state->BitAnd_type, NULL,
2898
17
                                                NULL);
2899
17
    if (!state->BitAnd_singleton) return -1;
2900
17
    state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
2901
17
                                     NULL, 0,
2902
17
        "FloorDiv");
2903
17
    if (!state->FloorDiv_type) return -1;
2904
17
    state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
2905
17
                                                  *)state->FloorDiv_type, NULL,
2906
17
                                                  NULL);
2907
17
    if (!state->FloorDiv_singleton) return -1;
2908
17
    state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
2909
17
        "unaryop = Invert | Not | UAdd | USub");
2910
17
    if (!state->unaryop_type) return -1;
2911
17
    if (add_attributes(state, state->unaryop_type, NULL, 0) < 0) return -1;
2912
17
    if (PySet_Add(state->abstract_types, state->unaryop_type) < 0) return -1;
2913
17
    state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
2914
17
                                   0,
2915
17
        "Invert");
2916
17
    if (!state->Invert_type) return -1;
2917
17
    state->Invert_singleton = PyType_GenericNew((PyTypeObject
2918
17
                                                *)state->Invert_type, NULL,
2919
17
                                                NULL);
2920
17
    if (!state->Invert_singleton) return -1;
2921
17
    state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
2922
17
        "Not");
2923
17
    if (!state->Not_type) return -1;
2924
17
    state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
2925
17
                                             NULL, NULL);
2926
17
    if (!state->Not_singleton) return -1;
2927
17
    state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
2928
17
        "UAdd");
2929
17
    if (!state->UAdd_type) return -1;
2930
17
    state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
2931
17
                                              NULL, NULL);
2932
17
    if (!state->UAdd_singleton) return -1;
2933
17
    state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
2934
17
        "USub");
2935
17
    if (!state->USub_type) return -1;
2936
17
    state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
2937
17
                                              NULL, NULL);
2938
17
    if (!state->USub_singleton) return -1;
2939
17
    state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
2940
17
        "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
2941
17
    if (!state->cmpop_type) return -1;
2942
17
    if (add_attributes(state, state->cmpop_type, NULL, 0) < 0) return -1;
2943
17
    if (PySet_Add(state->abstract_types, state->cmpop_type) < 0) return -1;
2944
17
    state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
2945
17
        "Eq");
2946
17
    if (!state->Eq_type) return -1;
2947
17
    state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
2948
17
                                            NULL, NULL);
2949
17
    if (!state->Eq_singleton) return -1;
2950
17
    state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
2951
17
        "NotEq");
2952
17
    if (!state->NotEq_type) return -1;
2953
17
    state->NotEq_singleton = PyType_GenericNew((PyTypeObject
2954
17
                                               *)state->NotEq_type, NULL, NULL);
2955
17
    if (!state->NotEq_singleton) return -1;
2956
17
    state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
2957
17
        "Lt");
2958
17
    if (!state->Lt_type) return -1;
2959
17
    state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
2960
17
                                            NULL, NULL);
2961
17
    if (!state->Lt_singleton) return -1;
2962
17
    state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
2963
17
        "LtE");
2964
17
    if (!state->LtE_type) return -1;
2965
17
    state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
2966
17
                                             NULL, NULL);
2967
17
    if (!state->LtE_singleton) return -1;
2968
17
    state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
2969
17
        "Gt");
2970
17
    if (!state->Gt_type) return -1;
2971
17
    state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
2972
17
                                            NULL, NULL);
2973
17
    if (!state->Gt_singleton) return -1;
2974
17
    state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
2975
17
        "GtE");
2976
17
    if (!state->GtE_type) return -1;
2977
17
    state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
2978
17
                                             NULL, NULL);
2979
17
    if (!state->GtE_singleton) return -1;
2980
17
    state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
2981
17
        "Is");
2982
17
    if (!state->Is_type) return -1;
2983
17
    state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
2984
17
                                            NULL, NULL);
2985
17
    if (!state->Is_singleton) return -1;
2986
17
    state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
2987
17
        "IsNot");
2988
17
    if (!state->IsNot_type) return -1;
2989
17
    state->IsNot_singleton = PyType_GenericNew((PyTypeObject
2990
17
                                               *)state->IsNot_type, NULL, NULL);
2991
17
    if (!state->IsNot_singleton) return -1;
2992
17
    state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
2993
17
        "In");
2994
17
    if (!state->In_type) return -1;
2995
17
    state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
2996
17
                                            NULL, NULL);
2997
17
    if (!state->In_singleton) return -1;
2998
17
    state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
2999
17
        "NotIn");
3000
17
    if (!state->NotIn_type) return -1;
3001
17
    state->NotIn_singleton = PyType_GenericNew((PyTypeObject
3002
17
                                               *)state->NotIn_type, NULL, NULL);
3003
17
    if (!state->NotIn_singleton) return -1;
3004
17
    state->comprehension_type = make_type(state, "comprehension",
3005
17
                                          state->AST_type,
3006
17
                                          comprehension_fields, 4,
3007
17
        "comprehension(expr target, expr iter, expr* ifs, int is_async)");
3008
17
    if (!state->comprehension_type) return -1;
3009
17
    if (add_attributes(state, state->comprehension_type, NULL, 0) < 0) return
3010
0
        -1;
3011
17
    state->excepthandler_type = make_type(state, "excepthandler",
3012
17
                                          state->AST_type, NULL, 0,
3013
17
        "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
3014
17
    if (!state->excepthandler_type) return -1;
3015
17
    if (add_attributes(state, state->excepthandler_type,
3016
17
        excepthandler_attributes, 4) < 0) return -1;
3017
17
    if (PySet_Add(state->abstract_types, state->excepthandler_type) < 0) return
3018
0
        -1;
3019
17
    if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
3020
17
        == -1)
3021
0
        return -1;
3022
17
    if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
3023
17
        Py_None) == -1)
3024
0
        return -1;
3025
17
    state->ExceptHandler_type = make_type(state, "ExceptHandler",
3026
17
                                          state->excepthandler_type,
3027
17
                                          ExceptHandler_fields, 3,
3028
17
        "ExceptHandler(expr? type, identifier? name, stmt* body)");
3029
17
    if (!state->ExceptHandler_type) return -1;
3030
17
    if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
3031
0
        return -1;
3032
17
    if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
3033
0
        return -1;
3034
17
    state->arguments_type = make_type(state, "arguments", state->AST_type,
3035
17
                                      arguments_fields, 7,
3036
17
        "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr?* kw_defaults, arg? kwarg, expr* defaults)");
3037
17
    if (!state->arguments_type) return -1;
3038
17
    if (add_attributes(state, state->arguments_type, NULL, 0) < 0) return -1;
3039
17
    if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
3040
0
        return -1;
3041
17
    if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
3042
0
        return -1;
3043
17
    state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
3044
17
        "arg(identifier arg, expr? annotation, string? type_comment)");
3045
17
    if (!state->arg_type) return -1;
3046
17
    if (add_attributes(state, state->arg_type, arg_attributes, 4) < 0) return
3047
0
        -1;
3048
17
    if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
3049
0
        return -1;
3050
17
    if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
3051
0
        return -1;
3052
17
    if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
3053
0
        return -1;
3054
17
    if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
3055
0
        return -1;
3056
17
    state->keyword_type = make_type(state, "keyword", state->AST_type,
3057
17
                                    keyword_fields, 2,
3058
17
        "keyword(identifier? arg, expr value)");
3059
17
    if (!state->keyword_type) return -1;
3060
17
    if (add_attributes(state, state->keyword_type, keyword_attributes, 4) < 0)
3061
0
        return -1;
3062
17
    if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
3063
0
        return -1;
3064
17
    if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
3065
0
        return -1;
3066
17
    if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
3067
17
        == -1)
3068
0
        return -1;
3069
17
    state->alias_type = make_type(state, "alias", state->AST_type,
3070
17
                                  alias_fields, 2,
3071
17
        "alias(identifier name, identifier? asname)");
3072
17
    if (!state->alias_type) return -1;
3073
17
    if (add_attributes(state, state->alias_type, alias_attributes, 4) < 0)
3074
0
        return -1;
3075
17
    if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
3076
0
        return -1;
3077
17
    if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
3078
0
        return -1;
3079
17
    if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
3080
17
        -1)
3081
0
        return -1;
3082
17
    state->withitem_type = make_type(state, "withitem", state->AST_type,
3083
17
                                     withitem_fields, 2,
3084
17
        "withitem(expr context_expr, expr? optional_vars)");
3085
17
    if (!state->withitem_type) return -1;
3086
17
    if (add_attributes(state, state->withitem_type, NULL, 0) < 0) return -1;
3087
17
    if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
3088
17
        == -1)
3089
0
        return -1;
3090
17
    state->match_case_type = make_type(state, "match_case", state->AST_type,
3091
17
                                       match_case_fields, 3,
3092
17
        "match_case(pattern pattern, expr? guard, stmt* body)");
3093
17
    if (!state->match_case_type) return -1;
3094
17
    if (add_attributes(state, state->match_case_type, NULL, 0) < 0) return -1;
3095
17
    if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
3096
0
        return -1;
3097
17
    state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
3098
17
        "pattern = MatchValue(expr value)\n"
3099
17
        "        | MatchSingleton(constant value)\n"
3100
17
        "        | MatchSequence(pattern* patterns)\n"
3101
17
        "        | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
3102
17
        "        | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
3103
17
        "        | MatchStar(identifier? name)\n"
3104
17
        "        | MatchAs(pattern? pattern, identifier? name)\n"
3105
17
        "        | MatchOr(pattern* patterns)");
3106
17
    if (!state->pattern_type) return -1;
3107
17
    if (add_attributes(state, state->pattern_type, pattern_attributes, 4) < 0)
3108
0
        return -1;
3109
17
    if (PySet_Add(state->abstract_types, state->pattern_type) < 0) return -1;
3110
17
    state->MatchValue_type = make_type(state, "MatchValue",
3111
17
                                       state->pattern_type, MatchValue_fields,
3112
17
                                       1,
3113
17
        "MatchValue(expr value)");
3114
17
    if (!state->MatchValue_type) return -1;
3115
17
    state->MatchSingleton_type = make_type(state, "MatchSingleton",
3116
17
                                           state->pattern_type,
3117
17
                                           MatchSingleton_fields, 1,
3118
17
        "MatchSingleton(constant value)");
3119
17
    if (!state->MatchSingleton_type) return -1;
3120
17
    state->MatchSequence_type = make_type(state, "MatchSequence",
3121
17
                                          state->pattern_type,
3122
17
                                          MatchSequence_fields, 1,
3123
17
        "MatchSequence(pattern* patterns)");
3124
17
    if (!state->MatchSequence_type) return -1;
3125
17
    state->MatchMapping_type = make_type(state, "MatchMapping",
3126
17
                                         state->pattern_type,
3127
17
                                         MatchMapping_fields, 3,
3128
17
        "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
3129
17
    if (!state->MatchMapping_type) return -1;
3130
17
    if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
3131
0
        return -1;
3132
17
    state->MatchClass_type = make_type(state, "MatchClass",
3133
17
                                       state->pattern_type, MatchClass_fields,
3134
17
                                       4,
3135
17
        "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
3136
17
    if (!state->MatchClass_type) return -1;
3137
17
    state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
3138
17
                                      MatchStar_fields, 1,
3139
17
        "MatchStar(identifier? name)");
3140
17
    if (!state->MatchStar_type) return -1;
3141
17
    if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
3142
0
        return -1;
3143
17
    state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
3144
17
                                    MatchAs_fields, 2,
3145
17
        "MatchAs(pattern? pattern, identifier? name)");
3146
17
    if (!state->MatchAs_type) return -1;
3147
17
    if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
3148
0
        return -1;
3149
17
    if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
3150
0
        return -1;
3151
17
    state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
3152
17
                                    MatchOr_fields, 1,
3153
17
        "MatchOr(pattern* patterns)");
3154
17
    if (!state->MatchOr_type) return -1;
3155
17
    state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
3156
17
                                        NULL, 0,
3157
17
        "type_ignore = TypeIgnore(int lineno, string tag)");
3158
17
    if (!state->type_ignore_type) return -1;
3159
17
    if (add_attributes(state, state->type_ignore_type, NULL, 0) < 0) return -1;
3160
17
    if (PySet_Add(state->abstract_types, state->type_ignore_type) < 0) return
3161
0
        -1;
3162
17
    state->TypeIgnore_type = make_type(state, "TypeIgnore",
3163
17
                                       state->type_ignore_type,
3164
17
                                       TypeIgnore_fields, 2,
3165
17
        "TypeIgnore(int lineno, string tag)");
3166
17
    if (!state->TypeIgnore_type) return -1;
3167
17
    state->type_param_type = make_type(state, "type_param", state->AST_type,
3168
17
                                       NULL, 0,
3169
17
        "type_param = TypeVar(identifier name, expr? bound, expr? default_value)\n"
3170
17
        "           | ParamSpec(identifier name, expr? default_value)\n"
3171
17
        "           | TypeVarTuple(identifier name, expr? default_value)");
3172
17
    if (!state->type_param_type) return -1;
3173
17
    if (add_attributes(state, state->type_param_type, type_param_attributes, 4)
3174
17
        < 0) return -1;
3175
17
    if (PySet_Add(state->abstract_types, state->type_param_type) < 0) return -1;
3176
17
    state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
3177
17
                                    TypeVar_fields, 3,
3178
17
        "TypeVar(identifier name, expr? bound, expr? default_value)");
3179
17
    if (!state->TypeVar_type) return -1;
3180
17
    if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
3181
0
        return -1;
3182
17
    if (PyObject_SetAttr(state->TypeVar_type, state->default_value, Py_None) ==
3183
17
        -1)
3184
0
        return -1;
3185
17
    state->ParamSpec_type = make_type(state, "ParamSpec",
3186
17
                                      state->type_param_type, ParamSpec_fields,
3187
17
                                      2,
3188
17
        "ParamSpec(identifier name, expr? default_value)");
3189
17
    if (!state->ParamSpec_type) return -1;
3190
17
    if (PyObject_SetAttr(state->ParamSpec_type, state->default_value, Py_None)
3191
17
        == -1)
3192
0
        return -1;
3193
17
    state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
3194
17
                                         state->type_param_type,
3195
17
                                         TypeVarTuple_fields, 2,
3196
17
        "TypeVarTuple(identifier name, expr? default_value)");
3197
17
    if (!state->TypeVarTuple_type) return -1;
3198
17
    if (PyObject_SetAttr(state->TypeVarTuple_type, state->default_value,
3199
17
        Py_None) == -1)
3200
0
        return -1;
3201
3202
17
    if (!add_ast_annotations(state)) {
3203
0
        return -1;
3204
0
    }
3205
17
    return 0;
3206
17
}
3207
3208
static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
3209
                       const char* field, PyArena* arena);
3210
static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
3211
                        const char* field, PyArena* arena);
3212
static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
3213
                        const char* field, PyArena* arena);
3214
static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
3215
                                expr_context_ty* out, const char* field,
3216
                                PyArena* arena);
3217
static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
3218
                          out, const char* field, PyArena* arena);
3219
static int obj2ast_operator(struct ast_state *state, PyObject* obj,
3220
                            operator_ty* out, const char* field, PyArena*
3221
                            arena);
3222
static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
3223
                           out, const char* field, PyArena* arena);
3224
static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
3225
                         const char* field, PyArena* arena);
3226
static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
3227
                                 comprehension_ty* out, const char* field,
3228
                                 PyArena* arena);
3229
static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
3230
                                 excepthandler_ty* out, const char* field,
3231
                                 PyArena* arena);
3232
static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
3233
                             arguments_ty* out, const char* field, PyArena*
3234
                             arena);
3235
static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
3236
                       const char* field, PyArena* arena);
3237
static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
3238
                           out, const char* field, PyArena* arena);
3239
static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
3240
                         const char* field, PyArena* arena);
3241
static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
3242
                            withitem_ty* out, const char* field, PyArena*
3243
                            arena);
3244
static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
3245
                              match_case_ty* out, const char* field, PyArena*
3246
                              arena);
3247
static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
3248
                           out, const char* field, PyArena* arena);
3249
static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
3250
                               type_ignore_ty* out, const char* field, PyArena*
3251
                               arena);
3252
static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
3253
                              type_param_ty* out, const char* field, PyArena*
3254
                              arena);
3255
3256
mod_ty
3257
_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
3258
              PyArena *arena)
3259
8.03k
{
3260
8.03k
    mod_ty p;
3261
8.03k
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3262
8.03k
    if (!p)
3263
0
        return NULL;
3264
8.03k
    p->kind = Module_kind;
3265
8.03k
    p->v.Module.body = body;
3266
8.03k
    p->v.Module.type_ignores = type_ignores;
3267
8.03k
    return p;
3268
8.03k
}
3269
3270
mod_ty
3271
_PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
3272
0
{
3273
0
    mod_ty p;
3274
0
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3275
0
    if (!p)
3276
0
        return NULL;
3277
0
    p->kind = Interactive_kind;
3278
0
    p->v.Interactive.body = body;
3279
0
    return p;
3280
0
}
3281
3282
mod_ty
3283
_PyAST_Expression(expr_ty body, PyArena *arena)
3284
196
{
3285
196
    mod_ty p;
3286
196
    if (!body) {
3287
0
        PyErr_SetString(PyExc_ValueError,
3288
0
                        "field 'body' is required for Expression");
3289
0
        return NULL;
3290
0
    }
3291
196
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3292
196
    if (!p)
3293
0
        return NULL;
3294
196
    p->kind = Expression_kind;
3295
196
    p->v.Expression.body = body;
3296
196
    return p;
3297
196
}
3298
3299
mod_ty
3300
_PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
3301
0
{
3302
0
    mod_ty p;
3303
0
    if (!returns) {
3304
0
        PyErr_SetString(PyExc_ValueError,
3305
0
                        "field 'returns' is required for FunctionType");
3306
0
        return NULL;
3307
0
    }
3308
0
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3309
0
    if (!p)
3310
0
        return NULL;
3311
0
    p->kind = FunctionType_kind;
3312
0
    p->v.FunctionType.argtypes = argtypes;
3313
0
    p->v.FunctionType.returns = returns;
3314
0
    return p;
3315
0
}
3316
3317
stmt_ty
3318
_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
3319
                   asdl_expr_seq * decorator_list, expr_ty returns, string
3320
                   type_comment, asdl_type_param_seq * type_params, int lineno,
3321
                   int col_offset, int end_lineno, int end_col_offset, PyArena
3322
                   *arena)
3323
6.69k
{
3324
6.69k
    stmt_ty p;
3325
6.69k
    if (!name) {
3326
0
        PyErr_SetString(PyExc_ValueError,
3327
0
                        "field 'name' is required for FunctionDef");
3328
0
        return NULL;
3329
0
    }
3330
6.69k
    if (!args) {
3331
0
        PyErr_SetString(PyExc_ValueError,
3332
0
                        "field 'args' is required for FunctionDef");
3333
0
        return NULL;
3334
0
    }
3335
6.69k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3336
6.69k
    if (!p)
3337
0
        return NULL;
3338
6.69k
    p->kind = FunctionDef_kind;
3339
6.69k
    p->v.FunctionDef.name = name;
3340
6.69k
    p->v.FunctionDef.args = args;
3341
6.69k
    p->v.FunctionDef.body = body;
3342
6.69k
    p->v.FunctionDef.decorator_list = decorator_list;
3343
6.69k
    p->v.FunctionDef.returns = returns;
3344
6.69k
    p->v.FunctionDef.type_comment = type_comment;
3345
6.69k
    p->v.FunctionDef.type_params = type_params;
3346
6.69k
    p->lineno = lineno;
3347
6.69k
    p->col_offset = col_offset;
3348
6.69k
    p->end_lineno = end_lineno;
3349
6.69k
    p->end_col_offset = end_col_offset;
3350
6.69k
    return p;
3351
6.69k
}
3352
3353
stmt_ty
3354
_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
3355
                        body, asdl_expr_seq * decorator_list, expr_ty returns,
3356
                        string type_comment, asdl_type_param_seq * type_params,
3357
                        int lineno, int col_offset, int end_lineno, int
3358
                        end_col_offset, PyArena *arena)
3359
1.10k
{
3360
1.10k
    stmt_ty p;
3361
1.10k
    if (!name) {
3362
0
        PyErr_SetString(PyExc_ValueError,
3363
0
                        "field 'name' is required for AsyncFunctionDef");
3364
0
        return NULL;
3365
0
    }
3366
1.10k
    if (!args) {
3367
0
        PyErr_SetString(PyExc_ValueError,
3368
0
                        "field 'args' is required for AsyncFunctionDef");
3369
0
        return NULL;
3370
0
    }
3371
1.10k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3372
1.10k
    if (!p)
3373
0
        return NULL;
3374
1.10k
    p->kind = AsyncFunctionDef_kind;
3375
1.10k
    p->v.AsyncFunctionDef.name = name;
3376
1.10k
    p->v.AsyncFunctionDef.args = args;
3377
1.10k
    p->v.AsyncFunctionDef.body = body;
3378
1.10k
    p->v.AsyncFunctionDef.decorator_list = decorator_list;
3379
1.10k
    p->v.AsyncFunctionDef.returns = returns;
3380
1.10k
    p->v.AsyncFunctionDef.type_comment = type_comment;
3381
1.10k
    p->v.AsyncFunctionDef.type_params = type_params;
3382
1.10k
    p->lineno = lineno;
3383
1.10k
    p->col_offset = col_offset;
3384
1.10k
    p->end_lineno = end_lineno;
3385
1.10k
    p->end_col_offset = end_col_offset;
3386
1.10k
    return p;
3387
1.10k
}
3388
3389
stmt_ty
3390
_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
3391
                keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
3392
                asdl_type_param_seq * type_params, int lineno, int col_offset,
3393
                int end_lineno, int end_col_offset, PyArena *arena)
3394
3.15k
{
3395
3.15k
    stmt_ty p;
3396
3.15k
    if (!name) {
3397
0
        PyErr_SetString(PyExc_ValueError,
3398
0
                        "field 'name' is required for ClassDef");
3399
0
        return NULL;
3400
0
    }
3401
3.15k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3402
3.15k
    if (!p)
3403
0
        return NULL;
3404
3.15k
    p->kind = ClassDef_kind;
3405
3.15k
    p->v.ClassDef.name = name;
3406
3.15k
    p->v.ClassDef.bases = bases;
3407
3.15k
    p->v.ClassDef.keywords = keywords;
3408
3.15k
    p->v.ClassDef.body = body;
3409
3.15k
    p->v.ClassDef.decorator_list = decorator_list;
3410
3.15k
    p->v.ClassDef.type_params = type_params;
3411
3.15k
    p->lineno = lineno;
3412
3.15k
    p->col_offset = col_offset;
3413
3.15k
    p->end_lineno = end_lineno;
3414
3.15k
    p->end_col_offset = end_col_offset;
3415
3.15k
    return p;
3416
3.15k
}
3417
3418
stmt_ty
3419
_PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
3420
              end_col_offset, PyArena *arena)
3421
2.97k
{
3422
2.97k
    stmt_ty p;
3423
2.97k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3424
2.97k
    if (!p)
3425
0
        return NULL;
3426
2.97k
    p->kind = Return_kind;
3427
2.97k
    p->v.Return.value = value;
3428
2.97k
    p->lineno = lineno;
3429
2.97k
    p->col_offset = col_offset;
3430
2.97k
    p->end_lineno = end_lineno;
3431
2.97k
    p->end_col_offset = end_col_offset;
3432
2.97k
    return p;
3433
2.97k
}
3434
3435
stmt_ty
3436
_PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
3437
              end_lineno, int end_col_offset, PyArena *arena)
3438
627
{
3439
627
    stmt_ty p;
3440
627
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3441
627
    if (!p)
3442
0
        return NULL;
3443
627
    p->kind = Delete_kind;
3444
627
    p->v.Delete.targets = targets;
3445
627
    p->lineno = lineno;
3446
627
    p->col_offset = col_offset;
3447
627
    p->end_lineno = end_lineno;
3448
627
    p->end_col_offset = end_col_offset;
3449
627
    return p;
3450
627
}
3451
3452
stmt_ty
3453
_PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
3454
              lineno, int col_offset, int end_lineno, int end_col_offset,
3455
              PyArena *arena)
3456
4.54k
{
3457
4.54k
    stmt_ty p;
3458
4.54k
    if (!value) {
3459
0
        PyErr_SetString(PyExc_ValueError,
3460
0
                        "field 'value' is required for Assign");
3461
0
        return NULL;
3462
0
    }
3463
4.54k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3464
4.54k
    if (!p)
3465
0
        return NULL;
3466
4.54k
    p->kind = Assign_kind;
3467
4.54k
    p->v.Assign.targets = targets;
3468
4.54k
    p->v.Assign.value = value;
3469
4.54k
    p->v.Assign.type_comment = type_comment;
3470
4.54k
    p->lineno = lineno;
3471
4.54k
    p->col_offset = col_offset;
3472
4.54k
    p->end_lineno = end_lineno;
3473
4.54k
    p->end_col_offset = end_col_offset;
3474
4.54k
    return p;
3475
4.54k
}
3476
3477
stmt_ty
3478
_PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
3479
                 value, int lineno, int col_offset, int end_lineno, int
3480
                 end_col_offset, PyArena *arena)
3481
401
{
3482
401
    stmt_ty p;
3483
401
    if (!name) {
3484
0
        PyErr_SetString(PyExc_ValueError,
3485
0
                        "field 'name' is required for TypeAlias");
3486
0
        return NULL;
3487
0
    }
3488
401
    if (!value) {
3489
0
        PyErr_SetString(PyExc_ValueError,
3490
0
                        "field 'value' is required for TypeAlias");
3491
0
        return NULL;
3492
0
    }
3493
401
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3494
401
    if (!p)
3495
0
        return NULL;
3496
401
    p->kind = TypeAlias_kind;
3497
401
    p->v.TypeAlias.name = name;
3498
401
    p->v.TypeAlias.type_params = type_params;
3499
401
    p->v.TypeAlias.value = value;
3500
401
    p->lineno = lineno;
3501
401
    p->col_offset = col_offset;
3502
401
    p->end_lineno = end_lineno;
3503
401
    p->end_col_offset = end_col_offset;
3504
401
    return p;
3505
401
}
3506
3507
stmt_ty
3508
_PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
3509
                 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3510
2.31k
{
3511
2.31k
    stmt_ty p;
3512
2.31k
    if (!target) {
3513
0
        PyErr_SetString(PyExc_ValueError,
3514
0
                        "field 'target' is required for AugAssign");
3515
0
        return NULL;
3516
0
    }
3517
2.31k
    if (!op) {
3518
0
        PyErr_SetString(PyExc_ValueError,
3519
0
                        "field 'op' is required for AugAssign");
3520
0
        return NULL;
3521
0
    }
3522
2.31k
    if (!value) {
3523
0
        PyErr_SetString(PyExc_ValueError,
3524
0
                        "field 'value' is required for AugAssign");
3525
0
        return NULL;
3526
0
    }
3527
2.31k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3528
2.31k
    if (!p)
3529
0
        return NULL;
3530
2.31k
    p->kind = AugAssign_kind;
3531
2.31k
    p->v.AugAssign.target = target;
3532
2.31k
    p->v.AugAssign.op = op;
3533
2.31k
    p->v.AugAssign.value = value;
3534
2.31k
    p->lineno = lineno;
3535
2.31k
    p->col_offset = col_offset;
3536
2.31k
    p->end_lineno = end_lineno;
3537
2.31k
    p->end_col_offset = end_col_offset;
3538
2.31k
    return p;
3539
2.31k
}
3540
3541
stmt_ty
3542
_PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
3543
                 int lineno, int col_offset, int end_lineno, int
3544
                 end_col_offset, PyArena *arena)
3545
3.28k
{
3546
3.28k
    stmt_ty p;
3547
3.28k
    if (!target) {
3548
0
        PyErr_SetString(PyExc_ValueError,
3549
0
                        "field 'target' is required for AnnAssign");
3550
0
        return NULL;
3551
0
    }
3552
3.28k
    if (!annotation) {
3553
0
        PyErr_SetString(PyExc_ValueError,
3554
0
                        "field 'annotation' is required for AnnAssign");
3555
0
        return NULL;
3556
0
    }
3557
3.28k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3558
3.28k
    if (!p)
3559
0
        return NULL;
3560
3.28k
    p->kind = AnnAssign_kind;
3561
3.28k
    p->v.AnnAssign.target = target;
3562
3.28k
    p->v.AnnAssign.annotation = annotation;
3563
3.28k
    p->v.AnnAssign.value = value;
3564
3.28k
    p->v.AnnAssign.simple = simple;
3565
3.28k
    p->lineno = lineno;
3566
3.28k
    p->col_offset = col_offset;
3567
3.28k
    p->end_lineno = end_lineno;
3568
3.28k
    p->end_col_offset = end_col_offset;
3569
3.28k
    return p;
3570
3.28k
}
3571
3572
stmt_ty
3573
_PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
3574
           orelse, string type_comment, int lineno, int col_offset, int
3575
           end_lineno, int end_col_offset, PyArena *arena)
3576
1.03k
{
3577
1.03k
    stmt_ty p;
3578
1.03k
    if (!target) {
3579
0
        PyErr_SetString(PyExc_ValueError,
3580
0
                        "field 'target' is required for For");
3581
0
        return NULL;
3582
0
    }
3583
1.03k
    if (!iter) {
3584
0
        PyErr_SetString(PyExc_ValueError,
3585
0
                        "field 'iter' is required for For");
3586
0
        return NULL;
3587
0
    }
3588
1.03k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3589
1.03k
    if (!p)
3590
0
        return NULL;
3591
1.03k
    p->kind = For_kind;
3592
1.03k
    p->v.For.target = target;
3593
1.03k
    p->v.For.iter = iter;
3594
1.03k
    p->v.For.body = body;
3595
1.03k
    p->v.For.orelse = orelse;
3596
1.03k
    p->v.For.type_comment = type_comment;
3597
1.03k
    p->lineno = lineno;
3598
1.03k
    p->col_offset = col_offset;
3599
1.03k
    p->end_lineno = end_lineno;
3600
1.03k
    p->end_col_offset = end_col_offset;
3601
1.03k
    return p;
3602
1.03k
}
3603
3604
stmt_ty
3605
_PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
3606
                asdl_stmt_seq * orelse, string type_comment, int lineno, int
3607
                col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3608
229
{
3609
229
    stmt_ty p;
3610
229
    if (!target) {
3611
0
        PyErr_SetString(PyExc_ValueError,
3612
0
                        "field 'target' is required for AsyncFor");
3613
0
        return NULL;
3614
0
    }
3615
229
    if (!iter) {
3616
0
        PyErr_SetString(PyExc_ValueError,
3617
0
                        "field 'iter' is required for AsyncFor");
3618
0
        return NULL;
3619
0
    }
3620
229
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3621
229
    if (!p)
3622
0
        return NULL;
3623
229
    p->kind = AsyncFor_kind;
3624
229
    p->v.AsyncFor.target = target;
3625
229
    p->v.AsyncFor.iter = iter;
3626
229
    p->v.AsyncFor.body = body;
3627
229
    p->v.AsyncFor.orelse = orelse;
3628
229
    p->v.AsyncFor.type_comment = type_comment;
3629
229
    p->lineno = lineno;
3630
229
    p->col_offset = col_offset;
3631
229
    p->end_lineno = end_lineno;
3632
229
    p->end_col_offset = end_col_offset;
3633
229
    return p;
3634
229
}
3635
3636
stmt_ty
3637
_PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
3638
             lineno, int col_offset, int end_lineno, int end_col_offset,
3639
             PyArena *arena)
3640
972
{
3641
972
    stmt_ty p;
3642
972
    if (!test) {
3643
0
        PyErr_SetString(PyExc_ValueError,
3644
0
                        "field 'test' is required for While");
3645
0
        return NULL;
3646
0
    }
3647
972
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3648
972
    if (!p)
3649
0
        return NULL;
3650
972
    p->kind = While_kind;
3651
972
    p->v.While.test = test;
3652
972
    p->v.While.body = body;
3653
972
    p->v.While.orelse = orelse;
3654
972
    p->lineno = lineno;
3655
972
    p->col_offset = col_offset;
3656
972
    p->end_lineno = end_lineno;
3657
972
    p->end_col_offset = end_col_offset;
3658
972
    return p;
3659
972
}
3660
3661
stmt_ty
3662
_PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
3663
          lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
3664
          *arena)
3665
3.96k
{
3666
3.96k
    stmt_ty p;
3667
3.96k
    if (!test) {
3668
0
        PyErr_SetString(PyExc_ValueError,
3669
0
                        "field 'test' is required for If");
3670
0
        return NULL;
3671
0
    }
3672
3.96k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3673
3.96k
    if (!p)
3674
0
        return NULL;
3675
3.96k
    p->kind = If_kind;
3676
3.96k
    p->v.If.test = test;
3677
3.96k
    p->v.If.body = body;
3678
3.96k
    p->v.If.orelse = orelse;
3679
3.96k
    p->lineno = lineno;
3680
3.96k
    p->col_offset = col_offset;
3681
3.96k
    p->end_lineno = end_lineno;
3682
3.96k
    p->end_col_offset = end_col_offset;
3683
3.96k
    return p;
3684
3.96k
}
3685
3686
stmt_ty
3687
_PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
3688
            type_comment, int lineno, int col_offset, int end_lineno, int
3689
            end_col_offset, PyArena *arena)
3690
3.46k
{
3691
3.46k
    stmt_ty p;
3692
3.46k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3693
3.46k
    if (!p)
3694
0
        return NULL;
3695
3.46k
    p->kind = With_kind;
3696
3.46k
    p->v.With.items = items;
3697
3.46k
    p->v.With.body = body;
3698
3.46k
    p->v.With.type_comment = type_comment;
3699
3.46k
    p->lineno = lineno;
3700
3.46k
    p->col_offset = col_offset;
3701
3.46k
    p->end_lineno = end_lineno;
3702
3.46k
    p->end_col_offset = end_col_offset;
3703
3.46k
    return p;
3704
3.46k
}
3705
3706
stmt_ty
3707
_PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
3708
                 type_comment, int lineno, int col_offset, int end_lineno, int
3709
                 end_col_offset, PyArena *arena)
3710
632
{
3711
632
    stmt_ty p;
3712
632
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3713
632
    if (!p)
3714
0
        return NULL;
3715
632
    p->kind = AsyncWith_kind;
3716
632
    p->v.AsyncWith.items = items;
3717
632
    p->v.AsyncWith.body = body;
3718
632
    p->v.AsyncWith.type_comment = type_comment;
3719
632
    p->lineno = lineno;
3720
632
    p->col_offset = col_offset;
3721
632
    p->end_lineno = end_lineno;
3722
632
    p->end_col_offset = end_col_offset;
3723
632
    return p;
3724
632
}
3725
3726
stmt_ty
3727
_PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
3728
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3729
761
{
3730
761
    stmt_ty p;
3731
761
    if (!subject) {
3732
0
        PyErr_SetString(PyExc_ValueError,
3733
0
                        "field 'subject' is required for Match");
3734
0
        return NULL;
3735
0
    }
3736
761
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3737
761
    if (!p)
3738
0
        return NULL;
3739
761
    p->kind = Match_kind;
3740
761
    p->v.Match.subject = subject;
3741
761
    p->v.Match.cases = cases;
3742
761
    p->lineno = lineno;
3743
761
    p->col_offset = col_offset;
3744
761
    p->end_lineno = end_lineno;
3745
761
    p->end_col_offset = end_col_offset;
3746
761
    return p;
3747
761
}
3748
3749
stmt_ty
3750
_PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
3751
             end_lineno, int end_col_offset, PyArena *arena)
3752
2.21k
{
3753
2.21k
    stmt_ty p;
3754
2.21k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3755
2.21k
    if (!p)
3756
0
        return NULL;
3757
2.21k
    p->kind = Raise_kind;
3758
2.21k
    p->v.Raise.exc = exc;
3759
2.21k
    p->v.Raise.cause = cause;
3760
2.21k
    p->lineno = lineno;
3761
2.21k
    p->col_offset = col_offset;
3762
2.21k
    p->end_lineno = end_lineno;
3763
2.21k
    p->end_col_offset = end_col_offset;
3764
2.21k
    return p;
3765
2.21k
}
3766
3767
stmt_ty
3768
_PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
3769
           asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
3770
           col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3771
3.06k
{
3772
3.06k
    stmt_ty p;
3773
3.06k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3774
3.06k
    if (!p)
3775
0
        return NULL;
3776
3.06k
    p->kind = Try_kind;
3777
3.06k
    p->v.Try.body = body;
3778
3.06k
    p->v.Try.handlers = handlers;
3779
3.06k
    p->v.Try.orelse = orelse;
3780
3.06k
    p->v.Try.finalbody = finalbody;
3781
3.06k
    p->lineno = lineno;
3782
3.06k
    p->col_offset = col_offset;
3783
3.06k
    p->end_lineno = end_lineno;
3784
3.06k
    p->end_col_offset = end_col_offset;
3785
3.06k
    return p;
3786
3.06k
}
3787
3788
stmt_ty
3789
_PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
3790
               asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
3791
               int col_offset, int end_lineno, int end_col_offset, PyArena
3792
               *arena)
3793
1.31k
{
3794
1.31k
    stmt_ty p;
3795
1.31k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3796
1.31k
    if (!p)
3797
0
        return NULL;
3798
1.31k
    p->kind = TryStar_kind;
3799
1.31k
    p->v.TryStar.body = body;
3800
1.31k
    p->v.TryStar.handlers = handlers;
3801
1.31k
    p->v.TryStar.orelse = orelse;
3802
1.31k
    p->v.TryStar.finalbody = finalbody;
3803
1.31k
    p->lineno = lineno;
3804
1.31k
    p->col_offset = col_offset;
3805
1.31k
    p->end_lineno = end_lineno;
3806
1.31k
    p->end_col_offset = end_col_offset;
3807
1.31k
    return p;
3808
1.31k
}
3809
3810
stmt_ty
3811
_PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
3812
              end_lineno, int end_col_offset, PyArena *arena)
3813
1.14k
{
3814
1.14k
    stmt_ty p;
3815
1.14k
    if (!test) {
3816
0
        PyErr_SetString(PyExc_ValueError,
3817
0
                        "field 'test' is required for Assert");
3818
0
        return NULL;
3819
0
    }
3820
1.14k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3821
1.14k
    if (!p)
3822
0
        return NULL;
3823
1.14k
    p->kind = Assert_kind;
3824
1.14k
    p->v.Assert.test = test;
3825
1.14k
    p->v.Assert.msg = msg;
3826
1.14k
    p->lineno = lineno;
3827
1.14k
    p->col_offset = col_offset;
3828
1.14k
    p->end_lineno = end_lineno;
3829
1.14k
    p->end_col_offset = end_col_offset;
3830
1.14k
    return p;
3831
1.14k
}
3832
3833
stmt_ty
3834
_PyAST_Import(asdl_alias_seq * names, int is_lazy, int lineno, int col_offset,
3835
              int end_lineno, int end_col_offset, PyArena *arena)
3836
2.54k
{
3837
2.54k
    stmt_ty p;
3838
2.54k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3839
2.54k
    if (!p)
3840
0
        return NULL;
3841
2.54k
    p->kind = Import_kind;
3842
2.54k
    p->v.Import.names = names;
3843
2.54k
    p->v.Import.is_lazy = is_lazy;
3844
2.54k
    p->lineno = lineno;
3845
2.54k
    p->col_offset = col_offset;
3846
2.54k
    p->end_lineno = end_lineno;
3847
2.54k
    p->end_col_offset = end_col_offset;
3848
2.54k
    return p;
3849
2.54k
}
3850
3851
stmt_ty
3852
_PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
3853
                  is_lazy, int lineno, int col_offset, int end_lineno, int
3854
                  end_col_offset, PyArena *arena)
3855
5.53k
{
3856
5.53k
    stmt_ty p;
3857
5.53k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3858
5.53k
    if (!p)
3859
0
        return NULL;
3860
5.53k
    p->kind = ImportFrom_kind;
3861
5.53k
    p->v.ImportFrom.module = module;
3862
5.53k
    p->v.ImportFrom.names = names;
3863
5.53k
    p->v.ImportFrom.level = level;
3864
5.53k
    p->v.ImportFrom.is_lazy = is_lazy;
3865
5.53k
    p->lineno = lineno;
3866
5.53k
    p->col_offset = col_offset;
3867
5.53k
    p->end_lineno = end_lineno;
3868
5.53k
    p->end_col_offset = end_col_offset;
3869
5.53k
    return p;
3870
5.53k
}
3871
3872
stmt_ty
3873
_PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
3874
              end_lineno, int end_col_offset, PyArena *arena)
3875
830
{
3876
830
    stmt_ty p;
3877
830
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3878
830
    if (!p)
3879
0
        return NULL;
3880
830
    p->kind = Global_kind;
3881
830
    p->v.Global.names = names;
3882
830
    p->lineno = lineno;
3883
830
    p->col_offset = col_offset;
3884
830
    p->end_lineno = end_lineno;
3885
830
    p->end_col_offset = end_col_offset;
3886
830
    return p;
3887
830
}
3888
3889
stmt_ty
3890
_PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
3891
                end_lineno, int end_col_offset, PyArena *arena)
3892
379
{
3893
379
    stmt_ty p;
3894
379
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3895
379
    if (!p)
3896
0
        return NULL;
3897
379
    p->kind = Nonlocal_kind;
3898
379
    p->v.Nonlocal.names = names;
3899
379
    p->lineno = lineno;
3900
379
    p->col_offset = col_offset;
3901
379
    p->end_lineno = end_lineno;
3902
379
    p->end_col_offset = end_col_offset;
3903
379
    return p;
3904
379
}
3905
3906
stmt_ty
3907
_PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
3908
            end_col_offset, PyArena *arena)
3909
102k
{
3910
102k
    stmt_ty p;
3911
102k
    if (!value) {
3912
0
        PyErr_SetString(PyExc_ValueError,
3913
0
                        "field 'value' is required for Expr");
3914
0
        return NULL;
3915
0
    }
3916
102k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3917
102k
    if (!p)
3918
0
        return NULL;
3919
102k
    p->kind = Expr_kind;
3920
102k
    p->v.Expr.value = value;
3921
102k
    p->lineno = lineno;
3922
102k
    p->col_offset = col_offset;
3923
102k
    p->end_lineno = end_lineno;
3924
102k
    p->end_col_offset = end_col_offset;
3925
102k
    return p;
3926
102k
}
3927
3928
stmt_ty
3929
_PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
3930
            PyArena *arena)
3931
1.45k
{
3932
1.45k
    stmt_ty p;
3933
1.45k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3934
1.45k
    if (!p)
3935
0
        return NULL;
3936
1.45k
    p->kind = Pass_kind;
3937
1.45k
    p->lineno = lineno;
3938
1.45k
    p->col_offset = col_offset;
3939
1.45k
    p->end_lineno = end_lineno;
3940
1.45k
    p->end_col_offset = end_col_offset;
3941
1.45k
    return p;
3942
1.45k
}
3943
3944
stmt_ty
3945
_PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
3946
             PyArena *arena)
3947
1.40k
{
3948
1.40k
    stmt_ty p;
3949
1.40k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3950
1.40k
    if (!p)
3951
0
        return NULL;
3952
1.40k
    p->kind = Break_kind;
3953
1.40k
    p->lineno = lineno;
3954
1.40k
    p->col_offset = col_offset;
3955
1.40k
    p->end_lineno = end_lineno;
3956
1.40k
    p->end_col_offset = end_col_offset;
3957
1.40k
    return p;
3958
1.40k
}
3959
3960
stmt_ty
3961
_PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
3962
                PyArena *arena)
3963
3.50k
{
3964
3.50k
    stmt_ty p;
3965
3.50k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3966
3.50k
    if (!p)
3967
0
        return NULL;
3968
3.50k
    p->kind = Continue_kind;
3969
3.50k
    p->lineno = lineno;
3970
3.50k
    p->col_offset = col_offset;
3971
3.50k
    p->end_lineno = end_lineno;
3972
3.50k
    p->end_col_offset = end_col_offset;
3973
3.50k
    return p;
3974
3.50k
}
3975
3976
expr_ty
3977
_PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
3978
              int end_lineno, int end_col_offset, PyArena *arena)
3979
1.86k
{
3980
1.86k
    expr_ty p;
3981
1.86k
    if (!op) {
3982
0
        PyErr_SetString(PyExc_ValueError,
3983
0
                        "field 'op' is required for BoolOp");
3984
0
        return NULL;
3985
0
    }
3986
1.86k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3987
1.86k
    if (!p)
3988
0
        return NULL;
3989
1.86k
    p->kind = BoolOp_kind;
3990
1.86k
    p->v.BoolOp.op = op;
3991
1.86k
    p->v.BoolOp.values = values;
3992
1.86k
    p->lineno = lineno;
3993
1.86k
    p->col_offset = col_offset;
3994
1.86k
    p->end_lineno = end_lineno;
3995
1.86k
    p->end_col_offset = end_col_offset;
3996
1.86k
    return p;
3997
1.86k
}
3998
3999
expr_ty
4000
_PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
4001
                 end_lineno, int end_col_offset, PyArena *arena)
4002
1.81k
{
4003
1.81k
    expr_ty p;
4004
1.81k
    if (!target) {
4005
0
        PyErr_SetString(PyExc_ValueError,
4006
0
                        "field 'target' is required for NamedExpr");
4007
0
        return NULL;
4008
0
    }
4009
1.81k
    if (!value) {
4010
0
        PyErr_SetString(PyExc_ValueError,
4011
0
                        "field 'value' is required for NamedExpr");
4012
0
        return NULL;
4013
0
    }
4014
1.81k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4015
1.81k
    if (!p)
4016
0
        return NULL;
4017
1.81k
    p->kind = NamedExpr_kind;
4018
1.81k
    p->v.NamedExpr.target = target;
4019
1.81k
    p->v.NamedExpr.value = value;
4020
1.81k
    p->lineno = lineno;
4021
1.81k
    p->col_offset = col_offset;
4022
1.81k
    p->end_lineno = end_lineno;
4023
1.81k
    p->end_col_offset = end_col_offset;
4024
1.81k
    return p;
4025
1.81k
}
4026
4027
expr_ty
4028
_PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
4029
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4030
58.7k
{
4031
58.7k
    expr_ty p;
4032
58.7k
    if (!left) {
4033
0
        PyErr_SetString(PyExc_ValueError,
4034
0
                        "field 'left' is required for BinOp");
4035
0
        return NULL;
4036
0
    }
4037
58.7k
    if (!op) {
4038
0
        PyErr_SetString(PyExc_ValueError,
4039
0
                        "field 'op' is required for BinOp");
4040
0
        return NULL;
4041
0
    }
4042
58.7k
    if (!right) {
4043
0
        PyErr_SetString(PyExc_ValueError,
4044
0
                        "field 'right' is required for BinOp");
4045
0
        return NULL;
4046
0
    }
4047
58.7k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4048
58.7k
    if (!p)
4049
0
        return NULL;
4050
58.7k
    p->kind = BinOp_kind;
4051
58.7k
    p->v.BinOp.left = left;
4052
58.7k
    p->v.BinOp.op = op;
4053
58.7k
    p->v.BinOp.right = right;
4054
58.7k
    p->lineno = lineno;
4055
58.7k
    p->col_offset = col_offset;
4056
58.7k
    p->end_lineno = end_lineno;
4057
58.7k
    p->end_col_offset = end_col_offset;
4058
58.7k
    return p;
4059
58.7k
}
4060
4061
expr_ty
4062
_PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
4063
               end_lineno, int end_col_offset, PyArena *arena)
4064
141k
{
4065
141k
    expr_ty p;
4066
141k
    if (!op) {
4067
0
        PyErr_SetString(PyExc_ValueError,
4068
0
                        "field 'op' is required for UnaryOp");
4069
0
        return NULL;
4070
0
    }
4071
141k
    if (!operand) {
4072
0
        PyErr_SetString(PyExc_ValueError,
4073
0
                        "field 'operand' is required for UnaryOp");
4074
0
        return NULL;
4075
0
    }
4076
141k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4077
141k
    if (!p)
4078
0
        return NULL;
4079
141k
    p->kind = UnaryOp_kind;
4080
141k
    p->v.UnaryOp.op = op;
4081
141k
    p->v.UnaryOp.operand = operand;
4082
141k
    p->lineno = lineno;
4083
141k
    p->col_offset = col_offset;
4084
141k
    p->end_lineno = end_lineno;
4085
141k
    p->end_col_offset = end_col_offset;
4086
141k
    return p;
4087
141k
}
4088
4089
expr_ty
4090
_PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
4091
              end_lineno, int end_col_offset, PyArena *arena)
4092
3.20k
{
4093
3.20k
    expr_ty p;
4094
3.20k
    if (!args) {
4095
0
        PyErr_SetString(PyExc_ValueError,
4096
0
                        "field 'args' is required for Lambda");
4097
0
        return NULL;
4098
0
    }
4099
3.20k
    if (!body) {
4100
0
        PyErr_SetString(PyExc_ValueError,
4101
0
                        "field 'body' is required for Lambda");
4102
0
        return NULL;
4103
0
    }
4104
3.20k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4105
3.20k
    if (!p)
4106
0
        return NULL;
4107
3.20k
    p->kind = Lambda_kind;
4108
3.20k
    p->v.Lambda.args = args;
4109
3.20k
    p->v.Lambda.body = body;
4110
3.20k
    p->lineno = lineno;
4111
3.20k
    p->col_offset = col_offset;
4112
3.20k
    p->end_lineno = end_lineno;
4113
3.20k
    p->end_col_offset = end_col_offset;
4114
3.20k
    return p;
4115
3.20k
}
4116
4117
expr_ty
4118
_PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
4119
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4120
914
{
4121
914
    expr_ty p;
4122
914
    if (!test) {
4123
0
        PyErr_SetString(PyExc_ValueError,
4124
0
                        "field 'test' is required for IfExp");
4125
0
        return NULL;
4126
0
    }
4127
914
    if (!body) {
4128
0
        PyErr_SetString(PyExc_ValueError,
4129
0
                        "field 'body' is required for IfExp");
4130
0
        return NULL;
4131
0
    }
4132
914
    if (!orelse) {
4133
0
        PyErr_SetString(PyExc_ValueError,
4134
0
                        "field 'orelse' is required for IfExp");
4135
0
        return NULL;
4136
0
    }
4137
914
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4138
914
    if (!p)
4139
0
        return NULL;
4140
914
    p->kind = IfExp_kind;
4141
914
    p->v.IfExp.test = test;
4142
914
    p->v.IfExp.body = body;
4143
914
    p->v.IfExp.orelse = orelse;
4144
914
    p->lineno = lineno;
4145
914
    p->col_offset = col_offset;
4146
914
    p->end_lineno = end_lineno;
4147
914
    p->end_col_offset = end_col_offset;
4148
914
    return p;
4149
914
}
4150
4151
expr_ty
4152
_PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
4153
            col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4154
3.79k
{
4155
3.79k
    expr_ty p;
4156
3.79k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4157
3.79k
    if (!p)
4158
0
        return NULL;
4159
3.79k
    p->kind = Dict_kind;
4160
3.79k
    p->v.Dict.keys = keys;
4161
3.79k
    p->v.Dict.values = values;
4162
3.79k
    p->lineno = lineno;
4163
3.79k
    p->col_offset = col_offset;
4164
3.79k
    p->end_lineno = end_lineno;
4165
3.79k
    p->end_col_offset = end_col_offset;
4166
3.79k
    return p;
4167
3.79k
}
4168
4169
expr_ty
4170
_PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
4171
           int end_col_offset, PyArena *arena)
4172
1.93k
{
4173
1.93k
    expr_ty p;
4174
1.93k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4175
1.93k
    if (!p)
4176
0
        return NULL;
4177
1.93k
    p->kind = Set_kind;
4178
1.93k
    p->v.Set.elts = elts;
4179
1.93k
    p->lineno = lineno;
4180
1.93k
    p->col_offset = col_offset;
4181
1.93k
    p->end_lineno = end_lineno;
4182
1.93k
    p->end_col_offset = end_col_offset;
4183
1.93k
    return p;
4184
1.93k
}
4185
4186
expr_ty
4187
_PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
4188
                int col_offset, int end_lineno, int end_col_offset, PyArena
4189
                *arena)
4190
892
{
4191
892
    expr_ty p;
4192
892
    if (!elt) {
4193
0
        PyErr_SetString(PyExc_ValueError,
4194
0
                        "field 'elt' is required for ListComp");
4195
0
        return NULL;
4196
0
    }
4197
892
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4198
892
    if (!p)
4199
0
        return NULL;
4200
892
    p->kind = ListComp_kind;
4201
892
    p->v.ListComp.elt = elt;
4202
892
    p->v.ListComp.generators = generators;
4203
892
    p->lineno = lineno;
4204
892
    p->col_offset = col_offset;
4205
892
    p->end_lineno = end_lineno;
4206
892
    p->end_col_offset = end_col_offset;
4207
892
    return p;
4208
892
}
4209
4210
expr_ty
4211
_PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
4212
               int col_offset, int end_lineno, int end_col_offset, PyArena
4213
               *arena)
4214
805
{
4215
805
    expr_ty p;
4216
805
    if (!elt) {
4217
0
        PyErr_SetString(PyExc_ValueError,
4218
0
                        "field 'elt' is required for SetComp");
4219
0
        return NULL;
4220
0
    }
4221
805
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4222
805
    if (!p)
4223
0
        return NULL;
4224
805
    p->kind = SetComp_kind;
4225
805
    p->v.SetComp.elt = elt;
4226
805
    p->v.SetComp.generators = generators;
4227
805
    p->lineno = lineno;
4228
805
    p->col_offset = col_offset;
4229
805
    p->end_lineno = end_lineno;
4230
805
    p->end_col_offset = end_col_offset;
4231
805
    return p;
4232
805
}
4233
4234
expr_ty
4235
_PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
4236
                generators, int lineno, int col_offset, int end_lineno, int
4237
                end_col_offset, PyArena *arena)
4238
1.25k
{
4239
1.25k
    expr_ty p;
4240
1.25k
    if (!key) {
4241
0
        PyErr_SetString(PyExc_ValueError,
4242
0
                        "field 'key' is required for DictComp");
4243
0
        return NULL;
4244
0
    }
4245
1.25k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4246
1.25k
    if (!p)
4247
0
        return NULL;
4248
1.25k
    p->kind = DictComp_kind;
4249
1.25k
    p->v.DictComp.key = key;
4250
1.25k
    p->v.DictComp.value = value;
4251
1.25k
    p->v.DictComp.generators = generators;
4252
1.25k
    p->lineno = lineno;
4253
1.25k
    p->col_offset = col_offset;
4254
1.25k
    p->end_lineno = end_lineno;
4255
1.25k
    p->end_col_offset = end_col_offset;
4256
1.25k
    return p;
4257
1.25k
}
4258
4259
expr_ty
4260
_PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
4261
                    lineno, int col_offset, int end_lineno, int end_col_offset,
4262
                    PyArena *arena)
4263
2.44k
{
4264
2.44k
    expr_ty p;
4265
2.44k
    if (!elt) {
4266
0
        PyErr_SetString(PyExc_ValueError,
4267
0
                        "field 'elt' is required for GeneratorExp");
4268
0
        return NULL;
4269
0
    }
4270
2.44k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4271
2.44k
    if (!p)
4272
0
        return NULL;
4273
2.44k
    p->kind = GeneratorExp_kind;
4274
2.44k
    p->v.GeneratorExp.elt = elt;
4275
2.44k
    p->v.GeneratorExp.generators = generators;
4276
2.44k
    p->lineno = lineno;
4277
2.44k
    p->col_offset = col_offset;
4278
2.44k
    p->end_lineno = end_lineno;
4279
2.44k
    p->end_col_offset = end_col_offset;
4280
2.44k
    return p;
4281
2.44k
}
4282
4283
expr_ty
4284
_PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
4285
             end_col_offset, PyArena *arena)
4286
262
{
4287
262
    expr_ty p;
4288
262
    if (!value) {
4289
0
        PyErr_SetString(PyExc_ValueError,
4290
0
                        "field 'value' is required for Await");
4291
0
        return NULL;
4292
0
    }
4293
262
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4294
262
    if (!p)
4295
0
        return NULL;
4296
262
    p->kind = Await_kind;
4297
262
    p->v.Await.value = value;
4298
262
    p->lineno = lineno;
4299
262
    p->col_offset = col_offset;
4300
262
    p->end_lineno = end_lineno;
4301
262
    p->end_col_offset = end_col_offset;
4302
262
    return p;
4303
262
}
4304
4305
expr_ty
4306
_PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
4307
             end_col_offset, PyArena *arena)
4308
1.83k
{
4309
1.83k
    expr_ty p;
4310
1.83k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4311
1.83k
    if (!p)
4312
0
        return NULL;
4313
1.83k
    p->kind = Yield_kind;
4314
1.83k
    p->v.Yield.value = value;
4315
1.83k
    p->lineno = lineno;
4316
1.83k
    p->col_offset = col_offset;
4317
1.83k
    p->end_lineno = end_lineno;
4318
1.83k
    p->end_col_offset = end_col_offset;
4319
1.83k
    return p;
4320
1.83k
}
4321
4322
expr_ty
4323
_PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
4324
                 end_col_offset, PyArena *arena)
4325
282
{
4326
282
    expr_ty p;
4327
282
    if (!value) {
4328
0
        PyErr_SetString(PyExc_ValueError,
4329
0
                        "field 'value' is required for YieldFrom");
4330
0
        return NULL;
4331
0
    }
4332
282
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4333
282
    if (!p)
4334
0
        return NULL;
4335
282
    p->kind = YieldFrom_kind;
4336
282
    p->v.YieldFrom.value = value;
4337
282
    p->lineno = lineno;
4338
282
    p->col_offset = col_offset;
4339
282
    p->end_lineno = end_lineno;
4340
282
    p->end_col_offset = end_col_offset;
4341
282
    return p;
4342
282
}
4343
4344
expr_ty
4345
_PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
4346
               int lineno, int col_offset, int end_lineno, int end_col_offset,
4347
               PyArena *arena)
4348
6.85k
{
4349
6.85k
    expr_ty p;
4350
6.85k
    if (!left) {
4351
0
        PyErr_SetString(PyExc_ValueError,
4352
0
                        "field 'left' is required for Compare");
4353
0
        return NULL;
4354
0
    }
4355
6.85k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4356
6.85k
    if (!p)
4357
0
        return NULL;
4358
6.85k
    p->kind = Compare_kind;
4359
6.85k
    p->v.Compare.left = left;
4360
6.85k
    p->v.Compare.ops = ops;
4361
6.85k
    p->v.Compare.comparators = comparators;
4362
6.85k
    p->lineno = lineno;
4363
6.85k
    p->col_offset = col_offset;
4364
6.85k
    p->end_lineno = end_lineno;
4365
6.85k
    p->end_col_offset = end_col_offset;
4366
6.85k
    return p;
4367
6.85k
}
4368
4369
expr_ty
4370
_PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
4371
            int lineno, int col_offset, int end_lineno, int end_col_offset,
4372
            PyArena *arena)
4373
49.4k
{
4374
49.4k
    expr_ty p;
4375
49.4k
    if (!func) {
4376
0
        PyErr_SetString(PyExc_ValueError,
4377
0
                        "field 'func' is required for Call");
4378
0
        return NULL;
4379
0
    }
4380
49.4k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4381
49.4k
    if (!p)
4382
0
        return NULL;
4383
49.4k
    p->kind = Call_kind;
4384
49.4k
    p->v.Call.func = func;
4385
49.4k
    p->v.Call.args = args;
4386
49.4k
    p->v.Call.keywords = keywords;
4387
49.4k
    p->lineno = lineno;
4388
49.4k
    p->col_offset = col_offset;
4389
49.4k
    p->end_lineno = end_lineno;
4390
49.4k
    p->end_col_offset = end_col_offset;
4391
49.4k
    return p;
4392
49.4k
}
4393
4394
expr_ty
4395
_PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
4396
                      lineno, int col_offset, int end_lineno, int
4397
                      end_col_offset, PyArena *arena)
4398
20.6k
{
4399
20.6k
    expr_ty p;
4400
20.6k
    if (!value) {
4401
0
        PyErr_SetString(PyExc_ValueError,
4402
0
                        "field 'value' is required for FormattedValue");
4403
0
        return NULL;
4404
0
    }
4405
20.6k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4406
20.6k
    if (!p)
4407
0
        return NULL;
4408
20.6k
    p->kind = FormattedValue_kind;
4409
20.6k
    p->v.FormattedValue.value = value;
4410
20.6k
    p->v.FormattedValue.conversion = conversion;
4411
20.6k
    p->v.FormattedValue.format_spec = format_spec;
4412
20.6k
    p->lineno = lineno;
4413
20.6k
    p->col_offset = col_offset;
4414
20.6k
    p->end_lineno = end_lineno;
4415
20.6k
    p->end_col_offset = end_col_offset;
4416
20.6k
    return p;
4417
20.6k
}
4418
4419
expr_ty
4420
_PyAST_Interpolation(expr_ty value, constant str, int conversion, expr_ty
4421
                     format_spec, int lineno, int col_offset, int end_lineno,
4422
                     int end_col_offset, PyArena *arena)
4423
6.48k
{
4424
6.48k
    expr_ty p;
4425
6.48k
    if (!value) {
4426
0
        PyErr_SetString(PyExc_ValueError,
4427
0
                        "field 'value' is required for Interpolation");
4428
0
        return NULL;
4429
0
    }
4430
6.48k
    if (!str) {
4431
0
        PyErr_SetString(PyExc_ValueError,
4432
0
                        "field 'str' is required for Interpolation");
4433
0
        return NULL;
4434
0
    }
4435
6.48k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4436
6.48k
    if (!p)
4437
0
        return NULL;
4438
6.48k
    p->kind = Interpolation_kind;
4439
6.48k
    p->v.Interpolation.value = value;
4440
6.48k
    p->v.Interpolation.str = str;
4441
6.48k
    p->v.Interpolation.conversion = conversion;
4442
6.48k
    p->v.Interpolation.format_spec = format_spec;
4443
6.48k
    p->lineno = lineno;
4444
6.48k
    p->col_offset = col_offset;
4445
6.48k
    p->end_lineno = end_lineno;
4446
6.48k
    p->end_col_offset = end_col_offset;
4447
6.48k
    return p;
4448
6.48k
}
4449
4450
expr_ty
4451
_PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
4452
                 end_lineno, int end_col_offset, PyArena *arena)
4453
41.2k
{
4454
41.2k
    expr_ty p;
4455
41.2k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4456
41.2k
    if (!p)
4457
0
        return NULL;
4458
41.2k
    p->kind = JoinedStr_kind;
4459
41.2k
    p->v.JoinedStr.values = values;
4460
41.2k
    p->lineno = lineno;
4461
41.2k
    p->col_offset = col_offset;
4462
41.2k
    p->end_lineno = end_lineno;
4463
41.2k
    p->end_col_offset = end_col_offset;
4464
41.2k
    return p;
4465
41.2k
}
4466
4467
expr_ty
4468
_PyAST_TemplateStr(asdl_expr_seq * values, int lineno, int col_offset, int
4469
                   end_lineno, int end_col_offset, PyArena *arena)
4470
4.94k
{
4471
4.94k
    expr_ty p;
4472
4.94k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4473
4.94k
    if (!p)
4474
0
        return NULL;
4475
4.94k
    p->kind = TemplateStr_kind;
4476
4.94k
    p->v.TemplateStr.values = values;
4477
4.94k
    p->lineno = lineno;
4478
4.94k
    p->col_offset = col_offset;
4479
4.94k
    p->end_lineno = end_lineno;
4480
4.94k
    p->end_col_offset = end_col_offset;
4481
4.94k
    return p;
4482
4.94k
}
4483
4484
expr_ty
4485
_PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
4486
                end_lineno, int end_col_offset, PyArena *arena)
4487
269k
{
4488
269k
    expr_ty p;
4489
269k
    if (!value) {
4490
0
        PyErr_SetString(PyExc_ValueError,
4491
0
                        "field 'value' is required for Constant");
4492
0
        return NULL;
4493
0
    }
4494
269k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4495
269k
    if (!p)
4496
0
        return NULL;
4497
269k
    p->kind = Constant_kind;
4498
269k
    p->v.Constant.value = value;
4499
269k
    p->v.Constant.kind = kind;
4500
269k
    p->lineno = lineno;
4501
269k
    p->col_offset = col_offset;
4502
269k
    p->end_lineno = end_lineno;
4503
269k
    p->end_col_offset = end_col_offset;
4504
269k
    return p;
4505
269k
}
4506
4507
expr_ty
4508
_PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
4509
                 lineno, int col_offset, int end_lineno, int end_col_offset,
4510
                 PyArena *arena)
4511
24.7k
{
4512
24.7k
    expr_ty p;
4513
24.7k
    if (!value) {
4514
0
        PyErr_SetString(PyExc_ValueError,
4515
0
                        "field 'value' is required for Attribute");
4516
0
        return NULL;
4517
0
    }
4518
24.7k
    if (!attr) {
4519
0
        PyErr_SetString(PyExc_ValueError,
4520
0
                        "field 'attr' is required for Attribute");
4521
0
        return NULL;
4522
0
    }
4523
24.7k
    if (!ctx) {
4524
0
        PyErr_SetString(PyExc_ValueError,
4525
0
                        "field 'ctx' is required for Attribute");
4526
0
        return NULL;
4527
0
    }
4528
24.7k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4529
24.7k
    if (!p)
4530
0
        return NULL;
4531
24.7k
    p->kind = Attribute_kind;
4532
24.7k
    p->v.Attribute.value = value;
4533
24.7k
    p->v.Attribute.attr = attr;
4534
24.7k
    p->v.Attribute.ctx = ctx;
4535
24.7k
    p->lineno = lineno;
4536
24.7k
    p->col_offset = col_offset;
4537
24.7k
    p->end_lineno = end_lineno;
4538
24.7k
    p->end_col_offset = end_col_offset;
4539
24.7k
    return p;
4540
24.7k
}
4541
4542
expr_ty
4543
_PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
4544
                 int col_offset, int end_lineno, int end_col_offset, PyArena
4545
                 *arena)
4546
4.31k
{
4547
4.31k
    expr_ty p;
4548
4.31k
    if (!value) {
4549
0
        PyErr_SetString(PyExc_ValueError,
4550
0
                        "field 'value' is required for Subscript");
4551
0
        return NULL;
4552
0
    }
4553
4.31k
    if (!slice) {
4554
0
        PyErr_SetString(PyExc_ValueError,
4555
0
                        "field 'slice' is required for Subscript");
4556
0
        return NULL;
4557
0
    }
4558
4.31k
    if (!ctx) {
4559
0
        PyErr_SetString(PyExc_ValueError,
4560
0
                        "field 'ctx' is required for Subscript");
4561
0
        return NULL;
4562
0
    }
4563
4.31k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4564
4.31k
    if (!p)
4565
0
        return NULL;
4566
4.31k
    p->kind = Subscript_kind;
4567
4.31k
    p->v.Subscript.value = value;
4568
4.31k
    p->v.Subscript.slice = slice;
4569
4.31k
    p->v.Subscript.ctx = ctx;
4570
4.31k
    p->lineno = lineno;
4571
4.31k
    p->col_offset = col_offset;
4572
4.31k
    p->end_lineno = end_lineno;
4573
4.31k
    p->end_col_offset = end_col_offset;
4574
4.31k
    return p;
4575
4.31k
}
4576
4577
expr_ty
4578
_PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
4579
               int end_lineno, int end_col_offset, PyArena *arena)
4580
19.7k
{
4581
19.7k
    expr_ty p;
4582
19.7k
    if (!value) {
4583
0
        PyErr_SetString(PyExc_ValueError,
4584
0
                        "field 'value' is required for Starred");
4585
0
        return NULL;
4586
0
    }
4587
19.7k
    if (!ctx) {
4588
0
        PyErr_SetString(PyExc_ValueError,
4589
0
                        "field 'ctx' is required for Starred");
4590
0
        return NULL;
4591
0
    }
4592
19.7k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4593
19.7k
    if (!p)
4594
0
        return NULL;
4595
19.7k
    p->kind = Starred_kind;
4596
19.7k
    p->v.Starred.value = value;
4597
19.7k
    p->v.Starred.ctx = ctx;
4598
19.7k
    p->lineno = lineno;
4599
19.7k
    p->col_offset = col_offset;
4600
19.7k
    p->end_lineno = end_lineno;
4601
19.7k
    p->end_col_offset = end_col_offset;
4602
19.7k
    return p;
4603
19.7k
}
4604
4605
expr_ty
4606
_PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
4607
            end_lineno, int end_col_offset, PyArena *arena)
4608
711k
{
4609
711k
    expr_ty p;
4610
711k
    if (!id) {
4611
0
        PyErr_SetString(PyExc_ValueError,
4612
0
                        "field 'id' is required for Name");
4613
0
        return NULL;
4614
0
    }
4615
711k
    if (!ctx) {
4616
0
        PyErr_SetString(PyExc_ValueError,
4617
0
                        "field 'ctx' is required for Name");
4618
0
        return NULL;
4619
0
    }
4620
711k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4621
711k
    if (!p)
4622
0
        return NULL;
4623
711k
    p->kind = Name_kind;
4624
711k
    p->v.Name.id = id;
4625
711k
    p->v.Name.ctx = ctx;
4626
711k
    p->lineno = lineno;
4627
711k
    p->col_offset = col_offset;
4628
711k
    p->end_lineno = end_lineno;
4629
711k
    p->end_col_offset = end_col_offset;
4630
711k
    return p;
4631
711k
}
4632
4633
expr_ty
4634
_PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
4635
            col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4636
9.34k
{
4637
9.34k
    expr_ty p;
4638
9.34k
    if (!ctx) {
4639
0
        PyErr_SetString(PyExc_ValueError,
4640
0
                        "field 'ctx' is required for List");
4641
0
        return NULL;
4642
0
    }
4643
9.34k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4644
9.34k
    if (!p)
4645
0
        return NULL;
4646
9.34k
    p->kind = List_kind;
4647
9.34k
    p->v.List.elts = elts;
4648
9.34k
    p->v.List.ctx = ctx;
4649
9.34k
    p->lineno = lineno;
4650
9.34k
    p->col_offset = col_offset;
4651
9.34k
    p->end_lineno = end_lineno;
4652
9.34k
    p->end_col_offset = end_col_offset;
4653
9.34k
    return p;
4654
9.34k
}
4655
4656
expr_ty
4657
_PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
4658
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4659
64.2k
{
4660
64.2k
    expr_ty p;
4661
64.2k
    if (!ctx) {
4662
0
        PyErr_SetString(PyExc_ValueError,
4663
0
                        "field 'ctx' is required for Tuple");
4664
0
        return NULL;
4665
0
    }
4666
64.2k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4667
64.2k
    if (!p)
4668
0
        return NULL;
4669
64.2k
    p->kind = Tuple_kind;
4670
64.2k
    p->v.Tuple.elts = elts;
4671
64.2k
    p->v.Tuple.ctx = ctx;
4672
64.2k
    p->lineno = lineno;
4673
64.2k
    p->col_offset = col_offset;
4674
64.2k
    p->end_lineno = end_lineno;
4675
64.2k
    p->end_col_offset = end_col_offset;
4676
64.2k
    return p;
4677
64.2k
}
4678
4679
expr_ty
4680
_PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
4681
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4682
4.41k
{
4683
4.41k
    expr_ty p;
4684
4.41k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4685
4.41k
    if (!p)
4686
0
        return NULL;
4687
4.41k
    p->kind = Slice_kind;
4688
4.41k
    p->v.Slice.lower = lower;
4689
4.41k
    p->v.Slice.upper = upper;
4690
4.41k
    p->v.Slice.step = step;
4691
4.41k
    p->lineno = lineno;
4692
4.41k
    p->col_offset = col_offset;
4693
4.41k
    p->end_lineno = end_lineno;
4694
4.41k
    p->end_col_offset = end_col_offset;
4695
4.41k
    return p;
4696
4.41k
}
4697
4698
comprehension_ty
4699
_PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
4700
                     is_async, PyArena *arena)
4701
7.71k
{
4702
7.71k
    comprehension_ty p;
4703
7.71k
    if (!target) {
4704
0
        PyErr_SetString(PyExc_ValueError,
4705
0
                        "field 'target' is required for comprehension");
4706
0
        return NULL;
4707
0
    }
4708
7.71k
    if (!iter) {
4709
0
        PyErr_SetString(PyExc_ValueError,
4710
0
                        "field 'iter' is required for comprehension");
4711
0
        return NULL;
4712
0
    }
4713
7.71k
    p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
4714
7.71k
    if (!p)
4715
0
        return NULL;
4716
7.71k
    p->target = target;
4717
7.71k
    p->iter = iter;
4718
7.71k
    p->ifs = ifs;
4719
7.71k
    p->is_async = is_async;
4720
7.71k
    return p;
4721
7.71k
}
4722
4723
excepthandler_ty
4724
_PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
4725
                     lineno, int col_offset, int end_lineno, int
4726
                     end_col_offset, PyArena *arena)
4727
8.23k
{
4728
8.23k
    excepthandler_ty p;
4729
8.23k
    p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
4730
8.23k
    if (!p)
4731
0
        return NULL;
4732
8.23k
    p->kind = ExceptHandler_kind;
4733
8.23k
    p->v.ExceptHandler.type = type;
4734
8.23k
    p->v.ExceptHandler.name = name;
4735
8.23k
    p->v.ExceptHandler.body = body;
4736
8.23k
    p->lineno = lineno;
4737
8.23k
    p->col_offset = col_offset;
4738
8.23k
    p->end_lineno = end_lineno;
4739
8.23k
    p->end_col_offset = end_col_offset;
4740
8.23k
    return p;
4741
8.23k
}
4742
4743
arguments_ty
4744
_PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
4745
                 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
4746
                 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
4747
                 *arena)
4748
188k
{
4749
188k
    arguments_ty p;
4750
188k
    p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
4751
188k
    if (!p)
4752
0
        return NULL;
4753
188k
    p->posonlyargs = posonlyargs;
4754
188k
    p->args = args;
4755
188k
    p->vararg = vararg;
4756
188k
    p->kwonlyargs = kwonlyargs;
4757
188k
    p->kw_defaults = kw_defaults;
4758
188k
    p->kwarg = kwarg;
4759
188k
    p->defaults = defaults;
4760
188k
    return p;
4761
188k
}
4762
4763
arg_ty
4764
_PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
4765
           int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4766
5.71M
{
4767
5.71M
    arg_ty p;
4768
5.71M
    if (!arg) {
4769
0
        PyErr_SetString(PyExc_ValueError,
4770
0
                        "field 'arg' is required for arg");
4771
0
        return NULL;
4772
0
    }
4773
5.71M
    p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
4774
5.71M
    if (!p)
4775
0
        return NULL;
4776
5.71M
    p->arg = arg;
4777
5.71M
    p->annotation = annotation;
4778
5.71M
    p->type_comment = type_comment;
4779
5.71M
    p->lineno = lineno;
4780
5.71M
    p->col_offset = col_offset;
4781
5.71M
    p->end_lineno = end_lineno;
4782
5.71M
    p->end_col_offset = end_col_offset;
4783
5.71M
    return p;
4784
5.71M
}
4785
4786
keyword_ty
4787
_PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
4788
               end_lineno, int end_col_offset, PyArena *arena)
4789
24.5k
{
4790
24.5k
    keyword_ty p;
4791
24.5k
    if (!value) {
4792
0
        PyErr_SetString(PyExc_ValueError,
4793
0
                        "field 'value' is required for keyword");
4794
0
        return NULL;
4795
0
    }
4796
24.5k
    p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
4797
24.5k
    if (!p)
4798
0
        return NULL;
4799
24.5k
    p->arg = arg;
4800
24.5k
    p->value = value;
4801
24.5k
    p->lineno = lineno;
4802
24.5k
    p->col_offset = col_offset;
4803
24.5k
    p->end_lineno = end_lineno;
4804
24.5k
    p->end_col_offset = end_col_offset;
4805
24.5k
    return p;
4806
24.5k
}
4807
4808
alias_ty
4809
_PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
4810
             int end_lineno, int end_col_offset, PyArena *arena)
4811
15.6k
{
4812
15.6k
    alias_ty p;
4813
15.6k
    if (!name) {
4814
0
        PyErr_SetString(PyExc_ValueError,
4815
0
                        "field 'name' is required for alias");
4816
0
        return NULL;
4817
0
    }
4818
15.6k
    p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
4819
15.6k
    if (!p)
4820
0
        return NULL;
4821
15.6k
    p->name = name;
4822
15.6k
    p->asname = asname;
4823
15.6k
    p->lineno = lineno;
4824
15.6k
    p->col_offset = col_offset;
4825
15.6k
    p->end_lineno = end_lineno;
4826
15.6k
    p->end_col_offset = end_col_offset;
4827
15.6k
    return p;
4828
15.6k
}
4829
4830
withitem_ty
4831
_PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
4832
12.6k
{
4833
12.6k
    withitem_ty p;
4834
12.6k
    if (!context_expr) {
4835
0
        PyErr_SetString(PyExc_ValueError,
4836
0
                        "field 'context_expr' is required for withitem");
4837
0
        return NULL;
4838
0
    }
4839
12.6k
    p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
4840
12.6k
    if (!p)
4841
0
        return NULL;
4842
12.6k
    p->context_expr = context_expr;
4843
12.6k
    p->optional_vars = optional_vars;
4844
12.6k
    return p;
4845
12.6k
}
4846
4847
match_case_ty
4848
_PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
4849
                  PyArena *arena)
4850
2.98k
{
4851
2.98k
    match_case_ty p;
4852
2.98k
    if (!pattern) {
4853
0
        PyErr_SetString(PyExc_ValueError,
4854
0
                        "field 'pattern' is required for match_case");
4855
0
        return NULL;
4856
0
    }
4857
2.98k
    p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
4858
2.98k
    if (!p)
4859
0
        return NULL;
4860
2.98k
    p->pattern = pattern;
4861
2.98k
    p->guard = guard;
4862
2.98k
    p->body = body;
4863
2.98k
    return p;
4864
2.98k
}
4865
4866
pattern_ty
4867
_PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
4868
                  int end_col_offset, PyArena *arena)
4869
6.59k
{
4870
6.59k
    pattern_ty p;
4871
6.59k
    if (!value) {
4872
0
        PyErr_SetString(PyExc_ValueError,
4873
0
                        "field 'value' is required for MatchValue");
4874
0
        return NULL;
4875
0
    }
4876
6.59k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4877
6.59k
    if (!p)
4878
0
        return NULL;
4879
6.59k
    p->kind = MatchValue_kind;
4880
6.59k
    p->v.MatchValue.value = value;
4881
6.59k
    p->lineno = lineno;
4882
6.59k
    p->col_offset = col_offset;
4883
6.59k
    p->end_lineno = end_lineno;
4884
6.59k
    p->end_col_offset = end_col_offset;
4885
6.59k
    return p;
4886
6.59k
}
4887
4888
pattern_ty
4889
_PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
4890
                      end_lineno, int end_col_offset, PyArena *arena)
4891
833
{
4892
833
    pattern_ty p;
4893
833
    if (!value) {
4894
0
        PyErr_SetString(PyExc_ValueError,
4895
0
                        "field 'value' is required for MatchSingleton");
4896
0
        return NULL;
4897
0
    }
4898
833
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4899
833
    if (!p)
4900
0
        return NULL;
4901
833
    p->kind = MatchSingleton_kind;
4902
833
    p->v.MatchSingleton.value = value;
4903
833
    p->lineno = lineno;
4904
833
    p->col_offset = col_offset;
4905
833
    p->end_lineno = end_lineno;
4906
833
    p->end_col_offset = end_col_offset;
4907
833
    return p;
4908
833
}
4909
4910
pattern_ty
4911
_PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
4912
                     int end_lineno, int end_col_offset, PyArena *arena)
4913
3.59k
{
4914
3.59k
    pattern_ty p;
4915
3.59k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4916
3.59k
    if (!p)
4917
0
        return NULL;
4918
3.59k
    p->kind = MatchSequence_kind;
4919
3.59k
    p->v.MatchSequence.patterns = patterns;
4920
3.59k
    p->lineno = lineno;
4921
3.59k
    p->col_offset = col_offset;
4922
3.59k
    p->end_lineno = end_lineno;
4923
3.59k
    p->end_col_offset = end_col_offset;
4924
3.59k
    return p;
4925
3.59k
}
4926
4927
pattern_ty
4928
_PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
4929
                    identifier rest, int lineno, int col_offset, int
4930
                    end_lineno, int end_col_offset, PyArena *arena)
4931
1.38k
{
4932
1.38k
    pattern_ty p;
4933
1.38k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4934
1.38k
    if (!p)
4935
0
        return NULL;
4936
1.38k
    p->kind = MatchMapping_kind;
4937
1.38k
    p->v.MatchMapping.keys = keys;
4938
1.38k
    p->v.MatchMapping.patterns = patterns;
4939
1.38k
    p->v.MatchMapping.rest = rest;
4940
1.38k
    p->lineno = lineno;
4941
1.38k
    p->col_offset = col_offset;
4942
1.38k
    p->end_lineno = end_lineno;
4943
1.38k
    p->end_col_offset = end_col_offset;
4944
1.38k
    return p;
4945
1.38k
}
4946
4947
pattern_ty
4948
_PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
4949
                  * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
4950
                  col_offset, int end_lineno, int end_col_offset, PyArena
4951
                  *arena)
4952
2.32k
{
4953
2.32k
    pattern_ty p;
4954
2.32k
    if (!cls) {
4955
0
        PyErr_SetString(PyExc_ValueError,
4956
0
                        "field 'cls' is required for MatchClass");
4957
0
        return NULL;
4958
0
    }
4959
2.32k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4960
2.32k
    if (!p)
4961
0
        return NULL;
4962
2.32k
    p->kind = MatchClass_kind;
4963
2.32k
    p->v.MatchClass.cls = cls;
4964
2.32k
    p->v.MatchClass.patterns = patterns;
4965
2.32k
    p->v.MatchClass.kwd_attrs = kwd_attrs;
4966
2.32k
    p->v.MatchClass.kwd_patterns = kwd_patterns;
4967
2.32k
    p->lineno = lineno;
4968
2.32k
    p->col_offset = col_offset;
4969
2.32k
    p->end_lineno = end_lineno;
4970
2.32k
    p->end_col_offset = end_col_offset;
4971
2.32k
    return p;
4972
2.32k
}
4973
4974
pattern_ty
4975
_PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
4976
                 int end_col_offset, PyArena *arena)
4977
1.66k
{
4978
1.66k
    pattern_ty p;
4979
1.66k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4980
1.66k
    if (!p)
4981
0
        return NULL;
4982
1.66k
    p->kind = MatchStar_kind;
4983
1.66k
    p->v.MatchStar.name = name;
4984
1.66k
    p->lineno = lineno;
4985
1.66k
    p->col_offset = col_offset;
4986
1.66k
    p->end_lineno = end_lineno;
4987
1.66k
    p->end_col_offset = end_col_offset;
4988
1.66k
    return p;
4989
1.66k
}
4990
4991
pattern_ty
4992
_PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
4993
               int end_lineno, int end_col_offset, PyArena *arena)
4994
21.6k
{
4995
21.6k
    pattern_ty p;
4996
21.6k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4997
21.6k
    if (!p)
4998
0
        return NULL;
4999
21.6k
    p->kind = MatchAs_kind;
5000
21.6k
    p->v.MatchAs.pattern = pattern;
5001
21.6k
    p->v.MatchAs.name = name;
5002
21.6k
    p->lineno = lineno;
5003
21.6k
    p->col_offset = col_offset;
5004
21.6k
    p->end_lineno = end_lineno;
5005
21.6k
    p->end_col_offset = end_col_offset;
5006
21.6k
    return p;
5007
21.6k
}
5008
5009
pattern_ty
5010
_PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
5011
               end_lineno, int end_col_offset, PyArena *arena)
5012
8.71k
{
5013
8.71k
    pattern_ty p;
5014
8.71k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
5015
8.71k
    if (!p)
5016
0
        return NULL;
5017
8.71k
    p->kind = MatchOr_kind;
5018
8.71k
    p->v.MatchOr.patterns = patterns;
5019
8.71k
    p->lineno = lineno;
5020
8.71k
    p->col_offset = col_offset;
5021
8.71k
    p->end_lineno = end_lineno;
5022
8.71k
    p->end_col_offset = end_col_offset;
5023
8.71k
    return p;
5024
8.71k
}
5025
5026
type_ignore_ty
5027
_PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
5028
0
{
5029
0
    type_ignore_ty p;
5030
0
    if (!tag) {
5031
0
        PyErr_SetString(PyExc_ValueError,
5032
0
                        "field 'tag' is required for TypeIgnore");
5033
0
        return NULL;
5034
0
    }
5035
0
    p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
5036
0
    if (!p)
5037
0
        return NULL;
5038
0
    p->kind = TypeIgnore_kind;
5039
0
    p->v.TypeIgnore.lineno = lineno;
5040
0
    p->v.TypeIgnore.tag = tag;
5041
0
    return p;
5042
0
}
5043
5044
type_param_ty
5045
_PyAST_TypeVar(identifier name, expr_ty bound, expr_ty default_value, int
5046
               lineno, int col_offset, int end_lineno, int end_col_offset,
5047
               PyArena *arena)
5048
7.37k
{
5049
7.37k
    type_param_ty p;
5050
7.37k
    if (!name) {
5051
0
        PyErr_SetString(PyExc_ValueError,
5052
0
                        "field 'name' is required for TypeVar");
5053
0
        return NULL;
5054
0
    }
5055
7.37k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5056
7.37k
    if (!p)
5057
0
        return NULL;
5058
7.37k
    p->kind = TypeVar_kind;
5059
7.37k
    p->v.TypeVar.name = name;
5060
7.37k
    p->v.TypeVar.bound = bound;
5061
7.37k
    p->v.TypeVar.default_value = default_value;
5062
7.37k
    p->lineno = lineno;
5063
7.37k
    p->col_offset = col_offset;
5064
7.37k
    p->end_lineno = end_lineno;
5065
7.37k
    p->end_col_offset = end_col_offset;
5066
7.37k
    return p;
5067
7.37k
}
5068
5069
type_param_ty
5070
_PyAST_ParamSpec(identifier name, expr_ty default_value, int lineno, int
5071
                 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
5072
1.77k
{
5073
1.77k
    type_param_ty p;
5074
1.77k
    if (!name) {
5075
0
        PyErr_SetString(PyExc_ValueError,
5076
0
                        "field 'name' is required for ParamSpec");
5077
0
        return NULL;
5078
0
    }
5079
1.77k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5080
1.77k
    if (!p)
5081
0
        return NULL;
5082
1.77k
    p->kind = ParamSpec_kind;
5083
1.77k
    p->v.ParamSpec.name = name;
5084
1.77k
    p->v.ParamSpec.default_value = default_value;
5085
1.77k
    p->lineno = lineno;
5086
1.77k
    p->col_offset = col_offset;
5087
1.77k
    p->end_lineno = end_lineno;
5088
1.77k
    p->end_col_offset = end_col_offset;
5089
1.77k
    return p;
5090
1.77k
}
5091
5092
type_param_ty
5093
_PyAST_TypeVarTuple(identifier name, expr_ty default_value, int lineno, int
5094
                    col_offset, int end_lineno, int end_col_offset, PyArena
5095
                    *arena)
5096
1.74k
{
5097
1.74k
    type_param_ty p;
5098
1.74k
    if (!name) {
5099
0
        PyErr_SetString(PyExc_ValueError,
5100
0
                        "field 'name' is required for TypeVarTuple");
5101
0
        return NULL;
5102
0
    }
5103
1.74k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5104
1.74k
    if (!p)
5105
0
        return NULL;
5106
1.74k
    p->kind = TypeVarTuple_kind;
5107
1.74k
    p->v.TypeVarTuple.name = name;
5108
1.74k
    p->v.TypeVarTuple.default_value = default_value;
5109
1.74k
    p->lineno = lineno;
5110
1.74k
    p->col_offset = col_offset;
5111
1.74k
    p->end_lineno = end_lineno;
5112
1.74k
    p->end_col_offset = end_col_offset;
5113
1.74k
    return p;
5114
1.74k
}
5115
5116
5117
PyObject*
5118
ast2obj_mod(struct ast_state *state, void* _o)
5119
7.39k
{
5120
7.39k
    mod_ty o = (mod_ty)_o;
5121
7.39k
    PyObject *result = NULL, *value = NULL;
5122
7.39k
    PyTypeObject *tp;
5123
7.39k
    if (!o) {
5124
0
        Py_RETURN_NONE;
5125
0
    }
5126
7.39k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5127
0
        return NULL;
5128
0
    }
5129
7.39k
    switch (o->kind) {
5130
7.39k
    case Module_kind:
5131
7.39k
        tp = (PyTypeObject *)state->Module_type;
5132
7.39k
        result = PyType_GenericNew(tp, NULL, NULL);
5133
7.39k
        if (!result) goto failed;
5134
7.39k
        value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
5135
7.39k
        if (!value) goto failed;
5136
7.39k
        if (PyObject_SetAttr(result, state->body, value) == -1)
5137
0
            goto failed;
5138
7.39k
        Py_DECREF(value);
5139
7.39k
        value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
5140
7.39k
                             ast2obj_type_ignore);
5141
7.39k
        if (!value) goto failed;
5142
7.39k
        if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
5143
0
            goto failed;
5144
7.39k
        Py_DECREF(value);
5145
7.39k
        break;
5146
0
    case Interactive_kind:
5147
0
        tp = (PyTypeObject *)state->Interactive_type;
5148
0
        result = PyType_GenericNew(tp, NULL, NULL);
5149
0
        if (!result) goto failed;
5150
0
        value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
5151
0
                             ast2obj_stmt);
5152
0
        if (!value) goto failed;
5153
0
        if (PyObject_SetAttr(result, state->body, value) == -1)
5154
0
            goto failed;
5155
0
        Py_DECREF(value);
5156
0
        break;
5157
0
    case Expression_kind:
5158
0
        tp = (PyTypeObject *)state->Expression_type;
5159
0
        result = PyType_GenericNew(tp, NULL, NULL);
5160
0
        if (!result) goto failed;
5161
0
        value = ast2obj_expr(state, o->v.Expression.body);
5162
0
        if (!value) goto failed;
5163
0
        if (PyObject_SetAttr(result, state->body, value) == -1)
5164
0
            goto failed;
5165
0
        Py_DECREF(value);
5166
0
        break;
5167
0
    case FunctionType_kind:
5168
0
        tp = (PyTypeObject *)state->FunctionType_type;
5169
0
        result = PyType_GenericNew(tp, NULL, NULL);
5170
0
        if (!result) goto failed;
5171
0
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
5172
0
                             ast2obj_expr);
5173
0
        if (!value) goto failed;
5174
0
        if (PyObject_SetAttr(result, state->argtypes, value) == -1)
5175
0
            goto failed;
5176
0
        Py_DECREF(value);
5177
0
        value = ast2obj_expr(state, o->v.FunctionType.returns);
5178
0
        if (!value) goto failed;
5179
0
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5180
0
            goto failed;
5181
0
        Py_DECREF(value);
5182
0
        break;
5183
7.39k
    }
5184
7.39k
    Py_LeaveRecursiveCall();
5185
7.39k
    return result;
5186
0
failed:
5187
0
    Py_LeaveRecursiveCall();
5188
0
    Py_XDECREF(value);
5189
0
    Py_XDECREF(result);
5190
0
    return NULL;
5191
7.39k
}
5192
5193
PyObject*
5194
ast2obj_stmt(struct ast_state *state, void* _o)
5195
48.5k
{
5196
48.5k
    stmt_ty o = (stmt_ty)_o;
5197
48.5k
    PyObject *result = NULL, *value = NULL;
5198
48.5k
    PyTypeObject *tp;
5199
48.5k
    if (!o) {
5200
0
        Py_RETURN_NONE;
5201
0
    }
5202
48.5k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5203
0
        return NULL;
5204
0
    }
5205
48.5k
    switch (o->kind) {
5206
1.95k
    case FunctionDef_kind:
5207
1.95k
        tp = (PyTypeObject *)state->FunctionDef_type;
5208
1.95k
        result = PyType_GenericNew(tp, NULL, NULL);
5209
1.95k
        if (!result) goto failed;
5210
1.95k
        value = ast2obj_identifier(state, o->v.FunctionDef.name);
5211
1.95k
        if (!value) goto failed;
5212
1.95k
        if (PyObject_SetAttr(result, state->name, value) == -1)
5213
0
            goto failed;
5214
1.95k
        Py_DECREF(value);
5215
1.95k
        value = ast2obj_arguments(state, o->v.FunctionDef.args);
5216
1.95k
        if (!value) goto failed;
5217
1.95k
        if (PyObject_SetAttr(result, state->args, value) == -1)
5218
0
            goto failed;
5219
1.95k
        Py_DECREF(value);
5220
1.95k
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
5221
1.95k
                             ast2obj_stmt);
5222
1.95k
        if (!value) goto failed;
5223
1.95k
        if (PyObject_SetAttr(result, state->body, value) == -1)
5224
0
            goto failed;
5225
1.95k
        Py_DECREF(value);
5226
1.95k
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
5227
1.95k
                             ast2obj_expr);
5228
1.95k
        if (!value) goto failed;
5229
1.95k
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5230
0
            goto failed;
5231
1.95k
        Py_DECREF(value);
5232
1.95k
        value = ast2obj_expr(state, o->v.FunctionDef.returns);
5233
1.95k
        if (!value) goto failed;
5234
1.95k
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5235
0
            goto failed;
5236
1.95k
        Py_DECREF(value);
5237
1.95k
        value = ast2obj_string(state, o->v.FunctionDef.type_comment);
5238
1.95k
        if (!value) goto failed;
5239
1.95k
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5240
0
            goto failed;
5241
1.95k
        Py_DECREF(value);
5242
1.95k
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.type_params,
5243
1.95k
                             ast2obj_type_param);
5244
1.95k
        if (!value) goto failed;
5245
1.95k
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5246
0
            goto failed;
5247
1.95k
        Py_DECREF(value);
5248
1.95k
        break;
5249
562
    case AsyncFunctionDef_kind:
5250
562
        tp = (PyTypeObject *)state->AsyncFunctionDef_type;
5251
562
        result = PyType_GenericNew(tp, NULL, NULL);
5252
562
        if (!result) goto failed;
5253
562
        value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
5254
562
        if (!value) goto failed;
5255
562
        if (PyObject_SetAttr(result, state->name, value) == -1)
5256
0
            goto failed;
5257
562
        Py_DECREF(value);
5258
562
        value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
5259
562
        if (!value) goto failed;
5260
562
        if (PyObject_SetAttr(result, state->args, value) == -1)
5261
0
            goto failed;
5262
562
        Py_DECREF(value);
5263
562
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
5264
562
                             ast2obj_stmt);
5265
562
        if (!value) goto failed;
5266
562
        if (PyObject_SetAttr(result, state->body, value) == -1)
5267
0
            goto failed;
5268
562
        Py_DECREF(value);
5269
562
        value = ast2obj_list(state,
5270
562
                             (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
5271
562
                             ast2obj_expr);
5272
562
        if (!value) goto failed;
5273
562
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5274
0
            goto failed;
5275
562
        Py_DECREF(value);
5276
562
        value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
5277
562
        if (!value) goto failed;
5278
562
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5279
0
            goto failed;
5280
562
        Py_DECREF(value);
5281
562
        value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
5282
562
        if (!value) goto failed;
5283
562
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5284
0
            goto failed;
5285
562
        Py_DECREF(value);
5286
562
        value = ast2obj_list(state,
5287
562
                             (asdl_seq*)o->v.AsyncFunctionDef.type_params,
5288
562
                             ast2obj_type_param);
5289
562
        if (!value) goto failed;
5290
562
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5291
0
            goto failed;
5292
562
        Py_DECREF(value);
5293
562
        break;
5294
373
    case ClassDef_kind:
5295
373
        tp = (PyTypeObject *)state->ClassDef_type;
5296
373
        result = PyType_GenericNew(tp, NULL, NULL);
5297
373
        if (!result) goto failed;
5298
373
        value = ast2obj_identifier(state, o->v.ClassDef.name);
5299
373
        if (!value) goto failed;
5300
373
        if (PyObject_SetAttr(result, state->name, value) == -1)
5301
0
            goto failed;
5302
373
        Py_DECREF(value);
5303
373
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
5304
373
                             ast2obj_expr);
5305
373
        if (!value) goto failed;
5306
373
        if (PyObject_SetAttr(result, state->bases, value) == -1)
5307
0
            goto failed;
5308
373
        Py_DECREF(value);
5309
373
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
5310
373
                             ast2obj_keyword);
5311
373
        if (!value) goto failed;
5312
373
        if (PyObject_SetAttr(result, state->keywords, value) == -1)
5313
0
            goto failed;
5314
373
        Py_DECREF(value);
5315
373
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
5316
373
                             ast2obj_stmt);
5317
373
        if (!value) goto failed;
5318
373
        if (PyObject_SetAttr(result, state->body, value) == -1)
5319
0
            goto failed;
5320
373
        Py_DECREF(value);
5321
373
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
5322
373
                             ast2obj_expr);
5323
373
        if (!value) goto failed;
5324
373
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5325
0
            goto failed;
5326
373
        Py_DECREF(value);
5327
373
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.type_params,
5328
373
                             ast2obj_type_param);
5329
373
        if (!value) goto failed;
5330
373
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5331
0
            goto failed;
5332
373
        Py_DECREF(value);
5333
373
        break;
5334
486
    case Return_kind:
5335
486
        tp = (PyTypeObject *)state->Return_type;
5336
486
        result = PyType_GenericNew(tp, NULL, NULL);
5337
486
        if (!result) goto failed;
5338
486
        value = ast2obj_expr(state, o->v.Return.value);
5339
486
        if (!value) goto failed;
5340
486
        if (PyObject_SetAttr(result, state->value, value) == -1)
5341
0
            goto failed;
5342
486
        Py_DECREF(value);
5343
486
        break;
5344
293
    case Delete_kind:
5345
293
        tp = (PyTypeObject *)state->Delete_type;
5346
293
        result = PyType_GenericNew(tp, NULL, NULL);
5347
293
        if (!result) goto failed;
5348
293
        value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
5349
293
                             ast2obj_expr);
5350
293
        if (!value) goto failed;
5351
293
        if (PyObject_SetAttr(result, state->targets, value) == -1)
5352
0
            goto failed;
5353
293
        Py_DECREF(value);
5354
293
        break;
5355
778
    case Assign_kind:
5356
778
        tp = (PyTypeObject *)state->Assign_type;
5357
778
        result = PyType_GenericNew(tp, NULL, NULL);
5358
778
        if (!result) goto failed;
5359
778
        value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
5360
778
                             ast2obj_expr);
5361
778
        if (!value) goto failed;
5362
778
        if (PyObject_SetAttr(result, state->targets, value) == -1)
5363
0
            goto failed;
5364
778
        Py_DECREF(value);
5365
778
        value = ast2obj_expr(state, o->v.Assign.value);
5366
778
        if (!value) goto failed;
5367
778
        if (PyObject_SetAttr(result, state->value, value) == -1)
5368
0
            goto failed;
5369
778
        Py_DECREF(value);
5370
778
        value = ast2obj_string(state, o->v.Assign.type_comment);
5371
778
        if (!value) goto failed;
5372
778
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5373
0
            goto failed;
5374
778
        Py_DECREF(value);
5375
778
        break;
5376
210
    case TypeAlias_kind:
5377
210
        tp = (PyTypeObject *)state->TypeAlias_type;
5378
210
        result = PyType_GenericNew(tp, NULL, NULL);
5379
210
        if (!result) goto failed;
5380
210
        value = ast2obj_expr(state, o->v.TypeAlias.name);
5381
210
        if (!value) goto failed;
5382
210
        if (PyObject_SetAttr(result, state->name, value) == -1)
5383
0
            goto failed;
5384
210
        Py_DECREF(value);
5385
210
        value = ast2obj_list(state, (asdl_seq*)o->v.TypeAlias.type_params,
5386
210
                             ast2obj_type_param);
5387
210
        if (!value) goto failed;
5388
210
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5389
0
            goto failed;
5390
210
        Py_DECREF(value);
5391
210
        value = ast2obj_expr(state, o->v.TypeAlias.value);
5392
210
        if (!value) goto failed;
5393
210
        if (PyObject_SetAttr(result, state->value, value) == -1)
5394
0
            goto failed;
5395
210
        Py_DECREF(value);
5396
210
        break;
5397
551
    case AugAssign_kind:
5398
551
        tp = (PyTypeObject *)state->AugAssign_type;
5399
551
        result = PyType_GenericNew(tp, NULL, NULL);
5400
551
        if (!result) goto failed;
5401
551
        value = ast2obj_expr(state, o->v.AugAssign.target);
5402
551
        if (!value) goto failed;
5403
551
        if (PyObject_SetAttr(result, state->target, value) == -1)
5404
0
            goto failed;
5405
551
        Py_DECREF(value);
5406
551
        value = ast2obj_operator(state, o->v.AugAssign.op);
5407
551
        if (!value) goto failed;
5408
551
        if (PyObject_SetAttr(result, state->op, value) == -1)
5409
0
            goto failed;
5410
551
        Py_DECREF(value);
5411
551
        value = ast2obj_expr(state, o->v.AugAssign.value);
5412
551
        if (!value) goto failed;
5413
551
        if (PyObject_SetAttr(result, state->value, value) == -1)
5414
0
            goto failed;
5415
551
        Py_DECREF(value);
5416
551
        break;
5417
1.26k
    case AnnAssign_kind:
5418
1.26k
        tp = (PyTypeObject *)state->AnnAssign_type;
5419
1.26k
        result = PyType_GenericNew(tp, NULL, NULL);
5420
1.26k
        if (!result) goto failed;
5421
1.26k
        value = ast2obj_expr(state, o->v.AnnAssign.target);
5422
1.26k
        if (!value) goto failed;
5423
1.26k
        if (PyObject_SetAttr(result, state->target, value) == -1)
5424
0
            goto failed;
5425
1.26k
        Py_DECREF(value);
5426
1.26k
        value = ast2obj_expr(state, o->v.AnnAssign.annotation);
5427
1.26k
        if (!value) goto failed;
5428
1.26k
        if (PyObject_SetAttr(result, state->annotation, value) == -1)
5429
0
            goto failed;
5430
1.26k
        Py_DECREF(value);
5431
1.26k
        value = ast2obj_expr(state, o->v.AnnAssign.value);
5432
1.26k
        if (!value) goto failed;
5433
1.26k
        if (PyObject_SetAttr(result, state->value, value) == -1)
5434
0
            goto failed;
5435
1.26k
        Py_DECREF(value);
5436
1.26k
        value = ast2obj_int(state, o->v.AnnAssign.simple);
5437
1.26k
        if (!value) goto failed;
5438
1.26k
        if (PyObject_SetAttr(result, state->simple, value) == -1)
5439
0
            goto failed;
5440
1.26k
        Py_DECREF(value);
5441
1.26k
        break;
5442
280
    case For_kind:
5443
280
        tp = (PyTypeObject *)state->For_type;
5444
280
        result = PyType_GenericNew(tp, NULL, NULL);
5445
280
        if (!result) goto failed;
5446
280
        value = ast2obj_expr(state, o->v.For.target);
5447
280
        if (!value) goto failed;
5448
280
        if (PyObject_SetAttr(result, state->target, value) == -1)
5449
0
            goto failed;
5450
280
        Py_DECREF(value);
5451
280
        value = ast2obj_expr(state, o->v.For.iter);
5452
280
        if (!value) goto failed;
5453
280
        if (PyObject_SetAttr(result, state->iter, value) == -1)
5454
0
            goto failed;
5455
280
        Py_DECREF(value);
5456
280
        value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
5457
280
        if (!value) goto failed;
5458
280
        if (PyObject_SetAttr(result, state->body, value) == -1)
5459
0
            goto failed;
5460
280
        Py_DECREF(value);
5461
280
        value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
5462
280
        if (!value) goto failed;
5463
280
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5464
0
            goto failed;
5465
280
        Py_DECREF(value);
5466
280
        value = ast2obj_string(state, o->v.For.type_comment);
5467
280
        if (!value) goto failed;
5468
280
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5469
0
            goto failed;
5470
280
        Py_DECREF(value);
5471
280
        break;
5472
83
    case AsyncFor_kind:
5473
83
        tp = (PyTypeObject *)state->AsyncFor_type;
5474
83
        result = PyType_GenericNew(tp, NULL, NULL);
5475
83
        if (!result) goto failed;
5476
83
        value = ast2obj_expr(state, o->v.AsyncFor.target);
5477
83
        if (!value) goto failed;
5478
83
        if (PyObject_SetAttr(result, state->target, value) == -1)
5479
0
            goto failed;
5480
83
        Py_DECREF(value);
5481
83
        value = ast2obj_expr(state, o->v.AsyncFor.iter);
5482
83
        if (!value) goto failed;
5483
83
        if (PyObject_SetAttr(result, state->iter, value) == -1)
5484
0
            goto failed;
5485
83
        Py_DECREF(value);
5486
83
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
5487
83
                             ast2obj_stmt);
5488
83
        if (!value) goto failed;
5489
83
        if (PyObject_SetAttr(result, state->body, value) == -1)
5490
0
            goto failed;
5491
83
        Py_DECREF(value);
5492
83
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
5493
83
                             ast2obj_stmt);
5494
83
        if (!value) goto failed;
5495
83
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5496
0
            goto failed;
5497
83
        Py_DECREF(value);
5498
83
        value = ast2obj_string(state, o->v.AsyncFor.type_comment);
5499
83
        if (!value) goto failed;
5500
83
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5501
0
            goto failed;
5502
83
        Py_DECREF(value);
5503
83
        break;
5504
279
    case While_kind:
5505
279
        tp = (PyTypeObject *)state->While_type;
5506
279
        result = PyType_GenericNew(tp, NULL, NULL);
5507
279
        if (!result) goto failed;
5508
279
        value = ast2obj_expr(state, o->v.While.test);
5509
279
        if (!value) goto failed;
5510
279
        if (PyObject_SetAttr(result, state->test, value) == -1)
5511
0
            goto failed;
5512
279
        Py_DECREF(value);
5513
279
        value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
5514
279
        if (!value) goto failed;
5515
279
        if (PyObject_SetAttr(result, state->body, value) == -1)
5516
0
            goto failed;
5517
279
        Py_DECREF(value);
5518
279
        value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
5519
279
        if (!value) goto failed;
5520
279
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5521
0
            goto failed;
5522
279
        Py_DECREF(value);
5523
279
        break;
5524
485
    case If_kind:
5525
485
        tp = (PyTypeObject *)state->If_type;
5526
485
        result = PyType_GenericNew(tp, NULL, NULL);
5527
485
        if (!result) goto failed;
5528
485
        value = ast2obj_expr(state, o->v.If.test);
5529
485
        if (!value) goto failed;
5530
485
        if (PyObject_SetAttr(result, state->test, value) == -1)
5531
0
            goto failed;
5532
485
        Py_DECREF(value);
5533
485
        value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
5534
485
        if (!value) goto failed;
5535
485
        if (PyObject_SetAttr(result, state->body, value) == -1)
5536
0
            goto failed;
5537
485
        Py_DECREF(value);
5538
485
        value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
5539
485
        if (!value) goto failed;
5540
485
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5541
0
            goto failed;
5542
485
        Py_DECREF(value);
5543
485
        break;
5544
490
    case With_kind:
5545
490
        tp = (PyTypeObject *)state->With_type;
5546
490
        result = PyType_GenericNew(tp, NULL, NULL);
5547
490
        if (!result) goto failed;
5548
490
        value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
5549
490
                             ast2obj_withitem);
5550
490
        if (!value) goto failed;
5551
490
        if (PyObject_SetAttr(result, state->items, value) == -1)
5552
0
            goto failed;
5553
490
        Py_DECREF(value);
5554
490
        value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
5555
490
        if (!value) goto failed;
5556
490
        if (PyObject_SetAttr(result, state->body, value) == -1)
5557
0
            goto failed;
5558
490
        Py_DECREF(value);
5559
490
        value = ast2obj_string(state, o->v.With.type_comment);
5560
490
        if (!value) goto failed;
5561
490
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5562
0
            goto failed;
5563
490
        Py_DECREF(value);
5564
490
        break;
5565
152
    case AsyncWith_kind:
5566
152
        tp = (PyTypeObject *)state->AsyncWith_type;
5567
152
        result = PyType_GenericNew(tp, NULL, NULL);
5568
152
        if (!result) goto failed;
5569
152
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
5570
152
                             ast2obj_withitem);
5571
152
        if (!value) goto failed;
5572
152
        if (PyObject_SetAttr(result, state->items, value) == -1)
5573
0
            goto failed;
5574
152
        Py_DECREF(value);
5575
152
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
5576
152
                             ast2obj_stmt);
5577
152
        if (!value) goto failed;
5578
152
        if (PyObject_SetAttr(result, state->body, value) == -1)
5579
0
            goto failed;
5580
152
        Py_DECREF(value);
5581
152
        value = ast2obj_string(state, o->v.AsyncWith.type_comment);
5582
152
        if (!value) goto failed;
5583
152
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5584
0
            goto failed;
5585
152
        Py_DECREF(value);
5586
152
        break;
5587
285
    case Match_kind:
5588
285
        tp = (PyTypeObject *)state->Match_type;
5589
285
        result = PyType_GenericNew(tp, NULL, NULL);
5590
285
        if (!result) goto failed;
5591
285
        value = ast2obj_expr(state, o->v.Match.subject);
5592
285
        if (!value) goto failed;
5593
285
        if (PyObject_SetAttr(result, state->subject, value) == -1)
5594
0
            goto failed;
5595
285
        Py_DECREF(value);
5596
285
        value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
5597
285
                             ast2obj_match_case);
5598
285
        if (!value) goto failed;
5599
285
        if (PyObject_SetAttr(result, state->cases, value) == -1)
5600
0
            goto failed;
5601
285
        Py_DECREF(value);
5602
285
        break;
5603
648
    case Raise_kind:
5604
648
        tp = (PyTypeObject *)state->Raise_type;
5605
648
        result = PyType_GenericNew(tp, NULL, NULL);
5606
648
        if (!result) goto failed;
5607
648
        value = ast2obj_expr(state, o->v.Raise.exc);
5608
648
        if (!value) goto failed;
5609
648
        if (PyObject_SetAttr(result, state->exc, value) == -1)
5610
0
            goto failed;
5611
648
        Py_DECREF(value);
5612
648
        value = ast2obj_expr(state, o->v.Raise.cause);
5613
648
        if (!value) goto failed;
5614
648
        if (PyObject_SetAttr(result, state->cause, value) == -1)
5615
0
            goto failed;
5616
648
        Py_DECREF(value);
5617
648
        break;
5618
577
    case Try_kind:
5619
577
        tp = (PyTypeObject *)state->Try_type;
5620
577
        result = PyType_GenericNew(tp, NULL, NULL);
5621
577
        if (!result) goto failed;
5622
577
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
5623
577
        if (!value) goto failed;
5624
577
        if (PyObject_SetAttr(result, state->body, value) == -1)
5625
0
            goto failed;
5626
577
        Py_DECREF(value);
5627
577
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
5628
577
                             ast2obj_excepthandler);
5629
577
        if (!value) goto failed;
5630
577
        if (PyObject_SetAttr(result, state->handlers, value) == -1)
5631
0
            goto failed;
5632
577
        Py_DECREF(value);
5633
577
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
5634
577
        if (!value) goto failed;
5635
577
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5636
0
            goto failed;
5637
577
        Py_DECREF(value);
5638
577
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
5639
577
                             ast2obj_stmt);
5640
577
        if (!value) goto failed;
5641
577
        if (PyObject_SetAttr(result, state->finalbody, value) == -1)
5642
0
            goto failed;
5643
577
        Py_DECREF(value);
5644
577
        break;
5645
419
    case TryStar_kind:
5646
419
        tp = (PyTypeObject *)state->TryStar_type;
5647
419
        result = PyType_GenericNew(tp, NULL, NULL);
5648
419
        if (!result) goto failed;
5649
419
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.body, ast2obj_stmt);
5650
419
        if (!value) goto failed;
5651
419
        if (PyObject_SetAttr(result, state->body, value) == -1)
5652
0
            goto failed;
5653
419
        Py_DECREF(value);
5654
419
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.handlers,
5655
419
                             ast2obj_excepthandler);
5656
419
        if (!value) goto failed;
5657
419
        if (PyObject_SetAttr(result, state->handlers, value) == -1)
5658
0
            goto failed;
5659
419
        Py_DECREF(value);
5660
419
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.orelse,
5661
419
                             ast2obj_stmt);
5662
419
        if (!value) goto failed;
5663
419
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5664
0
            goto failed;
5665
419
        Py_DECREF(value);
5666
419
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.finalbody,
5667
419
                             ast2obj_stmt);
5668
419
        if (!value) goto failed;
5669
419
        if (PyObject_SetAttr(result, state->finalbody, value) == -1)
5670
0
            goto failed;
5671
419
        Py_DECREF(value);
5672
419
        break;
5673
158
    case Assert_kind:
5674
158
        tp = (PyTypeObject *)state->Assert_type;
5675
158
        result = PyType_GenericNew(tp, NULL, NULL);
5676
158
        if (!result) goto failed;
5677
158
        value = ast2obj_expr(state, o->v.Assert.test);
5678
158
        if (!value) goto failed;
5679
158
        if (PyObject_SetAttr(result, state->test, value) == -1)
5680
0
            goto failed;
5681
158
        Py_DECREF(value);
5682
158
        value = ast2obj_expr(state, o->v.Assert.msg);
5683
158
        if (!value) goto failed;
5684
158
        if (PyObject_SetAttr(result, state->msg, value) == -1)
5685
0
            goto failed;
5686
158
        Py_DECREF(value);
5687
158
        break;
5688
777
    case Import_kind:
5689
777
        tp = (PyTypeObject *)state->Import_type;
5690
777
        result = PyType_GenericNew(tp, NULL, NULL);
5691
777
        if (!result) goto failed;
5692
777
        value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
5693
777
                             ast2obj_alias);
5694
777
        if (!value) goto failed;
5695
777
        if (PyObject_SetAttr(result, state->names, value) == -1)
5696
0
            goto failed;
5697
777
        Py_DECREF(value);
5698
777
        value = ast2obj_int(state, o->v.Import.is_lazy);
5699
777
        if (!value) goto failed;
5700
777
        if (PyObject_SetAttr(result, state->is_lazy, value) == -1)
5701
0
            goto failed;
5702
777
        Py_DECREF(value);
5703
777
        break;
5704
1.04k
    case ImportFrom_kind:
5705
1.04k
        tp = (PyTypeObject *)state->ImportFrom_type;
5706
1.04k
        result = PyType_GenericNew(tp, NULL, NULL);
5707
1.04k
        if (!result) goto failed;
5708
1.04k
        value = ast2obj_identifier(state, o->v.ImportFrom.module);
5709
1.04k
        if (!value) goto failed;
5710
1.04k
        if (PyObject_SetAttr(result, state->module, value) == -1)
5711
0
            goto failed;
5712
1.04k
        Py_DECREF(value);
5713
1.04k
        value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
5714
1.04k
                             ast2obj_alias);
5715
1.04k
        if (!value) goto failed;
5716
1.04k
        if (PyObject_SetAttr(result, state->names, value) == -1)
5717
0
            goto failed;
5718
1.04k
        Py_DECREF(value);
5719
1.04k
        value = ast2obj_int(state, o->v.ImportFrom.level);
5720
1.04k
        if (!value) goto failed;
5721
1.04k
        if (PyObject_SetAttr(result, state->level, value) == -1)
5722
0
            goto failed;
5723
1.04k
        Py_DECREF(value);
5724
1.04k
        value = ast2obj_int(state, o->v.ImportFrom.is_lazy);
5725
1.04k
        if (!value) goto failed;
5726
1.04k
        if (PyObject_SetAttr(result, state->is_lazy, value) == -1)
5727
0
            goto failed;
5728
1.04k
        Py_DECREF(value);
5729
1.04k
        break;
5730
280
    case Global_kind:
5731
280
        tp = (PyTypeObject *)state->Global_type;
5732
280
        result = PyType_GenericNew(tp, NULL, NULL);
5733
280
        if (!result) goto failed;
5734
280
        value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
5735
280
                             ast2obj_identifier);
5736
280
        if (!value) goto failed;
5737
280
        if (PyObject_SetAttr(result, state->names, value) == -1)
5738
0
            goto failed;
5739
280
        Py_DECREF(value);
5740
280
        break;
5741
194
    case Nonlocal_kind:
5742
194
        tp = (PyTypeObject *)state->Nonlocal_type;
5743
194
        result = PyType_GenericNew(tp, NULL, NULL);
5744
194
        if (!result) goto failed;
5745
194
        value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
5746
194
                             ast2obj_identifier);
5747
194
        if (!value) goto failed;
5748
194
        if (PyObject_SetAttr(result, state->names, value) == -1)
5749
0
            goto failed;
5750
194
        Py_DECREF(value);
5751
194
        break;
5752
35.1k
    case Expr_kind:
5753
35.1k
        tp = (PyTypeObject *)state->Expr_type;
5754
35.1k
        result = PyType_GenericNew(tp, NULL, NULL);
5755
35.1k
        if (!result) goto failed;
5756
35.1k
        value = ast2obj_expr(state, o->v.Expr.value);
5757
35.1k
        if (!value) goto failed;
5758
35.1k
        if (PyObject_SetAttr(result, state->value, value) == -1)
5759
0
            goto failed;
5760
35.1k
        Py_DECREF(value);
5761
35.1k
        break;
5762
228
    case Pass_kind:
5763
228
        tp = (PyTypeObject *)state->Pass_type;
5764
228
        result = PyType_GenericNew(tp, NULL, NULL);
5765
228
        if (!result) goto failed;
5766
228
        break;
5767
235
    case Break_kind:
5768
235
        tp = (PyTypeObject *)state->Break_type;
5769
235
        result = PyType_GenericNew(tp, NULL, NULL);
5770
235
        if (!result) goto failed;
5771
235
        break;
5772
235
    case Continue_kind:
5773
231
        tp = (PyTypeObject *)state->Continue_type;
5774
231
        result = PyType_GenericNew(tp, NULL, NULL);
5775
231
        if (!result) goto failed;
5776
231
        break;
5777
48.5k
    }
5778
48.5k
    value = ast2obj_int(state, o->lineno);
5779
48.5k
    if (!value) goto failed;
5780
48.5k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
5781
0
        goto failed;
5782
48.5k
    Py_DECREF(value);
5783
48.5k
    value = ast2obj_int(state, o->col_offset);
5784
48.5k
    if (!value) goto failed;
5785
48.5k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5786
0
        goto failed;
5787
48.5k
    Py_DECREF(value);
5788
48.5k
    value = ast2obj_int(state, o->end_lineno);
5789
48.5k
    if (!value) goto failed;
5790
48.5k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5791
0
        goto failed;
5792
48.5k
    Py_DECREF(value);
5793
48.5k
    value = ast2obj_int(state, o->end_col_offset);
5794
48.5k
    if (!value) goto failed;
5795
48.5k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5796
0
        goto failed;
5797
48.5k
    Py_DECREF(value);
5798
48.5k
    Py_LeaveRecursiveCall();
5799
48.5k
    return result;
5800
0
failed:
5801
0
    Py_LeaveRecursiveCall();
5802
0
    Py_XDECREF(value);
5803
0
    Py_XDECREF(result);
5804
0
    return NULL;
5805
48.5k
}
5806
5807
PyObject*
5808
ast2obj_expr(struct ast_state *state, void* _o)
5809
363k
{
5810
363k
    expr_ty o = (expr_ty)_o;
5811
363k
    PyObject *result = NULL, *value = NULL;
5812
363k
    PyTypeObject *tp;
5813
363k
    if (!o) {
5814
46.3k
        Py_RETURN_NONE;
5815
46.3k
    }
5816
316k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5817
0
        return NULL;
5818
0
    }
5819
316k
    switch (o->kind) {
5820
814
    case BoolOp_kind:
5821
814
        tp = (PyTypeObject *)state->BoolOp_type;
5822
814
        result = PyType_GenericNew(tp, NULL, NULL);
5823
814
        if (!result) goto failed;
5824
814
        value = ast2obj_boolop(state, o->v.BoolOp.op);
5825
814
        if (!value) goto failed;
5826
814
        if (PyObject_SetAttr(result, state->op, value) == -1)
5827
0
            goto failed;
5828
814
        Py_DECREF(value);
5829
814
        value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
5830
814
                             ast2obj_expr);
5831
814
        if (!value) goto failed;
5832
814
        if (PyObject_SetAttr(result, state->values, value) == -1)
5833
0
            goto failed;
5834
814
        Py_DECREF(value);
5835
814
        break;
5836
103
    case NamedExpr_kind:
5837
103
        tp = (PyTypeObject *)state->NamedExpr_type;
5838
103
        result = PyType_GenericNew(tp, NULL, NULL);
5839
103
        if (!result) goto failed;
5840
103
        value = ast2obj_expr(state, o->v.NamedExpr.target);
5841
103
        if (!value) goto failed;
5842
103
        if (PyObject_SetAttr(result, state->target, value) == -1)
5843
0
            goto failed;
5844
103
        Py_DECREF(value);
5845
103
        value = ast2obj_expr(state, o->v.NamedExpr.value);
5846
103
        if (!value) goto failed;
5847
103
        if (PyObject_SetAttr(result, state->value, value) == -1)
5848
0
            goto failed;
5849
103
        Py_DECREF(value);
5850
103
        break;
5851
25.1k
    case BinOp_kind:
5852
25.1k
        tp = (PyTypeObject *)state->BinOp_type;
5853
25.1k
        result = PyType_GenericNew(tp, NULL, NULL);
5854
25.1k
        if (!result) goto failed;
5855
25.1k
        value = ast2obj_expr(state, o->v.BinOp.left);
5856
25.1k
        if (!value) goto failed;
5857
25.1k
        if (PyObject_SetAttr(result, state->left, value) == -1)
5858
0
            goto failed;
5859
25.1k
        Py_DECREF(value);
5860
25.1k
        value = ast2obj_operator(state, o->v.BinOp.op);
5861
25.1k
        if (!value) goto failed;
5862
25.1k
        if (PyObject_SetAttr(result, state->op, value) == -1)
5863
0
            goto failed;
5864
25.1k
        Py_DECREF(value);
5865
25.1k
        value = ast2obj_expr(state, o->v.BinOp.right);
5866
25.1k
        if (!value) goto failed;
5867
25.1k
        if (PyObject_SetAttr(result, state->right, value) == -1)
5868
0
            goto failed;
5869
25.1k
        Py_DECREF(value);
5870
25.1k
        break;
5871
111k
    case UnaryOp_kind:
5872
111k
        tp = (PyTypeObject *)state->UnaryOp_type;
5873
111k
        result = PyType_GenericNew(tp, NULL, NULL);
5874
111k
        if (!result) goto failed;
5875
111k
        value = ast2obj_unaryop(state, o->v.UnaryOp.op);
5876
111k
        if (!value) goto failed;
5877
111k
        if (PyObject_SetAttr(result, state->op, value) == -1)
5878
0
            goto failed;
5879
111k
        Py_DECREF(value);
5880
111k
        value = ast2obj_expr(state, o->v.UnaryOp.operand);
5881
111k
        if (!value) goto failed;
5882
111k
        if (PyObject_SetAttr(result, state->operand, value) == -1)
5883
0
            goto failed;
5884
111k
        Py_DECREF(value);
5885
111k
        break;
5886
1.24k
    case Lambda_kind:
5887
1.24k
        tp = (PyTypeObject *)state->Lambda_type;
5888
1.24k
        result = PyType_GenericNew(tp, NULL, NULL);
5889
1.24k
        if (!result) goto failed;
5890
1.24k
        value = ast2obj_arguments(state, o->v.Lambda.args);
5891
1.24k
        if (!value) goto failed;
5892
1.24k
        if (PyObject_SetAttr(result, state->args, value) == -1)
5893
0
            goto failed;
5894
1.24k
        Py_DECREF(value);
5895
1.24k
        value = ast2obj_expr(state, o->v.Lambda.body);
5896
1.24k
        if (!value) goto failed;
5897
1.24k
        if (PyObject_SetAttr(result, state->body, value) == -1)
5898
0
            goto failed;
5899
1.24k
        Py_DECREF(value);
5900
1.24k
        break;
5901
199
    case IfExp_kind:
5902
199
        tp = (PyTypeObject *)state->IfExp_type;
5903
199
        result = PyType_GenericNew(tp, NULL, NULL);
5904
199
        if (!result) goto failed;
5905
199
        value = ast2obj_expr(state, o->v.IfExp.test);
5906
199
        if (!value) goto failed;
5907
199
        if (PyObject_SetAttr(result, state->test, value) == -1)
5908
0
            goto failed;
5909
199
        Py_DECREF(value);
5910
199
        value = ast2obj_expr(state, o->v.IfExp.body);
5911
199
        if (!value) goto failed;
5912
199
        if (PyObject_SetAttr(result, state->body, value) == -1)
5913
0
            goto failed;
5914
199
        Py_DECREF(value);
5915
199
        value = ast2obj_expr(state, o->v.IfExp.orelse);
5916
199
        if (!value) goto failed;
5917
199
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5918
0
            goto failed;
5919
199
        Py_DECREF(value);
5920
199
        break;
5921
998
    case Dict_kind:
5922
998
        tp = (PyTypeObject *)state->Dict_type;
5923
998
        result = PyType_GenericNew(tp, NULL, NULL);
5924
998
        if (!result) goto failed;
5925
998
        value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
5926
998
        if (!value) goto failed;
5927
998
        if (PyObject_SetAttr(result, state->keys, value) == -1)
5928
0
            goto failed;
5929
998
        Py_DECREF(value);
5930
998
        value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
5931
998
        if (!value) goto failed;
5932
998
        if (PyObject_SetAttr(result, state->values, value) == -1)
5933
0
            goto failed;
5934
998
        Py_DECREF(value);
5935
998
        break;
5936
414
    case Set_kind:
5937
414
        tp = (PyTypeObject *)state->Set_type;
5938
414
        result = PyType_GenericNew(tp, NULL, NULL);
5939
414
        if (!result) goto failed;
5940
414
        value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
5941
414
        if (!value) goto failed;
5942
414
        if (PyObject_SetAttr(result, state->elts, value) == -1)
5943
0
            goto failed;
5944
414
        Py_DECREF(value);
5945
414
        break;
5946
262
    case ListComp_kind:
5947
262
        tp = (PyTypeObject *)state->ListComp_type;
5948
262
        result = PyType_GenericNew(tp, NULL, NULL);
5949
262
        if (!result) goto failed;
5950
262
        value = ast2obj_expr(state, o->v.ListComp.elt);
5951
262
        if (!value) goto failed;
5952
262
        if (PyObject_SetAttr(result, state->elt, value) == -1)
5953
0
            goto failed;
5954
262
        Py_DECREF(value);
5955
262
        value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
5956
262
                             ast2obj_comprehension);
5957
262
        if (!value) goto failed;
5958
262
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5959
0
            goto failed;
5960
262
        Py_DECREF(value);
5961
262
        break;
5962
281
    case SetComp_kind:
5963
281
        tp = (PyTypeObject *)state->SetComp_type;
5964
281
        result = PyType_GenericNew(tp, NULL, NULL);
5965
281
        if (!result) goto failed;
5966
281
        value = ast2obj_expr(state, o->v.SetComp.elt);
5967
281
        if (!value) goto failed;
5968
281
        if (PyObject_SetAttr(result, state->elt, value) == -1)
5969
0
            goto failed;
5970
281
        Py_DECREF(value);
5971
281
        value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
5972
281
                             ast2obj_comprehension);
5973
281
        if (!value) goto failed;
5974
281
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5975
0
            goto failed;
5976
281
        Py_DECREF(value);
5977
281
        break;
5978
430
    case DictComp_kind:
5979
430
        tp = (PyTypeObject *)state->DictComp_type;
5980
430
        result = PyType_GenericNew(tp, NULL, NULL);
5981
430
        if (!result) goto failed;
5982
430
        value = ast2obj_expr(state, o->v.DictComp.key);
5983
430
        if (!value) goto failed;
5984
430
        if (PyObject_SetAttr(result, state->key, value) == -1)
5985
0
            goto failed;
5986
430
        Py_DECREF(value);
5987
430
        value = ast2obj_expr(state, o->v.DictComp.value);
5988
430
        if (!value) goto failed;
5989
430
        if (PyObject_SetAttr(result, state->value, value) == -1)
5990
0
            goto failed;
5991
430
        Py_DECREF(value);
5992
430
        value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
5993
430
                             ast2obj_comprehension);
5994
430
        if (!value) goto failed;
5995
430
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5996
0
            goto failed;
5997
430
        Py_DECREF(value);
5998
430
        break;
5999
573
    case GeneratorExp_kind:
6000
573
        tp = (PyTypeObject *)state->GeneratorExp_type;
6001
573
        result = PyType_GenericNew(tp, NULL, NULL);
6002
573
        if (!result) goto failed;
6003
573
        value = ast2obj_expr(state, o->v.GeneratorExp.elt);
6004
573
        if (!value) goto failed;
6005
573
        if (PyObject_SetAttr(result, state->elt, value) == -1)
6006
0
            goto failed;
6007
573
        Py_DECREF(value);
6008
573
        value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
6009
573
                             ast2obj_comprehension);
6010
573
        if (!value) goto failed;
6011
573
        if (PyObject_SetAttr(result, state->generators, value) == -1)
6012
0
            goto failed;
6013
573
        Py_DECREF(value);
6014
573
        break;
6015
67
    case Await_kind:
6016
67
        tp = (PyTypeObject *)state->Await_type;
6017
67
        result = PyType_GenericNew(tp, NULL, NULL);
6018
67
        if (!result) goto failed;
6019
67
        value = ast2obj_expr(state, o->v.Await.value);
6020
67
        if (!value) goto failed;
6021
67
        if (PyObject_SetAttr(result, state->value, value) == -1)
6022
0
            goto failed;
6023
67
        Py_DECREF(value);
6024
67
        break;
6025
344
    case Yield_kind:
6026
344
        tp = (PyTypeObject *)state->Yield_type;
6027
344
        result = PyType_GenericNew(tp, NULL, NULL);
6028
344
        if (!result) goto failed;
6029
344
        value = ast2obj_expr(state, o->v.Yield.value);
6030
344
        if (!value) goto failed;
6031
344
        if (PyObject_SetAttr(result, state->value, value) == -1)
6032
0
            goto failed;
6033
344
        Py_DECREF(value);
6034
344
        break;
6035
70
    case YieldFrom_kind:
6036
70
        tp = (PyTypeObject *)state->YieldFrom_type;
6037
70
        result = PyType_GenericNew(tp, NULL, NULL);
6038
70
        if (!result) goto failed;
6039
70
        value = ast2obj_expr(state, o->v.YieldFrom.value);
6040
70
        if (!value) goto failed;
6041
70
        if (PyObject_SetAttr(result, state->value, value) == -1)
6042
0
            goto failed;
6043
70
        Py_DECREF(value);
6044
70
        break;
6045
2.15k
    case Compare_kind:
6046
2.15k
        tp = (PyTypeObject *)state->Compare_type;
6047
2.15k
        result = PyType_GenericNew(tp, NULL, NULL);
6048
2.15k
        if (!result) goto failed;
6049
2.15k
        value = ast2obj_expr(state, o->v.Compare.left);
6050
2.15k
        if (!value) goto failed;
6051
2.15k
        if (PyObject_SetAttr(result, state->left, value) == -1)
6052
0
            goto failed;
6053
2.15k
        Py_DECREF(value);
6054
2.15k
        {
6055
2.15k
            Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
6056
2.15k
            value = PyList_New(n);
6057
2.15k
            if (!value) goto failed;
6058
8.73k
            for(i = 0; i < n; i++)
6059
6.57k
                PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
6060
2.15k
        }
6061
2.15k
        if (!value) goto failed;
6062
2.15k
        if (PyObject_SetAttr(result, state->ops, value) == -1)
6063
0
            goto failed;
6064
2.15k
        Py_DECREF(value);
6065
2.15k
        value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
6066
2.15k
                             ast2obj_expr);
6067
2.15k
        if (!value) goto failed;
6068
2.15k
        if (PyObject_SetAttr(result, state->comparators, value) == -1)
6069
0
            goto failed;
6070
2.15k
        Py_DECREF(value);
6071
2.15k
        break;
6072
3.95k
    case Call_kind:
6073
3.95k
        tp = (PyTypeObject *)state->Call_type;
6074
3.95k
        result = PyType_GenericNew(tp, NULL, NULL);
6075
3.95k
        if (!result) goto failed;
6076
3.95k
        value = ast2obj_expr(state, o->v.Call.func);
6077
3.95k
        if (!value) goto failed;
6078
3.95k
        if (PyObject_SetAttr(result, state->func, value) == -1)
6079
0
            goto failed;
6080
3.95k
        Py_DECREF(value);
6081
3.95k
        value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
6082
3.95k
        if (!value) goto failed;
6083
3.95k
        if (PyObject_SetAttr(result, state->args, value) == -1)
6084
0
            goto failed;
6085
3.95k
        Py_DECREF(value);
6086
3.95k
        value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
6087
3.95k
                             ast2obj_keyword);
6088
3.95k
        if (!value) goto failed;
6089
3.95k
        if (PyObject_SetAttr(result, state->keywords, value) == -1)
6090
0
            goto failed;
6091
3.95k
        Py_DECREF(value);
6092
3.95k
        break;
6093
12.2k
    case FormattedValue_kind:
6094
12.2k
        tp = (PyTypeObject *)state->FormattedValue_type;
6095
12.2k
        result = PyType_GenericNew(tp, NULL, NULL);
6096
12.2k
        if (!result) goto failed;
6097
12.2k
        value = ast2obj_expr(state, o->v.FormattedValue.value);
6098
12.2k
        if (!value) goto failed;
6099
12.2k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6100
0
            goto failed;
6101
12.2k
        Py_DECREF(value);
6102
12.2k
        value = ast2obj_int(state, o->v.FormattedValue.conversion);
6103
12.2k
        if (!value) goto failed;
6104
12.2k
        if (PyObject_SetAttr(result, state->conversion, value) == -1)
6105
0
            goto failed;
6106
12.2k
        Py_DECREF(value);
6107
12.2k
        value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
6108
12.2k
        if (!value) goto failed;
6109
12.2k
        if (PyObject_SetAttr(result, state->format_spec, value) == -1)
6110
0
            goto failed;
6111
12.2k
        Py_DECREF(value);
6112
12.2k
        break;
6113
2.60k
    case Interpolation_kind:
6114
2.60k
        tp = (PyTypeObject *)state->Interpolation_type;
6115
2.60k
        result = PyType_GenericNew(tp, NULL, NULL);
6116
2.60k
        if (!result) goto failed;
6117
2.60k
        value = ast2obj_expr(state, o->v.Interpolation.value);
6118
2.60k
        if (!value) goto failed;
6119
2.60k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6120
0
            goto failed;
6121
2.60k
        Py_DECREF(value);
6122
2.60k
        value = ast2obj_constant(state, o->v.Interpolation.str);
6123
2.60k
        if (!value) goto failed;
6124
2.60k
        if (PyObject_SetAttr(result, state->str, value) == -1)
6125
0
            goto failed;
6126
2.60k
        Py_DECREF(value);
6127
2.60k
        value = ast2obj_int(state, o->v.Interpolation.conversion);
6128
2.60k
        if (!value) goto failed;
6129
2.60k
        if (PyObject_SetAttr(result, state->conversion, value) == -1)
6130
0
            goto failed;
6131
2.60k
        Py_DECREF(value);
6132
2.60k
        value = ast2obj_expr(state, o->v.Interpolation.format_spec);
6133
2.60k
        if (!value) goto failed;
6134
2.60k
        if (PyObject_SetAttr(result, state->format_spec, value) == -1)
6135
0
            goto failed;
6136
2.60k
        Py_DECREF(value);
6137
2.60k
        break;
6138
7.56k
    case JoinedStr_kind:
6139
7.56k
        tp = (PyTypeObject *)state->JoinedStr_type;
6140
7.56k
        result = PyType_GenericNew(tp, NULL, NULL);
6141
7.56k
        if (!result) goto failed;
6142
7.56k
        value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
6143
7.56k
                             ast2obj_expr);
6144
7.56k
        if (!value) goto failed;
6145
7.56k
        if (PyObject_SetAttr(result, state->values, value) == -1)
6146
0
            goto failed;
6147
7.56k
        Py_DECREF(value);
6148
7.56k
        break;
6149
393
    case TemplateStr_kind:
6150
393
        tp = (PyTypeObject *)state->TemplateStr_type;
6151
393
        result = PyType_GenericNew(tp, NULL, NULL);
6152
393
        if (!result) goto failed;
6153
393
        value = ast2obj_list(state, (asdl_seq*)o->v.TemplateStr.values,
6154
393
                             ast2obj_expr);
6155
393
        if (!value) goto failed;
6156
393
        if (PyObject_SetAttr(result, state->values, value) == -1)
6157
0
            goto failed;
6158
393
        Py_DECREF(value);
6159
393
        break;
6160
58.9k
    case Constant_kind:
6161
58.9k
        tp = (PyTypeObject *)state->Constant_type;
6162
58.9k
        result = PyType_GenericNew(tp, NULL, NULL);
6163
58.9k
        if (!result) goto failed;
6164
58.9k
        value = ast2obj_constant(state, o->v.Constant.value);
6165
58.9k
        if (!value) goto failed;
6166
58.9k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6167
0
            goto failed;
6168
58.9k
        Py_DECREF(value);
6169
58.9k
        value = ast2obj_string(state, o->v.Constant.kind);
6170
58.9k
        if (!value) goto failed;
6171
58.9k
        if (PyObject_SetAttr(result, state->kind, value) == -1)
6172
0
            goto failed;
6173
58.9k
        Py_DECREF(value);
6174
58.9k
        break;
6175
2.50k
    case Attribute_kind:
6176
2.50k
        tp = (PyTypeObject *)state->Attribute_type;
6177
2.50k
        result = PyType_GenericNew(tp, NULL, NULL);
6178
2.50k
        if (!result) goto failed;
6179
2.50k
        value = ast2obj_expr(state, o->v.Attribute.value);
6180
2.50k
        if (!value) goto failed;
6181
2.50k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6182
0
            goto failed;
6183
2.50k
        Py_DECREF(value);
6184
2.50k
        value = ast2obj_identifier(state, o->v.Attribute.attr);
6185
2.50k
        if (!value) goto failed;
6186
2.50k
        if (PyObject_SetAttr(result, state->attr, value) == -1)
6187
0
            goto failed;
6188
2.50k
        Py_DECREF(value);
6189
2.50k
        value = ast2obj_expr_context(state, o->v.Attribute.ctx);
6190
2.50k
        if (!value) goto failed;
6191
2.50k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6192
0
            goto failed;
6193
2.50k
        Py_DECREF(value);
6194
2.50k
        break;
6195
803
    case Subscript_kind:
6196
803
        tp = (PyTypeObject *)state->Subscript_type;
6197
803
        result = PyType_GenericNew(tp, NULL, NULL);
6198
803
        if (!result) goto failed;
6199
803
        value = ast2obj_expr(state, o->v.Subscript.value);
6200
803
        if (!value) goto failed;
6201
803
        if (PyObject_SetAttr(result, state->value, value) == -1)
6202
0
            goto failed;
6203
803
        Py_DECREF(value);
6204
803
        value = ast2obj_expr(state, o->v.Subscript.slice);
6205
803
        if (!value) goto failed;
6206
803
        if (PyObject_SetAttr(result, state->slice, value) == -1)
6207
0
            goto failed;
6208
803
        Py_DECREF(value);
6209
803
        value = ast2obj_expr_context(state, o->v.Subscript.ctx);
6210
803
        if (!value) goto failed;
6211
803
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6212
0
            goto failed;
6213
803
        Py_DECREF(value);
6214
803
        break;
6215
1.11k
    case Starred_kind:
6216
1.11k
        tp = (PyTypeObject *)state->Starred_type;
6217
1.11k
        result = PyType_GenericNew(tp, NULL, NULL);
6218
1.11k
        if (!result) goto failed;
6219
1.11k
        value = ast2obj_expr(state, o->v.Starred.value);
6220
1.11k
        if (!value) goto failed;
6221
1.11k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6222
0
            goto failed;
6223
1.11k
        Py_DECREF(value);
6224
1.11k
        value = ast2obj_expr_context(state, o->v.Starred.ctx);
6225
1.11k
        if (!value) goto failed;
6226
1.11k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6227
0
            goto failed;
6228
1.11k
        Py_DECREF(value);
6229
1.11k
        break;
6230
72.0k
    case Name_kind:
6231
72.0k
        tp = (PyTypeObject *)state->Name_type;
6232
72.0k
        result = PyType_GenericNew(tp, NULL, NULL);
6233
72.0k
        if (!result) goto failed;
6234
72.0k
        value = ast2obj_identifier(state, o->v.Name.id);
6235
72.0k
        if (!value) goto failed;
6236
72.0k
        if (PyObject_SetAttr(result, state->id, value) == -1)
6237
0
            goto failed;
6238
72.0k
        Py_DECREF(value);
6239
72.0k
        value = ast2obj_expr_context(state, o->v.Name.ctx);
6240
72.0k
        if (!value) goto failed;
6241
72.0k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6242
0
            goto failed;
6243
72.0k
        Py_DECREF(value);
6244
72.0k
        break;
6245
1.04k
    case List_kind:
6246
1.04k
        tp = (PyTypeObject *)state->List_type;
6247
1.04k
        result = PyType_GenericNew(tp, NULL, NULL);
6248
1.04k
        if (!result) goto failed;
6249
1.04k
        value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
6250
1.04k
        if (!value) goto failed;
6251
1.04k
        if (PyObject_SetAttr(result, state->elts, value) == -1)
6252
0
            goto failed;
6253
1.04k
        Py_DECREF(value);
6254
1.04k
        value = ast2obj_expr_context(state, o->v.List.ctx);
6255
1.04k
        if (!value) goto failed;
6256
1.04k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6257
0
            goto failed;
6258
1.04k
        Py_DECREF(value);
6259
1.04k
        break;
6260
6.29k
    case Tuple_kind:
6261
6.29k
        tp = (PyTypeObject *)state->Tuple_type;
6262
6.29k
        result = PyType_GenericNew(tp, NULL, NULL);
6263
6.29k
        if (!result) goto failed;
6264
6.29k
        value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
6265
6.29k
        if (!value) goto failed;
6266
6.29k
        if (PyObject_SetAttr(result, state->elts, value) == -1)
6267
0
            goto failed;
6268
6.29k
        Py_DECREF(value);
6269
6.29k
        value = ast2obj_expr_context(state, o->v.Tuple.ctx);
6270
6.29k
        if (!value) goto failed;
6271
6.29k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6272
0
            goto failed;
6273
6.29k
        Py_DECREF(value);
6274
6.29k
        break;
6275
2.43k
    case Slice_kind:
6276
2.43k
        tp = (PyTypeObject *)state->Slice_type;
6277
2.43k
        result = PyType_GenericNew(tp, NULL, NULL);
6278
2.43k
        if (!result) goto failed;
6279
2.43k
        value = ast2obj_expr(state, o->v.Slice.lower);
6280
2.43k
        if (!value) goto failed;
6281
2.43k
        if (PyObject_SetAttr(result, state->lower, value) == -1)
6282
0
            goto failed;
6283
2.43k
        Py_DECREF(value);
6284
2.43k
        value = ast2obj_expr(state, o->v.Slice.upper);
6285
2.43k
        if (!value) goto failed;
6286
2.43k
        if (PyObject_SetAttr(result, state->upper, value) == -1)
6287
0
            goto failed;
6288
2.43k
        Py_DECREF(value);
6289
2.43k
        value = ast2obj_expr(state, o->v.Slice.step);
6290
2.43k
        if (!value) goto failed;
6291
2.43k
        if (PyObject_SetAttr(result, state->step, value) == -1)
6292
0
            goto failed;
6293
2.43k
        Py_DECREF(value);
6294
2.43k
        break;
6295
316k
    }
6296
316k
    value = ast2obj_int(state, o->lineno);
6297
316k
    if (!value) goto failed;
6298
316k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6299
0
        goto failed;
6300
316k
    Py_DECREF(value);
6301
316k
    value = ast2obj_int(state, o->col_offset);
6302
316k
    if (!value) goto failed;
6303
316k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6304
0
        goto failed;
6305
316k
    Py_DECREF(value);
6306
316k
    value = ast2obj_int(state, o->end_lineno);
6307
316k
    if (!value) goto failed;
6308
316k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6309
0
        goto failed;
6310
316k
    Py_DECREF(value);
6311
316k
    value = ast2obj_int(state, o->end_col_offset);
6312
316k
    if (!value) goto failed;
6313
316k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6314
0
        goto failed;
6315
316k
    Py_DECREF(value);
6316
316k
    Py_LeaveRecursiveCall();
6317
316k
    return result;
6318
0
failed:
6319
0
    Py_LeaveRecursiveCall();
6320
0
    Py_XDECREF(value);
6321
0
    Py_XDECREF(result);
6322
0
    return NULL;
6323
316k
}
6324
6325
PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
6326
83.8k
{
6327
83.8k
    switch(o) {
6328
77.2k
        case Load:
6329
77.2k
            return Py_NewRef(state->Load_singleton);
6330
5.80k
        case Store:
6331
5.80k
            return Py_NewRef(state->Store_singleton);
6332
745
        case Del:
6333
745
            return Py_NewRef(state->Del_singleton);
6334
83.8k
    }
6335
83.8k
    Py_UNREACHABLE();
6336
83.8k
}
6337
PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
6338
814
{
6339
814
    switch(o) {
6340
244
        case And:
6341
244
            return Py_NewRef(state->And_singleton);
6342
570
        case Or:
6343
570
            return Py_NewRef(state->Or_singleton);
6344
814
    }
6345
814
    Py_UNREACHABLE();
6346
814
}
6347
PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
6348
25.6k
{
6349
25.6k
    switch(o) {
6350
4.67k
        case Add:
6351
4.67k
            return Py_NewRef(state->Add_singleton);
6352
9.30k
        case Sub:
6353
9.30k
            return Py_NewRef(state->Sub_singleton);
6354
4.74k
        case Mult:
6355
4.74k
            return Py_NewRef(state->Mult_singleton);
6356
791
        case MatMult:
6357
791
            return Py_NewRef(state->MatMult_singleton);
6358
985
        case Div:
6359
985
            return Py_NewRef(state->Div_singleton);
6360
1.17k
        case Mod:
6361
1.17k
            return Py_NewRef(state->Mod_singleton);
6362
686
        case Pow:
6363
686
            return Py_NewRef(state->Pow_singleton);
6364
584
        case LShift:
6365
584
            return Py_NewRef(state->LShift_singleton);
6366
277
        case RShift:
6367
277
            return Py_NewRef(state->RShift_singleton);
6368
934
        case BitOr:
6369
934
            return Py_NewRef(state->BitOr_singleton);
6370
392
        case BitXor:
6371
392
            return Py_NewRef(state->BitXor_singleton);
6372
913
        case BitAnd:
6373
913
            return Py_NewRef(state->BitAnd_singleton);
6374
215
        case FloorDiv:
6375
215
            return Py_NewRef(state->FloorDiv_singleton);
6376
25.6k
    }
6377
25.6k
    Py_UNREACHABLE();
6378
25.6k
}
6379
PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
6380
111k
{
6381
111k
    switch(o) {
6382
53.5k
        case Invert:
6383
53.5k
            return Py_NewRef(state->Invert_singleton);
6384
93
        case Not:
6385
93
            return Py_NewRef(state->Not_singleton);
6386
27.4k
        case UAdd:
6387
27.4k
            return Py_NewRef(state->UAdd_singleton);
6388
30.6k
        case USub:
6389
30.6k
            return Py_NewRef(state->USub_singleton);
6390
111k
    }
6391
111k
    Py_UNREACHABLE();
6392
111k
}
6393
PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
6394
6.57k
{
6395
6.57k
    switch(o) {
6396
369
        case Eq:
6397
369
            return Py_NewRef(state->Eq_singleton);
6398
237
        case NotEq:
6399
237
            return Py_NewRef(state->NotEq_singleton);
6400
2.79k
        case Lt:
6401
2.79k
            return Py_NewRef(state->Lt_singleton);
6402
206
        case LtE:
6403
206
            return Py_NewRef(state->LtE_singleton);
6404
2.07k
        case Gt:
6405
2.07k
            return Py_NewRef(state->Gt_singleton);
6406
258
        case GtE:
6407
258
            return Py_NewRef(state->GtE_singleton);
6408
245
        case Is:
6409
245
            return Py_NewRef(state->Is_singleton);
6410
76
        case IsNot:
6411
76
            return Py_NewRef(state->IsNot_singleton);
6412
125
        case In:
6413
125
            return Py_NewRef(state->In_singleton);
6414
197
        case NotIn:
6415
197
            return Py_NewRef(state->NotIn_singleton);
6416
6.57k
    }
6417
6.57k
    Py_UNREACHABLE();
6418
6.57k
}
6419
PyObject*
6420
ast2obj_comprehension(struct ast_state *state, void* _o)
6421
1.59k
{
6422
1.59k
    comprehension_ty o = (comprehension_ty)_o;
6423
1.59k
    PyObject *result = NULL, *value = NULL;
6424
1.59k
    PyTypeObject *tp;
6425
1.59k
    if (!o) {
6426
0
        Py_RETURN_NONE;
6427
0
    }
6428
1.59k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6429
0
        return NULL;
6430
0
    }
6431
1.59k
    tp = (PyTypeObject *)state->comprehension_type;
6432
1.59k
    result = PyType_GenericNew(tp, NULL, NULL);
6433
1.59k
    if (!result) return NULL;
6434
1.59k
    value = ast2obj_expr(state, o->target);
6435
1.59k
    if (!value) goto failed;
6436
1.59k
    if (PyObject_SetAttr(result, state->target, value) == -1)
6437
0
        goto failed;
6438
1.59k
    Py_DECREF(value);
6439
1.59k
    value = ast2obj_expr(state, o->iter);
6440
1.59k
    if (!value) goto failed;
6441
1.59k
    if (PyObject_SetAttr(result, state->iter, value) == -1)
6442
0
        goto failed;
6443
1.59k
    Py_DECREF(value);
6444
1.59k
    value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
6445
1.59k
    if (!value) goto failed;
6446
1.59k
    if (PyObject_SetAttr(result, state->ifs, value) == -1)
6447
0
        goto failed;
6448
1.59k
    Py_DECREF(value);
6449
1.59k
    value = ast2obj_int(state, o->is_async);
6450
1.59k
    if (!value) goto failed;
6451
1.59k
    if (PyObject_SetAttr(result, state->is_async, value) == -1)
6452
0
        goto failed;
6453
1.59k
    Py_DECREF(value);
6454
1.59k
    Py_LeaveRecursiveCall();
6455
1.59k
    return result;
6456
0
failed:
6457
0
    Py_LeaveRecursiveCall();
6458
0
    Py_XDECREF(value);
6459
0
    Py_XDECREF(result);
6460
0
    return NULL;
6461
1.59k
}
6462
6463
PyObject*
6464
ast2obj_excepthandler(struct ast_state *state, void* _o)
6465
1.32k
{
6466
1.32k
    excepthandler_ty o = (excepthandler_ty)_o;
6467
1.32k
    PyObject *result = NULL, *value = NULL;
6468
1.32k
    PyTypeObject *tp;
6469
1.32k
    if (!o) {
6470
0
        Py_RETURN_NONE;
6471
0
    }
6472
1.32k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6473
0
        return NULL;
6474
0
    }
6475
1.32k
    switch (o->kind) {
6476
1.32k
    case ExceptHandler_kind:
6477
1.32k
        tp = (PyTypeObject *)state->ExceptHandler_type;
6478
1.32k
        result = PyType_GenericNew(tp, NULL, NULL);
6479
1.32k
        if (!result) goto failed;
6480
1.32k
        value = ast2obj_expr(state, o->v.ExceptHandler.type);
6481
1.32k
        if (!value) goto failed;
6482
1.32k
        if (PyObject_SetAttr(result, state->type, value) == -1)
6483
0
            goto failed;
6484
1.32k
        Py_DECREF(value);
6485
1.32k
        value = ast2obj_identifier(state, o->v.ExceptHandler.name);
6486
1.32k
        if (!value) goto failed;
6487
1.32k
        if (PyObject_SetAttr(result, state->name, value) == -1)
6488
0
            goto failed;
6489
1.32k
        Py_DECREF(value);
6490
1.32k
        value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
6491
1.32k
                             ast2obj_stmt);
6492
1.32k
        if (!value) goto failed;
6493
1.32k
        if (PyObject_SetAttr(result, state->body, value) == -1)
6494
0
            goto failed;
6495
1.32k
        Py_DECREF(value);
6496
1.32k
        break;
6497
1.32k
    }
6498
1.32k
    value = ast2obj_int(state, o->lineno);
6499
1.32k
    if (!value) goto failed;
6500
1.32k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6501
0
        goto failed;
6502
1.32k
    Py_DECREF(value);
6503
1.32k
    value = ast2obj_int(state, o->col_offset);
6504
1.32k
    if (!value) goto failed;
6505
1.32k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6506
0
        goto failed;
6507
1.32k
    Py_DECREF(value);
6508
1.32k
    value = ast2obj_int(state, o->end_lineno);
6509
1.32k
    if (!value) goto failed;
6510
1.32k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6511
0
        goto failed;
6512
1.32k
    Py_DECREF(value);
6513
1.32k
    value = ast2obj_int(state, o->end_col_offset);
6514
1.32k
    if (!value) goto failed;
6515
1.32k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6516
0
        goto failed;
6517
1.32k
    Py_DECREF(value);
6518
1.32k
    Py_LeaveRecursiveCall();
6519
1.32k
    return result;
6520
0
failed:
6521
0
    Py_LeaveRecursiveCall();
6522
0
    Py_XDECREF(value);
6523
0
    Py_XDECREF(result);
6524
0
    return NULL;
6525
1.32k
}
6526
6527
PyObject*
6528
ast2obj_arguments(struct ast_state *state, void* _o)
6529
3.76k
{
6530
3.76k
    arguments_ty o = (arguments_ty)_o;
6531
3.76k
    PyObject *result = NULL, *value = NULL;
6532
3.76k
    PyTypeObject *tp;
6533
3.76k
    if (!o) {
6534
0
        Py_RETURN_NONE;
6535
0
    }
6536
3.76k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6537
0
        return NULL;
6538
0
    }
6539
3.76k
    tp = (PyTypeObject *)state->arguments_type;
6540
3.76k
    result = PyType_GenericNew(tp, NULL, NULL);
6541
3.76k
    if (!result) return NULL;
6542
3.76k
    value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
6543
3.76k
    if (!value) goto failed;
6544
3.76k
    if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
6545
0
        goto failed;
6546
3.76k
    Py_DECREF(value);
6547
3.76k
    value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
6548
3.76k
    if (!value) goto failed;
6549
3.76k
    if (PyObject_SetAttr(result, state->args, value) == -1)
6550
0
        goto failed;
6551
3.76k
    Py_DECREF(value);
6552
3.76k
    value = ast2obj_arg(state, o->vararg);
6553
3.76k
    if (!value) goto failed;
6554
3.76k
    if (PyObject_SetAttr(result, state->vararg, value) == -1)
6555
0
        goto failed;
6556
3.76k
    Py_DECREF(value);
6557
3.76k
    value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
6558
3.76k
    if (!value) goto failed;
6559
3.76k
    if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
6560
0
        goto failed;
6561
3.76k
    Py_DECREF(value);
6562
3.76k
    value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
6563
3.76k
    if (!value) goto failed;
6564
3.76k
    if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
6565
0
        goto failed;
6566
3.76k
    Py_DECREF(value);
6567
3.76k
    value = ast2obj_arg(state, o->kwarg);
6568
3.76k
    if (!value) goto failed;
6569
3.76k
    if (PyObject_SetAttr(result, state->kwarg, value) == -1)
6570
0
        goto failed;
6571
3.76k
    Py_DECREF(value);
6572
3.76k
    value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
6573
3.76k
    if (!value) goto failed;
6574
3.76k
    if (PyObject_SetAttr(result, state->defaults, value) == -1)
6575
0
        goto failed;
6576
3.76k
    Py_DECREF(value);
6577
3.76k
    Py_LeaveRecursiveCall();
6578
3.76k
    return result;
6579
0
failed:
6580
0
    Py_LeaveRecursiveCall();
6581
0
    Py_XDECREF(value);
6582
0
    Py_XDECREF(result);
6583
0
    return NULL;
6584
3.76k
}
6585
6586
PyObject*
6587
ast2obj_arg(struct ast_state *state, void* _o)
6588
17.9k
{
6589
17.9k
    arg_ty o = (arg_ty)_o;
6590
17.9k
    PyObject *result = NULL, *value = NULL;
6591
17.9k
    PyTypeObject *tp;
6592
17.9k
    if (!o) {
6593
6.06k
        Py_RETURN_NONE;
6594
6.06k
    }
6595
11.8k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6596
0
        return NULL;
6597
0
    }
6598
11.8k
    tp = (PyTypeObject *)state->arg_type;
6599
11.8k
    result = PyType_GenericNew(tp, NULL, NULL);
6600
11.8k
    if (!result) return NULL;
6601
11.8k
    value = ast2obj_identifier(state, o->arg);
6602
11.8k
    if (!value) goto failed;
6603
11.8k
    if (PyObject_SetAttr(result, state->arg, value) == -1)
6604
0
        goto failed;
6605
11.8k
    Py_DECREF(value);
6606
11.8k
    value = ast2obj_expr(state, o->annotation);
6607
11.8k
    if (!value) goto failed;
6608
11.8k
    if (PyObject_SetAttr(result, state->annotation, value) == -1)
6609
0
        goto failed;
6610
11.8k
    Py_DECREF(value);
6611
11.8k
    value = ast2obj_string(state, o->type_comment);
6612
11.8k
    if (!value) goto failed;
6613
11.8k
    if (PyObject_SetAttr(result, state->type_comment, value) == -1)
6614
0
        goto failed;
6615
11.8k
    Py_DECREF(value);
6616
11.8k
    value = ast2obj_int(state, o->lineno);
6617
11.8k
    if (!value) goto failed;
6618
11.8k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6619
0
        goto failed;
6620
11.8k
    Py_DECREF(value);
6621
11.8k
    value = ast2obj_int(state, o->col_offset);
6622
11.8k
    if (!value) goto failed;
6623
11.8k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6624
0
        goto failed;
6625
11.8k
    Py_DECREF(value);
6626
11.8k
    value = ast2obj_int(state, o->end_lineno);
6627
11.8k
    if (!value) goto failed;
6628
11.8k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6629
0
        goto failed;
6630
11.8k
    Py_DECREF(value);
6631
11.8k
    value = ast2obj_int(state, o->end_col_offset);
6632
11.8k
    if (!value) goto failed;
6633
11.8k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6634
0
        goto failed;
6635
11.8k
    Py_DECREF(value);
6636
11.8k
    Py_LeaveRecursiveCall();
6637
11.8k
    return result;
6638
0
failed:
6639
0
    Py_LeaveRecursiveCall();
6640
0
    Py_XDECREF(value);
6641
0
    Py_XDECREF(result);
6642
0
    return NULL;
6643
11.8k
}
6644
6645
PyObject*
6646
ast2obj_keyword(struct ast_state *state, void* _o)
6647
1.92k
{
6648
1.92k
    keyword_ty o = (keyword_ty)_o;
6649
1.92k
    PyObject *result = NULL, *value = NULL;
6650
1.92k
    PyTypeObject *tp;
6651
1.92k
    if (!o) {
6652
0
        Py_RETURN_NONE;
6653
0
    }
6654
1.92k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6655
0
        return NULL;
6656
0
    }
6657
1.92k
    tp = (PyTypeObject *)state->keyword_type;
6658
1.92k
    result = PyType_GenericNew(tp, NULL, NULL);
6659
1.92k
    if (!result) return NULL;
6660
1.92k
    value = ast2obj_identifier(state, o->arg);
6661
1.92k
    if (!value) goto failed;
6662
1.92k
    if (PyObject_SetAttr(result, state->arg, value) == -1)
6663
0
        goto failed;
6664
1.92k
    Py_DECREF(value);
6665
1.92k
    value = ast2obj_expr(state, o->value);
6666
1.92k
    if (!value) goto failed;
6667
1.92k
    if (PyObject_SetAttr(result, state->value, value) == -1)
6668
0
        goto failed;
6669
1.92k
    Py_DECREF(value);
6670
1.92k
    value = ast2obj_int(state, o->lineno);
6671
1.92k
    if (!value) goto failed;
6672
1.92k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6673
0
        goto failed;
6674
1.92k
    Py_DECREF(value);
6675
1.92k
    value = ast2obj_int(state, o->col_offset);
6676
1.92k
    if (!value) goto failed;
6677
1.92k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6678
0
        goto failed;
6679
1.92k
    Py_DECREF(value);
6680
1.92k
    value = ast2obj_int(state, o->end_lineno);
6681
1.92k
    if (!value) goto failed;
6682
1.92k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6683
0
        goto failed;
6684
1.92k
    Py_DECREF(value);
6685
1.92k
    value = ast2obj_int(state, o->end_col_offset);
6686
1.92k
    if (!value) goto failed;
6687
1.92k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6688
0
        goto failed;
6689
1.92k
    Py_DECREF(value);
6690
1.92k
    Py_LeaveRecursiveCall();
6691
1.92k
    return result;
6692
0
failed:
6693
0
    Py_LeaveRecursiveCall();
6694
0
    Py_XDECREF(value);
6695
0
    Py_XDECREF(result);
6696
0
    return NULL;
6697
1.92k
}
6698
6699
PyObject*
6700
ast2obj_alias(struct ast_state *state, void* _o)
6701
3.55k
{
6702
3.55k
    alias_ty o = (alias_ty)_o;
6703
3.55k
    PyObject *result = NULL, *value = NULL;
6704
3.55k
    PyTypeObject *tp;
6705
3.55k
    if (!o) {
6706
0
        Py_RETURN_NONE;
6707
0
    }
6708
3.55k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6709
0
        return NULL;
6710
0
    }
6711
3.55k
    tp = (PyTypeObject *)state->alias_type;
6712
3.55k
    result = PyType_GenericNew(tp, NULL, NULL);
6713
3.55k
    if (!result) return NULL;
6714
3.55k
    value = ast2obj_identifier(state, o->name);
6715
3.55k
    if (!value) goto failed;
6716
3.55k
    if (PyObject_SetAttr(result, state->name, value) == -1)
6717
0
        goto failed;
6718
3.55k
    Py_DECREF(value);
6719
3.55k
    value = ast2obj_identifier(state, o->asname);
6720
3.55k
    if (!value) goto failed;
6721
3.55k
    if (PyObject_SetAttr(result, state->asname, value) == -1)
6722
0
        goto failed;
6723
3.55k
    Py_DECREF(value);
6724
3.55k
    value = ast2obj_int(state, o->lineno);
6725
3.55k
    if (!value) goto failed;
6726
3.55k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6727
0
        goto failed;
6728
3.55k
    Py_DECREF(value);
6729
3.55k
    value = ast2obj_int(state, o->col_offset);
6730
3.55k
    if (!value) goto failed;
6731
3.55k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6732
0
        goto failed;
6733
3.55k
    Py_DECREF(value);
6734
3.55k
    value = ast2obj_int(state, o->end_lineno);
6735
3.55k
    if (!value) goto failed;
6736
3.55k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6737
0
        goto failed;
6738
3.55k
    Py_DECREF(value);
6739
3.55k
    value = ast2obj_int(state, o->end_col_offset);
6740
3.55k
    if (!value) goto failed;
6741
3.55k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6742
0
        goto failed;
6743
3.55k
    Py_DECREF(value);
6744
3.55k
    Py_LeaveRecursiveCall();
6745
3.55k
    return result;
6746
0
failed:
6747
0
    Py_LeaveRecursiveCall();
6748
0
    Py_XDECREF(value);
6749
0
    Py_XDECREF(result);
6750
0
    return NULL;
6751
3.55k
}
6752
6753
PyObject*
6754
ast2obj_withitem(struct ast_state *state, void* _o)
6755
1.89k
{
6756
1.89k
    withitem_ty o = (withitem_ty)_o;
6757
1.89k
    PyObject *result = NULL, *value = NULL;
6758
1.89k
    PyTypeObject *tp;
6759
1.89k
    if (!o) {
6760
0
        Py_RETURN_NONE;
6761
0
    }
6762
1.89k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6763
0
        return NULL;
6764
0
    }
6765
1.89k
    tp = (PyTypeObject *)state->withitem_type;
6766
1.89k
    result = PyType_GenericNew(tp, NULL, NULL);
6767
1.89k
    if (!result) return NULL;
6768
1.89k
    value = ast2obj_expr(state, o->context_expr);
6769
1.89k
    if (!value) goto failed;
6770
1.89k
    if (PyObject_SetAttr(result, state->context_expr, value) == -1)
6771
0
        goto failed;
6772
1.89k
    Py_DECREF(value);
6773
1.89k
    value = ast2obj_expr(state, o->optional_vars);
6774
1.89k
    if (!value) goto failed;
6775
1.89k
    if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
6776
0
        goto failed;
6777
1.89k
    Py_DECREF(value);
6778
1.89k
    Py_LeaveRecursiveCall();
6779
1.89k
    return result;
6780
0
failed:
6781
0
    Py_LeaveRecursiveCall();
6782
0
    Py_XDECREF(value);
6783
0
    Py_XDECREF(result);
6784
0
    return NULL;
6785
1.89k
}
6786
6787
PyObject*
6788
ast2obj_match_case(struct ast_state *state, void* _o)
6789
845
{
6790
845
    match_case_ty o = (match_case_ty)_o;
6791
845
    PyObject *result = NULL, *value = NULL;
6792
845
    PyTypeObject *tp;
6793
845
    if (!o) {
6794
0
        Py_RETURN_NONE;
6795
0
    }
6796
845
    if (Py_EnterRecursiveCall("during  ast construction")) {
6797
0
        return NULL;
6798
0
    }
6799
845
    tp = (PyTypeObject *)state->match_case_type;
6800
845
    result = PyType_GenericNew(tp, NULL, NULL);
6801
845
    if (!result) return NULL;
6802
845
    value = ast2obj_pattern(state, o->pattern);
6803
845
    if (!value) goto failed;
6804
845
    if (PyObject_SetAttr(result, state->pattern, value) == -1)
6805
0
        goto failed;
6806
845
    Py_DECREF(value);
6807
845
    value = ast2obj_expr(state, o->guard);
6808
845
    if (!value) goto failed;
6809
845
    if (PyObject_SetAttr(result, state->guard, value) == -1)
6810
0
        goto failed;
6811
845
    Py_DECREF(value);
6812
845
    value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
6813
845
    if (!value) goto failed;
6814
845
    if (PyObject_SetAttr(result, state->body, value) == -1)
6815
0
        goto failed;
6816
845
    Py_DECREF(value);
6817
845
    Py_LeaveRecursiveCall();
6818
845
    return result;
6819
0
failed:
6820
0
    Py_LeaveRecursiveCall();
6821
0
    Py_XDECREF(value);
6822
0
    Py_XDECREF(result);
6823
0
    return NULL;
6824
845
}
6825
6826
PyObject*
6827
ast2obj_pattern(struct ast_state *state, void* _o)
6828
26.1k
{
6829
26.1k
    pattern_ty o = (pattern_ty)_o;
6830
26.1k
    PyObject *result = NULL, *value = NULL;
6831
26.1k
    PyTypeObject *tp;
6832
26.1k
    if (!o) {
6833
9.69k
        Py_RETURN_NONE;
6834
9.69k
    }
6835
16.4k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6836
0
        return NULL;
6837
0
    }
6838
16.4k
    switch (o->kind) {
6839
794
    case MatchValue_kind:
6840
794
        tp = (PyTypeObject *)state->MatchValue_type;
6841
794
        result = PyType_GenericNew(tp, NULL, NULL);
6842
794
        if (!result) goto failed;
6843
794
        value = ast2obj_expr(state, o->v.MatchValue.value);
6844
794
        if (!value) goto failed;
6845
794
        if (PyObject_SetAttr(result, state->value, value) == -1)
6846
0
            goto failed;
6847
794
        Py_DECREF(value);
6848
794
        break;
6849
274
    case MatchSingleton_kind:
6850
274
        tp = (PyTypeObject *)state->MatchSingleton_type;
6851
274
        result = PyType_GenericNew(tp, NULL, NULL);
6852
274
        if (!result) goto failed;
6853
274
        value = ast2obj_constant(state, o->v.MatchSingleton.value);
6854
274
        if (!value) goto failed;
6855
274
        if (PyObject_SetAttr(result, state->value, value) == -1)
6856
0
            goto failed;
6857
274
        Py_DECREF(value);
6858
274
        break;
6859
530
    case MatchSequence_kind:
6860
530
        tp = (PyTypeObject *)state->MatchSequence_type;
6861
530
        result = PyType_GenericNew(tp, NULL, NULL);
6862
530
        if (!result) goto failed;
6863
530
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
6864
530
                             ast2obj_pattern);
6865
530
        if (!value) goto failed;
6866
530
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6867
0
            goto failed;
6868
530
        Py_DECREF(value);
6869
530
        break;
6870
319
    case MatchMapping_kind:
6871
319
        tp = (PyTypeObject *)state->MatchMapping_type;
6872
319
        result = PyType_GenericNew(tp, NULL, NULL);
6873
319
        if (!result) goto failed;
6874
319
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
6875
319
                             ast2obj_expr);
6876
319
        if (!value) goto failed;
6877
319
        if (PyObject_SetAttr(result, state->keys, value) == -1)
6878
0
            goto failed;
6879
319
        Py_DECREF(value);
6880
319
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
6881
319
                             ast2obj_pattern);
6882
319
        if (!value) goto failed;
6883
319
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6884
0
            goto failed;
6885
319
        Py_DECREF(value);
6886
319
        value = ast2obj_identifier(state, o->v.MatchMapping.rest);
6887
319
        if (!value) goto failed;
6888
319
        if (PyObject_SetAttr(result, state->rest, value) == -1)
6889
0
            goto failed;
6890
319
        Py_DECREF(value);
6891
319
        break;
6892
1.10k
    case MatchClass_kind:
6893
1.10k
        tp = (PyTypeObject *)state->MatchClass_type;
6894
1.10k
        result = PyType_GenericNew(tp, NULL, NULL);
6895
1.10k
        if (!result) goto failed;
6896
1.10k
        value = ast2obj_expr(state, o->v.MatchClass.cls);
6897
1.10k
        if (!value) goto failed;
6898
1.10k
        if (PyObject_SetAttr(result, state->cls, value) == -1)
6899
0
            goto failed;
6900
1.10k
        Py_DECREF(value);
6901
1.10k
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
6902
1.10k
                             ast2obj_pattern);
6903
1.10k
        if (!value) goto failed;
6904
1.10k
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6905
0
            goto failed;
6906
1.10k
        Py_DECREF(value);
6907
1.10k
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
6908
1.10k
                             ast2obj_identifier);
6909
1.10k
        if (!value) goto failed;
6910
1.10k
        if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
6911
0
            goto failed;
6912
1.10k
        Py_DECREF(value);
6913
1.10k
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
6914
1.10k
                             ast2obj_pattern);
6915
1.10k
        if (!value) goto failed;
6916
1.10k
        if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
6917
0
            goto failed;
6918
1.10k
        Py_DECREF(value);
6919
1.10k
        break;
6920
311
    case MatchStar_kind:
6921
311
        tp = (PyTypeObject *)state->MatchStar_type;
6922
311
        result = PyType_GenericNew(tp, NULL, NULL);
6923
311
        if (!result) goto failed;
6924
311
        value = ast2obj_identifier(state, o->v.MatchStar.name);
6925
311
        if (!value) goto failed;
6926
311
        if (PyObject_SetAttr(result, state->name, value) == -1)
6927
0
            goto failed;
6928
311
        Py_DECREF(value);
6929
311
        break;
6930
9.76k
    case MatchAs_kind:
6931
9.76k
        tp = (PyTypeObject *)state->MatchAs_type;
6932
9.76k
        result = PyType_GenericNew(tp, NULL, NULL);
6933
9.76k
        if (!result) goto failed;
6934
9.76k
        value = ast2obj_pattern(state, o->v.MatchAs.pattern);
6935
9.76k
        if (!value) goto failed;
6936
9.76k
        if (PyObject_SetAttr(result, state->pattern, value) == -1)
6937
0
            goto failed;
6938
9.76k
        Py_DECREF(value);
6939
9.76k
        value = ast2obj_identifier(state, o->v.MatchAs.name);
6940
9.76k
        if (!value) goto failed;
6941
9.76k
        if (PyObject_SetAttr(result, state->name, value) == -1)
6942
0
            goto failed;
6943
9.76k
        Py_DECREF(value);
6944
9.76k
        break;
6945
3.40k
    case MatchOr_kind:
6946
3.40k
        tp = (PyTypeObject *)state->MatchOr_type;
6947
3.40k
        result = PyType_GenericNew(tp, NULL, NULL);
6948
3.40k
        if (!result) goto failed;
6949
3.40k
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
6950
3.40k
                             ast2obj_pattern);
6951
3.40k
        if (!value) goto failed;
6952
3.40k
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6953
0
            goto failed;
6954
3.40k
        Py_DECREF(value);
6955
3.40k
        break;
6956
16.4k
    }
6957
16.4k
    value = ast2obj_int(state, o->lineno);
6958
16.4k
    if (!value) goto failed;
6959
16.4k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6960
0
        goto failed;
6961
16.4k
    Py_DECREF(value);
6962
16.4k
    value = ast2obj_int(state, o->col_offset);
6963
16.4k
    if (!value) goto failed;
6964
16.4k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6965
0
        goto failed;
6966
16.4k
    Py_DECREF(value);
6967
16.4k
    value = ast2obj_int(state, o->end_lineno);
6968
16.4k
    if (!value) goto failed;
6969
16.4k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6970
0
        goto failed;
6971
16.4k
    Py_DECREF(value);
6972
16.4k
    value = ast2obj_int(state, o->end_col_offset);
6973
16.4k
    if (!value) goto failed;
6974
16.4k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6975
0
        goto failed;
6976
16.4k
    Py_DECREF(value);
6977
16.4k
    Py_LeaveRecursiveCall();
6978
16.4k
    return result;
6979
0
failed:
6980
0
    Py_LeaveRecursiveCall();
6981
0
    Py_XDECREF(value);
6982
0
    Py_XDECREF(result);
6983
0
    return NULL;
6984
16.4k
}
6985
6986
PyObject*
6987
ast2obj_type_ignore(struct ast_state *state, void* _o)
6988
0
{
6989
0
    type_ignore_ty o = (type_ignore_ty)_o;
6990
0
    PyObject *result = NULL, *value = NULL;
6991
0
    PyTypeObject *tp;
6992
0
    if (!o) {
6993
0
        Py_RETURN_NONE;
6994
0
    }
6995
0
    if (Py_EnterRecursiveCall("during  ast construction")) {
6996
0
        return NULL;
6997
0
    }
6998
0
    switch (o->kind) {
6999
0
    case TypeIgnore_kind:
7000
0
        tp = (PyTypeObject *)state->TypeIgnore_type;
7001
0
        result = PyType_GenericNew(tp, NULL, NULL);
7002
0
        if (!result) goto failed;
7003
0
        value = ast2obj_int(state, o->v.TypeIgnore.lineno);
7004
0
        if (!value) goto failed;
7005
0
        if (PyObject_SetAttr(result, state->lineno, value) == -1)
7006
0
            goto failed;
7007
0
        Py_DECREF(value);
7008
0
        value = ast2obj_string(state, o->v.TypeIgnore.tag);
7009
0
        if (!value) goto failed;
7010
0
        if (PyObject_SetAttr(result, state->tag, value) == -1)
7011
0
            goto failed;
7012
0
        Py_DECREF(value);
7013
0
        break;
7014
0
    }
7015
0
    Py_LeaveRecursiveCall();
7016
0
    return result;
7017
0
failed:
7018
0
    Py_LeaveRecursiveCall();
7019
0
    Py_XDECREF(value);
7020
0
    Py_XDECREF(result);
7021
0
    return NULL;
7022
0
}
7023
7024
PyObject*
7025
ast2obj_type_param(struct ast_state *state, void* _o)
7026
7.47k
{
7027
7.47k
    type_param_ty o = (type_param_ty)_o;
7028
7.47k
    PyObject *result = NULL, *value = NULL;
7029
7.47k
    PyTypeObject *tp;
7030
7.47k
    if (!o) {
7031
0
        Py_RETURN_NONE;
7032
0
    }
7033
7.47k
    if (Py_EnterRecursiveCall("during  ast construction")) {
7034
0
        return NULL;
7035
0
    }
7036
7.47k
    switch (o->kind) {
7037
5.53k
    case TypeVar_kind:
7038
5.53k
        tp = (PyTypeObject *)state->TypeVar_type;
7039
5.53k
        result = PyType_GenericNew(tp, NULL, NULL);
7040
5.53k
        if (!result) goto failed;
7041
5.53k
        value = ast2obj_identifier(state, o->v.TypeVar.name);
7042
5.53k
        if (!value) goto failed;
7043
5.53k
        if (PyObject_SetAttr(result, state->name, value) == -1)
7044
0
            goto failed;
7045
5.53k
        Py_DECREF(value);
7046
5.53k
        value = ast2obj_expr(state, o->v.TypeVar.bound);
7047
5.53k
        if (!value) goto failed;
7048
5.53k
        if (PyObject_SetAttr(result, state->bound, value) == -1)
7049
0
            goto failed;
7050
5.53k
        Py_DECREF(value);
7051
5.53k
        value = ast2obj_expr(state, o->v.TypeVar.default_value);
7052
5.53k
        if (!value) goto failed;
7053
5.53k
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7054
0
            goto failed;
7055
5.53k
        Py_DECREF(value);
7056
5.53k
        break;
7057
1.10k
    case ParamSpec_kind:
7058
1.10k
        tp = (PyTypeObject *)state->ParamSpec_type;
7059
1.10k
        result = PyType_GenericNew(tp, NULL, NULL);
7060
1.10k
        if (!result) goto failed;
7061
1.10k
        value = ast2obj_identifier(state, o->v.ParamSpec.name);
7062
1.10k
        if (!value) goto failed;
7063
1.10k
        if (PyObject_SetAttr(result, state->name, value) == -1)
7064
0
            goto failed;
7065
1.10k
        Py_DECREF(value);
7066
1.10k
        value = ast2obj_expr(state, o->v.ParamSpec.default_value);
7067
1.10k
        if (!value) goto failed;
7068
1.10k
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7069
0
            goto failed;
7070
1.10k
        Py_DECREF(value);
7071
1.10k
        break;
7072
836
    case TypeVarTuple_kind:
7073
836
        tp = (PyTypeObject *)state->TypeVarTuple_type;
7074
836
        result = PyType_GenericNew(tp, NULL, NULL);
7075
836
        if (!result) goto failed;
7076
836
        value = ast2obj_identifier(state, o->v.TypeVarTuple.name);
7077
836
        if (!value) goto failed;
7078
836
        if (PyObject_SetAttr(result, state->name, value) == -1)
7079
0
            goto failed;
7080
836
        Py_DECREF(value);
7081
836
        value = ast2obj_expr(state, o->v.TypeVarTuple.default_value);
7082
836
        if (!value) goto failed;
7083
836
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7084
0
            goto failed;
7085
836
        Py_DECREF(value);
7086
836
        break;
7087
7.47k
    }
7088
7.47k
    value = ast2obj_int(state, o->lineno);
7089
7.47k
    if (!value) goto failed;
7090
7.47k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
7091
0
        goto failed;
7092
7.47k
    Py_DECREF(value);
7093
7.47k
    value = ast2obj_int(state, o->col_offset);
7094
7.47k
    if (!value) goto failed;
7095
7.47k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
7096
0
        goto failed;
7097
7.47k
    Py_DECREF(value);
7098
7.47k
    value = ast2obj_int(state, o->end_lineno);
7099
7.47k
    if (!value) goto failed;
7100
7.47k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
7101
0
        goto failed;
7102
7.47k
    Py_DECREF(value);
7103
7.47k
    value = ast2obj_int(state, o->end_col_offset);
7104
7.47k
    if (!value) goto failed;
7105
7.47k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
7106
0
        goto failed;
7107
7.47k
    Py_DECREF(value);
7108
7.47k
    Py_LeaveRecursiveCall();
7109
7.47k
    return result;
7110
0
failed:
7111
0
    Py_LeaveRecursiveCall();
7112
0
    Py_XDECREF(value);
7113
0
    Py_XDECREF(result);
7114
0
    return NULL;
7115
7.47k
}
7116
7117
7118
int
7119
obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, const char*
7120
            field, PyArena* arena)
7121
0
{
7122
0
    int isinstance;
7123
7124
0
    PyObject *tmp = NULL;
7125
0
    PyObject *tp;
7126
7127
0
    if (obj == Py_None) {
7128
0
        *out = NULL;
7129
0
        return 0;
7130
0
    }
7131
0
    tp = state->mod_type;
7132
0
    isinstance = PyObject_IsInstance(obj, tp);
7133
0
    if (isinstance == -1) {
7134
0
        return 1;
7135
0
    }
7136
0
    if (!isinstance && field != NULL) {
7137
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'mod', got '%T'", field, obj);
7138
0
        return 1;
7139
0
    }
7140
0
    tp = state->Module_type;
7141
0
    isinstance = PyObject_IsInstance(obj, tp);
7142
0
    if (isinstance == -1) {
7143
0
        return -1;
7144
0
    }
7145
0
    if (isinstance) {
7146
0
        asdl_stmt_seq* body;
7147
0
        asdl_type_ignore_seq* type_ignores;
7148
7149
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7150
0
            return -1;
7151
0
        }
7152
0
        if (tmp == NULL) {
7153
0
            tmp = PyList_New(0);
7154
0
            if (tmp == NULL) {
7155
0
                return -1;
7156
0
            }
7157
0
        }
7158
0
        {
7159
0
            int res;
7160
0
            Py_ssize_t len;
7161
0
            Py_ssize_t i;
7162
0
            if (!PyList_Check(tmp)) {
7163
0
                PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %T", tmp);
7164
0
                goto failed;
7165
0
            }
7166
0
            len = PyList_GET_SIZE(tmp);
7167
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7168
0
            if (body == NULL) goto failed;
7169
0
            for (i = 0; i < len; i++) {
7170
0
                stmt_ty val;
7171
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7172
0
                if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
7173
0
                    goto failed;
7174
0
                }
7175
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7176
0
                _Py_LeaveRecursiveCall();
7177
0
                Py_DECREF(tmp2);
7178
0
                if (res != 0) goto failed;
7179
0
                if (len != PyList_GET_SIZE(tmp)) {
7180
0
                    PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
7181
0
                    goto failed;
7182
0
                }
7183
0
                asdl_seq_SET(body, i, val);
7184
0
            }
7185
0
            Py_CLEAR(tmp);
7186
0
        }
7187
0
        if (PyObject_GetOptionalAttr(obj, state->type_ignores, &tmp) < 0) {
7188
0
            return -1;
7189
0
        }
7190
0
        if (tmp == NULL) {
7191
0
            tmp = PyList_New(0);
7192
0
            if (tmp == NULL) {
7193
0
                return -1;
7194
0
            }
7195
0
        }
7196
0
        {
7197
0
            int res;
7198
0
            Py_ssize_t len;
7199
0
            Py_ssize_t i;
7200
0
            if (!PyList_Check(tmp)) {
7201
0
                PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %T", tmp);
7202
0
                goto failed;
7203
0
            }
7204
0
            len = PyList_GET_SIZE(tmp);
7205
0
            type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
7206
0
            if (type_ignores == NULL) goto failed;
7207
0
            for (i = 0; i < len; i++) {
7208
0
                type_ignore_ty val;
7209
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7210
0
                if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
7211
0
                    goto failed;
7212
0
                }
7213
0
                res = obj2ast_type_ignore(state, tmp2, &val, "type_ignores", arena);
7214
0
                _Py_LeaveRecursiveCall();
7215
0
                Py_DECREF(tmp2);
7216
0
                if (res != 0) goto failed;
7217
0
                if (len != PyList_GET_SIZE(tmp)) {
7218
0
                    PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
7219
0
                    goto failed;
7220
0
                }
7221
0
                asdl_seq_SET(type_ignores, i, val);
7222
0
            }
7223
0
            Py_CLEAR(tmp);
7224
0
        }
7225
0
        *out = _PyAST_Module(body, type_ignores, arena);
7226
0
        if (*out == NULL) goto failed;
7227
0
        return 0;
7228
0
    }
7229
0
    tp = state->Interactive_type;
7230
0
    isinstance = PyObject_IsInstance(obj, tp);
7231
0
    if (isinstance == -1) {
7232
0
        return -1;
7233
0
    }
7234
0
    if (isinstance) {
7235
0
        asdl_stmt_seq* body;
7236
7237
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7238
0
            return -1;
7239
0
        }
7240
0
        if (tmp == NULL) {
7241
0
            tmp = PyList_New(0);
7242
0
            if (tmp == NULL) {
7243
0
                return -1;
7244
0
            }
7245
0
        }
7246
0
        {
7247
0
            int res;
7248
0
            Py_ssize_t len;
7249
0
            Py_ssize_t i;
7250
0
            if (!PyList_Check(tmp)) {
7251
0
                PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %T", tmp);
7252
0
                goto failed;
7253
0
            }
7254
0
            len = PyList_GET_SIZE(tmp);
7255
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7256
0
            if (body == NULL) goto failed;
7257
0
            for (i = 0; i < len; i++) {
7258
0
                stmt_ty val;
7259
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7260
0
                if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
7261
0
                    goto failed;
7262
0
                }
7263
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7264
0
                _Py_LeaveRecursiveCall();
7265
0
                Py_DECREF(tmp2);
7266
0
                if (res != 0) goto failed;
7267
0
                if (len != PyList_GET_SIZE(tmp)) {
7268
0
                    PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
7269
0
                    goto failed;
7270
0
                }
7271
0
                asdl_seq_SET(body, i, val);
7272
0
            }
7273
0
            Py_CLEAR(tmp);
7274
0
        }
7275
0
        *out = _PyAST_Interactive(body, arena);
7276
0
        if (*out == NULL) goto failed;
7277
0
        return 0;
7278
0
    }
7279
0
    tp = state->Expression_type;
7280
0
    isinstance = PyObject_IsInstance(obj, tp);
7281
0
    if (isinstance == -1) {
7282
0
        return -1;
7283
0
    }
7284
0
    if (isinstance) {
7285
0
        expr_ty body;
7286
7287
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7288
0
            return -1;
7289
0
        }
7290
0
        if (tmp == NULL) {
7291
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
7292
0
            return -1;
7293
0
        }
7294
0
        else {
7295
0
            int res;
7296
0
            if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
7297
0
                goto failed;
7298
0
            }
7299
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
7300
0
            _Py_LeaveRecursiveCall();
7301
0
            if (res != 0) goto failed;
7302
0
            Py_CLEAR(tmp);
7303
0
        }
7304
0
        *out = _PyAST_Expression(body, arena);
7305
0
        if (*out == NULL) goto failed;
7306
0
        return 0;
7307
0
    }
7308
0
    tp = state->FunctionType_type;
7309
0
    isinstance = PyObject_IsInstance(obj, tp);
7310
0
    if (isinstance == -1) {
7311
0
        return -1;
7312
0
    }
7313
0
    if (isinstance) {
7314
0
        asdl_expr_seq* argtypes;
7315
0
        expr_ty returns;
7316
7317
0
        if (PyObject_GetOptionalAttr(obj, state->argtypes, &tmp) < 0) {
7318
0
            return -1;
7319
0
        }
7320
0
        if (tmp == NULL) {
7321
0
            tmp = PyList_New(0);
7322
0
            if (tmp == NULL) {
7323
0
                return -1;
7324
0
            }
7325
0
        }
7326
0
        {
7327
0
            int res;
7328
0
            Py_ssize_t len;
7329
0
            Py_ssize_t i;
7330
0
            if (!PyList_Check(tmp)) {
7331
0
                PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %T", tmp);
7332
0
                goto failed;
7333
0
            }
7334
0
            len = PyList_GET_SIZE(tmp);
7335
0
            argtypes = _Py_asdl_expr_seq_new(len, arena);
7336
0
            if (argtypes == NULL) goto failed;
7337
0
            for (i = 0; i < len; i++) {
7338
0
                expr_ty val;
7339
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7340
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
7341
0
                    goto failed;
7342
0
                }
7343
0
                res = obj2ast_expr(state, tmp2, &val, "argtypes", arena);
7344
0
                _Py_LeaveRecursiveCall();
7345
0
                Py_DECREF(tmp2);
7346
0
                if (res != 0) goto failed;
7347
0
                if (len != PyList_GET_SIZE(tmp)) {
7348
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
7349
0
                    goto failed;
7350
0
                }
7351
0
                asdl_seq_SET(argtypes, i, val);
7352
0
            }
7353
0
            Py_CLEAR(tmp);
7354
0
        }
7355
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7356
0
            return -1;
7357
0
        }
7358
0
        if (tmp == NULL) {
7359
0
            PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
7360
0
            return -1;
7361
0
        }
7362
0
        else {
7363
0
            int res;
7364
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
7365
0
                goto failed;
7366
0
            }
7367
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7368
0
            _Py_LeaveRecursiveCall();
7369
0
            if (res != 0) goto failed;
7370
0
            Py_CLEAR(tmp);
7371
0
        }
7372
0
        *out = _PyAST_FunctionType(argtypes, returns, arena);
7373
0
        if (*out == NULL) goto failed;
7374
0
        return 0;
7375
0
    }
7376
7377
0
    PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
7378
0
    failed:
7379
0
    Py_XDECREF(tmp);
7380
0
    return -1;
7381
0
}
7382
7383
int
7384
obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, const char*
7385
             field, PyArena* arena)
7386
0
{
7387
0
    int isinstance;
7388
7389
0
    PyObject *tmp = NULL;
7390
0
    PyObject *tp;
7391
0
    int lineno;
7392
0
    int col_offset;
7393
0
    int end_lineno;
7394
0
    int end_col_offset;
7395
7396
0
    if (obj == Py_None) {
7397
0
        *out = NULL;
7398
0
        return 0;
7399
0
    }
7400
0
    tp = state->stmt_type;
7401
0
    isinstance = PyObject_IsInstance(obj, tp);
7402
0
    if (isinstance == -1) {
7403
0
        return 1;
7404
0
    }
7405
0
    if (!isinstance && field != NULL) {
7406
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'stmt', got '%T'", field, obj);
7407
0
        return 1;
7408
0
    }
7409
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
7410
0
        return -1;
7411
0
    }
7412
0
    if (tmp == NULL) {
7413
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
7414
0
        return -1;
7415
0
    }
7416
0
    else {
7417
0
        int res;
7418
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7419
0
            goto failed;
7420
0
        }
7421
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
7422
0
        _Py_LeaveRecursiveCall();
7423
0
        if (res != 0) goto failed;
7424
0
        Py_CLEAR(tmp);
7425
0
    }
7426
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
7427
0
        return -1;
7428
0
    }
7429
0
    if (tmp == NULL) {
7430
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
7431
0
        return -1;
7432
0
    }
7433
0
    else {
7434
0
        int res;
7435
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7436
0
            goto failed;
7437
0
        }
7438
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
7439
0
        _Py_LeaveRecursiveCall();
7440
0
        if (res != 0) goto failed;
7441
0
        Py_CLEAR(tmp);
7442
0
    }
7443
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
7444
0
        return -1;
7445
0
    }
7446
0
    if (tmp == NULL || tmp == Py_None) {
7447
0
        Py_CLEAR(tmp);
7448
0
        end_lineno = lineno;
7449
0
    }
7450
0
    else {
7451
0
        int res;
7452
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7453
0
            goto failed;
7454
0
        }
7455
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
7456
0
        _Py_LeaveRecursiveCall();
7457
0
        if (res != 0) goto failed;
7458
0
        Py_CLEAR(tmp);
7459
0
    }
7460
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
7461
0
        return -1;
7462
0
    }
7463
0
    if (tmp == NULL || tmp == Py_None) {
7464
0
        Py_CLEAR(tmp);
7465
0
        end_col_offset = col_offset;
7466
0
    }
7467
0
    else {
7468
0
        int res;
7469
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7470
0
            goto failed;
7471
0
        }
7472
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
7473
0
        _Py_LeaveRecursiveCall();
7474
0
        if (res != 0) goto failed;
7475
0
        Py_CLEAR(tmp);
7476
0
    }
7477
0
    tp = state->FunctionDef_type;
7478
0
    isinstance = PyObject_IsInstance(obj, tp);
7479
0
    if (isinstance == -1) {
7480
0
        return -1;
7481
0
    }
7482
0
    if (isinstance) {
7483
0
        identifier name;
7484
0
        arguments_ty args;
7485
0
        asdl_stmt_seq* body;
7486
0
        asdl_expr_seq* decorator_list;
7487
0
        expr_ty returns;
7488
0
        string type_comment;
7489
0
        asdl_type_param_seq* type_params;
7490
7491
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7492
0
            return -1;
7493
0
        }
7494
0
        if (tmp == NULL) {
7495
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
7496
0
            return -1;
7497
0
        }
7498
0
        else {
7499
0
            int res;
7500
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7501
0
                goto failed;
7502
0
            }
7503
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7504
0
            _Py_LeaveRecursiveCall();
7505
0
            if (res != 0) goto failed;
7506
0
            Py_CLEAR(tmp);
7507
0
        }
7508
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
7509
0
            return -1;
7510
0
        }
7511
0
        if (tmp == NULL) {
7512
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
7513
0
            return -1;
7514
0
        }
7515
0
        else {
7516
0
            int res;
7517
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7518
0
                goto failed;
7519
0
            }
7520
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
7521
0
            _Py_LeaveRecursiveCall();
7522
0
            if (res != 0) goto failed;
7523
0
            Py_CLEAR(tmp);
7524
0
        }
7525
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7526
0
            return -1;
7527
0
        }
7528
0
        if (tmp == NULL) {
7529
0
            tmp = PyList_New(0);
7530
0
            if (tmp == NULL) {
7531
0
                return -1;
7532
0
            }
7533
0
        }
7534
0
        {
7535
0
            int res;
7536
0
            Py_ssize_t len;
7537
0
            Py_ssize_t i;
7538
0
            if (!PyList_Check(tmp)) {
7539
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %T", tmp);
7540
0
                goto failed;
7541
0
            }
7542
0
            len = PyList_GET_SIZE(tmp);
7543
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7544
0
            if (body == NULL) goto failed;
7545
0
            for (i = 0; i < len; i++) {
7546
0
                stmt_ty val;
7547
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7548
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7549
0
                    goto failed;
7550
0
                }
7551
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7552
0
                _Py_LeaveRecursiveCall();
7553
0
                Py_DECREF(tmp2);
7554
0
                if (res != 0) goto failed;
7555
0
                if (len != PyList_GET_SIZE(tmp)) {
7556
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
7557
0
                    goto failed;
7558
0
                }
7559
0
                asdl_seq_SET(body, i, val);
7560
0
            }
7561
0
            Py_CLEAR(tmp);
7562
0
        }
7563
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
7564
0
            return -1;
7565
0
        }
7566
0
        if (tmp == NULL) {
7567
0
            tmp = PyList_New(0);
7568
0
            if (tmp == NULL) {
7569
0
                return -1;
7570
0
            }
7571
0
        }
7572
0
        {
7573
0
            int res;
7574
0
            Py_ssize_t len;
7575
0
            Py_ssize_t i;
7576
0
            if (!PyList_Check(tmp)) {
7577
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %T", tmp);
7578
0
                goto failed;
7579
0
            }
7580
0
            len = PyList_GET_SIZE(tmp);
7581
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
7582
0
            if (decorator_list == NULL) goto failed;
7583
0
            for (i = 0; i < len; i++) {
7584
0
                expr_ty val;
7585
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7586
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7587
0
                    goto failed;
7588
0
                }
7589
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
7590
0
                _Py_LeaveRecursiveCall();
7591
0
                Py_DECREF(tmp2);
7592
0
                if (res != 0) goto failed;
7593
0
                if (len != PyList_GET_SIZE(tmp)) {
7594
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
7595
0
                    goto failed;
7596
0
                }
7597
0
                asdl_seq_SET(decorator_list, i, val);
7598
0
            }
7599
0
            Py_CLEAR(tmp);
7600
0
        }
7601
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7602
0
            return -1;
7603
0
        }
7604
0
        if (tmp == NULL || tmp == Py_None) {
7605
0
            Py_CLEAR(tmp);
7606
0
            returns = NULL;
7607
0
        }
7608
0
        else {
7609
0
            int res;
7610
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7611
0
                goto failed;
7612
0
            }
7613
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7614
0
            _Py_LeaveRecursiveCall();
7615
0
            if (res != 0) goto failed;
7616
0
            Py_CLEAR(tmp);
7617
0
        }
7618
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
7619
0
            return -1;
7620
0
        }
7621
0
        if (tmp == NULL || tmp == Py_None) {
7622
0
            Py_CLEAR(tmp);
7623
0
            type_comment = NULL;
7624
0
        }
7625
0
        else {
7626
0
            int res;
7627
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7628
0
                goto failed;
7629
0
            }
7630
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
7631
0
                                 arena);
7632
0
            _Py_LeaveRecursiveCall();
7633
0
            if (res != 0) goto failed;
7634
0
            Py_CLEAR(tmp);
7635
0
        }
7636
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
7637
0
            return -1;
7638
0
        }
7639
0
        if (tmp == NULL) {
7640
0
            tmp = PyList_New(0);
7641
0
            if (tmp == NULL) {
7642
0
                return -1;
7643
0
            }
7644
0
        }
7645
0
        {
7646
0
            int res;
7647
0
            Py_ssize_t len;
7648
0
            Py_ssize_t i;
7649
0
            if (!PyList_Check(tmp)) {
7650
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %T", tmp);
7651
0
                goto failed;
7652
0
            }
7653
0
            len = PyList_GET_SIZE(tmp);
7654
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
7655
0
            if (type_params == NULL) goto failed;
7656
0
            for (i = 0; i < len; i++) {
7657
0
                type_param_ty val;
7658
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7659
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7660
0
                    goto failed;
7661
0
                }
7662
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
7663
0
                _Py_LeaveRecursiveCall();
7664
0
                Py_DECREF(tmp2);
7665
0
                if (res != 0) goto failed;
7666
0
                if (len != PyList_GET_SIZE(tmp)) {
7667
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
7668
0
                    goto failed;
7669
0
                }
7670
0
                asdl_seq_SET(type_params, i, val);
7671
0
            }
7672
0
            Py_CLEAR(tmp);
7673
0
        }
7674
0
        *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
7675
0
                                  type_comment, type_params, lineno,
7676
0
                                  col_offset, end_lineno, end_col_offset,
7677
0
                                  arena);
7678
0
        if (*out == NULL) goto failed;
7679
0
        return 0;
7680
0
    }
7681
0
    tp = state->AsyncFunctionDef_type;
7682
0
    isinstance = PyObject_IsInstance(obj, tp);
7683
0
    if (isinstance == -1) {
7684
0
        return -1;
7685
0
    }
7686
0
    if (isinstance) {
7687
0
        identifier name;
7688
0
        arguments_ty args;
7689
0
        asdl_stmt_seq* body;
7690
0
        asdl_expr_seq* decorator_list;
7691
0
        expr_ty returns;
7692
0
        string type_comment;
7693
0
        asdl_type_param_seq* type_params;
7694
7695
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7696
0
            return -1;
7697
0
        }
7698
0
        if (tmp == NULL) {
7699
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
7700
0
            return -1;
7701
0
        }
7702
0
        else {
7703
0
            int res;
7704
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7705
0
                goto failed;
7706
0
            }
7707
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7708
0
            _Py_LeaveRecursiveCall();
7709
0
            if (res != 0) goto failed;
7710
0
            Py_CLEAR(tmp);
7711
0
        }
7712
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
7713
0
            return -1;
7714
0
        }
7715
0
        if (tmp == NULL) {
7716
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
7717
0
            return -1;
7718
0
        }
7719
0
        else {
7720
0
            int res;
7721
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7722
0
                goto failed;
7723
0
            }
7724
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
7725
0
            _Py_LeaveRecursiveCall();
7726
0
            if (res != 0) goto failed;
7727
0
            Py_CLEAR(tmp);
7728
0
        }
7729
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7730
0
            return -1;
7731
0
        }
7732
0
        if (tmp == NULL) {
7733
0
            tmp = PyList_New(0);
7734
0
            if (tmp == NULL) {
7735
0
                return -1;
7736
0
            }
7737
0
        }
7738
0
        {
7739
0
            int res;
7740
0
            Py_ssize_t len;
7741
0
            Py_ssize_t i;
7742
0
            if (!PyList_Check(tmp)) {
7743
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %T", tmp);
7744
0
                goto failed;
7745
0
            }
7746
0
            len = PyList_GET_SIZE(tmp);
7747
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7748
0
            if (body == NULL) goto failed;
7749
0
            for (i = 0; i < len; i++) {
7750
0
                stmt_ty val;
7751
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7752
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7753
0
                    goto failed;
7754
0
                }
7755
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7756
0
                _Py_LeaveRecursiveCall();
7757
0
                Py_DECREF(tmp2);
7758
0
                if (res != 0) goto failed;
7759
0
                if (len != PyList_GET_SIZE(tmp)) {
7760
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
7761
0
                    goto failed;
7762
0
                }
7763
0
                asdl_seq_SET(body, i, val);
7764
0
            }
7765
0
            Py_CLEAR(tmp);
7766
0
        }
7767
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
7768
0
            return -1;
7769
0
        }
7770
0
        if (tmp == NULL) {
7771
0
            tmp = PyList_New(0);
7772
0
            if (tmp == NULL) {
7773
0
                return -1;
7774
0
            }
7775
0
        }
7776
0
        {
7777
0
            int res;
7778
0
            Py_ssize_t len;
7779
0
            Py_ssize_t i;
7780
0
            if (!PyList_Check(tmp)) {
7781
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %T", tmp);
7782
0
                goto failed;
7783
0
            }
7784
0
            len = PyList_GET_SIZE(tmp);
7785
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
7786
0
            if (decorator_list == NULL) goto failed;
7787
0
            for (i = 0; i < len; i++) {
7788
0
                expr_ty val;
7789
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7790
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7791
0
                    goto failed;
7792
0
                }
7793
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
7794
0
                _Py_LeaveRecursiveCall();
7795
0
                Py_DECREF(tmp2);
7796
0
                if (res != 0) goto failed;
7797
0
                if (len != PyList_GET_SIZE(tmp)) {
7798
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
7799
0
                    goto failed;
7800
0
                }
7801
0
                asdl_seq_SET(decorator_list, i, val);
7802
0
            }
7803
0
            Py_CLEAR(tmp);
7804
0
        }
7805
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7806
0
            return -1;
7807
0
        }
7808
0
        if (tmp == NULL || tmp == Py_None) {
7809
0
            Py_CLEAR(tmp);
7810
0
            returns = NULL;
7811
0
        }
7812
0
        else {
7813
0
            int res;
7814
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7815
0
                goto failed;
7816
0
            }
7817
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7818
0
            _Py_LeaveRecursiveCall();
7819
0
            if (res != 0) goto failed;
7820
0
            Py_CLEAR(tmp);
7821
0
        }
7822
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
7823
0
            return -1;
7824
0
        }
7825
0
        if (tmp == NULL || tmp == Py_None) {
7826
0
            Py_CLEAR(tmp);
7827
0
            type_comment = NULL;
7828
0
        }
7829
0
        else {
7830
0
            int res;
7831
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7832
0
                goto failed;
7833
0
            }
7834
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
7835
0
                                 arena);
7836
0
            _Py_LeaveRecursiveCall();
7837
0
            if (res != 0) goto failed;
7838
0
            Py_CLEAR(tmp);
7839
0
        }
7840
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
7841
0
            return -1;
7842
0
        }
7843
0
        if (tmp == NULL) {
7844
0
            tmp = PyList_New(0);
7845
0
            if (tmp == NULL) {
7846
0
                return -1;
7847
0
            }
7848
0
        }
7849
0
        {
7850
0
            int res;
7851
0
            Py_ssize_t len;
7852
0
            Py_ssize_t i;
7853
0
            if (!PyList_Check(tmp)) {
7854
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %T", tmp);
7855
0
                goto failed;
7856
0
            }
7857
0
            len = PyList_GET_SIZE(tmp);
7858
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
7859
0
            if (type_params == NULL) goto failed;
7860
0
            for (i = 0; i < len; i++) {
7861
0
                type_param_ty val;
7862
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7863
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7864
0
                    goto failed;
7865
0
                }
7866
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
7867
0
                _Py_LeaveRecursiveCall();
7868
0
                Py_DECREF(tmp2);
7869
0
                if (res != 0) goto failed;
7870
0
                if (len != PyList_GET_SIZE(tmp)) {
7871
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
7872
0
                    goto failed;
7873
0
                }
7874
0
                asdl_seq_SET(type_params, i, val);
7875
0
            }
7876
0
            Py_CLEAR(tmp);
7877
0
        }
7878
0
        *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
7879
0
                                       returns, type_comment, type_params,
7880
0
                                       lineno, col_offset, end_lineno,
7881
0
                                       end_col_offset, arena);
7882
0
        if (*out == NULL) goto failed;
7883
0
        return 0;
7884
0
    }
7885
0
    tp = state->ClassDef_type;
7886
0
    isinstance = PyObject_IsInstance(obj, tp);
7887
0
    if (isinstance == -1) {
7888
0
        return -1;
7889
0
    }
7890
0
    if (isinstance) {
7891
0
        identifier name;
7892
0
        asdl_expr_seq* bases;
7893
0
        asdl_keyword_seq* keywords;
7894
0
        asdl_stmt_seq* body;
7895
0
        asdl_expr_seq* decorator_list;
7896
0
        asdl_type_param_seq* type_params;
7897
7898
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7899
0
            return -1;
7900
0
        }
7901
0
        if (tmp == NULL) {
7902
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
7903
0
            return -1;
7904
0
        }
7905
0
        else {
7906
0
            int res;
7907
0
            if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7908
0
                goto failed;
7909
0
            }
7910
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7911
0
            _Py_LeaveRecursiveCall();
7912
0
            if (res != 0) goto failed;
7913
0
            Py_CLEAR(tmp);
7914
0
        }
7915
0
        if (PyObject_GetOptionalAttr(obj, state->bases, &tmp) < 0) {
7916
0
            return -1;
7917
0
        }
7918
0
        if (tmp == NULL) {
7919
0
            tmp = PyList_New(0);
7920
0
            if (tmp == NULL) {
7921
0
                return -1;
7922
0
            }
7923
0
        }
7924
0
        {
7925
0
            int res;
7926
0
            Py_ssize_t len;
7927
0
            Py_ssize_t i;
7928
0
            if (!PyList_Check(tmp)) {
7929
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %T", tmp);
7930
0
                goto failed;
7931
0
            }
7932
0
            len = PyList_GET_SIZE(tmp);
7933
0
            bases = _Py_asdl_expr_seq_new(len, arena);
7934
0
            if (bases == NULL) goto failed;
7935
0
            for (i = 0; i < len; i++) {
7936
0
                expr_ty val;
7937
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7938
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7939
0
                    goto failed;
7940
0
                }
7941
0
                res = obj2ast_expr(state, tmp2, &val, "bases", arena);
7942
0
                _Py_LeaveRecursiveCall();
7943
0
                Py_DECREF(tmp2);
7944
0
                if (res != 0) goto failed;
7945
0
                if (len != PyList_GET_SIZE(tmp)) {
7946
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
7947
0
                    goto failed;
7948
0
                }
7949
0
                asdl_seq_SET(bases, i, val);
7950
0
            }
7951
0
            Py_CLEAR(tmp);
7952
0
        }
7953
0
        if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
7954
0
            return -1;
7955
0
        }
7956
0
        if (tmp == NULL) {
7957
0
            tmp = PyList_New(0);
7958
0
            if (tmp == NULL) {
7959
0
                return -1;
7960
0
            }
7961
0
        }
7962
0
        {
7963
0
            int res;
7964
0
            Py_ssize_t len;
7965
0
            Py_ssize_t i;
7966
0
            if (!PyList_Check(tmp)) {
7967
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %T", tmp);
7968
0
                goto failed;
7969
0
            }
7970
0
            len = PyList_GET_SIZE(tmp);
7971
0
            keywords = _Py_asdl_keyword_seq_new(len, arena);
7972
0
            if (keywords == NULL) goto failed;
7973
0
            for (i = 0; i < len; i++) {
7974
0
                keyword_ty val;
7975
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7976
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7977
0
                    goto failed;
7978
0
                }
7979
0
                res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
7980
0
                _Py_LeaveRecursiveCall();
7981
0
                Py_DECREF(tmp2);
7982
0
                if (res != 0) goto failed;
7983
0
                if (len != PyList_GET_SIZE(tmp)) {
7984
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
7985
0
                    goto failed;
7986
0
                }
7987
0
                asdl_seq_SET(keywords, i, val);
7988
0
            }
7989
0
            Py_CLEAR(tmp);
7990
0
        }
7991
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7992
0
            return -1;
7993
0
        }
7994
0
        if (tmp == NULL) {
7995
0
            tmp = PyList_New(0);
7996
0
            if (tmp == NULL) {
7997
0
                return -1;
7998
0
            }
7999
0
        }
8000
0
        {
8001
0
            int res;
8002
0
            Py_ssize_t len;
8003
0
            Py_ssize_t i;
8004
0
            if (!PyList_Check(tmp)) {
8005
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %T", tmp);
8006
0
                goto failed;
8007
0
            }
8008
0
            len = PyList_GET_SIZE(tmp);
8009
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8010
0
            if (body == NULL) goto failed;
8011
0
            for (i = 0; i < len; i++) {
8012
0
                stmt_ty val;
8013
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8014
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8015
0
                    goto failed;
8016
0
                }
8017
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8018
0
                _Py_LeaveRecursiveCall();
8019
0
                Py_DECREF(tmp2);
8020
0
                if (res != 0) goto failed;
8021
0
                if (len != PyList_GET_SIZE(tmp)) {
8022
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
8023
0
                    goto failed;
8024
0
                }
8025
0
                asdl_seq_SET(body, i, val);
8026
0
            }
8027
0
            Py_CLEAR(tmp);
8028
0
        }
8029
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
8030
0
            return -1;
8031
0
        }
8032
0
        if (tmp == NULL) {
8033
0
            tmp = PyList_New(0);
8034
0
            if (tmp == NULL) {
8035
0
                return -1;
8036
0
            }
8037
0
        }
8038
0
        {
8039
0
            int res;
8040
0
            Py_ssize_t len;
8041
0
            Py_ssize_t i;
8042
0
            if (!PyList_Check(tmp)) {
8043
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %T", tmp);
8044
0
                goto failed;
8045
0
            }
8046
0
            len = PyList_GET_SIZE(tmp);
8047
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
8048
0
            if (decorator_list == NULL) goto failed;
8049
0
            for (i = 0; i < len; i++) {
8050
0
                expr_ty val;
8051
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8052
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8053
0
                    goto failed;
8054
0
                }
8055
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
8056
0
                _Py_LeaveRecursiveCall();
8057
0
                Py_DECREF(tmp2);
8058
0
                if (res != 0) goto failed;
8059
0
                if (len != PyList_GET_SIZE(tmp)) {
8060
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
8061
0
                    goto failed;
8062
0
                }
8063
0
                asdl_seq_SET(decorator_list, i, val);
8064
0
            }
8065
0
            Py_CLEAR(tmp);
8066
0
        }
8067
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
8068
0
            return -1;
8069
0
        }
8070
0
        if (tmp == NULL) {
8071
0
            tmp = PyList_New(0);
8072
0
            if (tmp == NULL) {
8073
0
                return -1;
8074
0
            }
8075
0
        }
8076
0
        {
8077
0
            int res;
8078
0
            Py_ssize_t len;
8079
0
            Py_ssize_t i;
8080
0
            if (!PyList_Check(tmp)) {
8081
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %T", tmp);
8082
0
                goto failed;
8083
0
            }
8084
0
            len = PyList_GET_SIZE(tmp);
8085
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
8086
0
            if (type_params == NULL) goto failed;
8087
0
            for (i = 0; i < len; i++) {
8088
0
                type_param_ty val;
8089
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8090
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8091
0
                    goto failed;
8092
0
                }
8093
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
8094
0
                _Py_LeaveRecursiveCall();
8095
0
                Py_DECREF(tmp2);
8096
0
                if (res != 0) goto failed;
8097
0
                if (len != PyList_GET_SIZE(tmp)) {
8098
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
8099
0
                    goto failed;
8100
0
                }
8101
0
                asdl_seq_SET(type_params, i, val);
8102
0
            }
8103
0
            Py_CLEAR(tmp);
8104
0
        }
8105
0
        *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
8106
0
                               type_params, lineno, col_offset, end_lineno,
8107
0
                               end_col_offset, arena);
8108
0
        if (*out == NULL) goto failed;
8109
0
        return 0;
8110
0
    }
8111
0
    tp = state->Return_type;
8112
0
    isinstance = PyObject_IsInstance(obj, tp);
8113
0
    if (isinstance == -1) {
8114
0
        return -1;
8115
0
    }
8116
0
    if (isinstance) {
8117
0
        expr_ty value;
8118
8119
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8120
0
            return -1;
8121
0
        }
8122
0
        if (tmp == NULL || tmp == Py_None) {
8123
0
            Py_CLEAR(tmp);
8124
0
            value = NULL;
8125
0
        }
8126
0
        else {
8127
0
            int res;
8128
0
            if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
8129
0
                goto failed;
8130
0
            }
8131
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8132
0
            _Py_LeaveRecursiveCall();
8133
0
            if (res != 0) goto failed;
8134
0
            Py_CLEAR(tmp);
8135
0
        }
8136
0
        *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
8137
0
                             end_col_offset, arena);
8138
0
        if (*out == NULL) goto failed;
8139
0
        return 0;
8140
0
    }
8141
0
    tp = state->Delete_type;
8142
0
    isinstance = PyObject_IsInstance(obj, tp);
8143
0
    if (isinstance == -1) {
8144
0
        return -1;
8145
0
    }
8146
0
    if (isinstance) {
8147
0
        asdl_expr_seq* targets;
8148
8149
0
        if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
8150
0
            return -1;
8151
0
        }
8152
0
        if (tmp == NULL) {
8153
0
            tmp = PyList_New(0);
8154
0
            if (tmp == NULL) {
8155
0
                return -1;
8156
0
            }
8157
0
        }
8158
0
        {
8159
0
            int res;
8160
0
            Py_ssize_t len;
8161
0
            Py_ssize_t i;
8162
0
            if (!PyList_Check(tmp)) {
8163
0
                PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %T", tmp);
8164
0
                goto failed;
8165
0
            }
8166
0
            len = PyList_GET_SIZE(tmp);
8167
0
            targets = _Py_asdl_expr_seq_new(len, arena);
8168
0
            if (targets == NULL) goto failed;
8169
0
            for (i = 0; i < len; i++) {
8170
0
                expr_ty val;
8171
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8172
0
                if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
8173
0
                    goto failed;
8174
0
                }
8175
0
                res = obj2ast_expr(state, tmp2, &val, "targets", arena);
8176
0
                _Py_LeaveRecursiveCall();
8177
0
                Py_DECREF(tmp2);
8178
0
                if (res != 0) goto failed;
8179
0
                if (len != PyList_GET_SIZE(tmp)) {
8180
0
                    PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
8181
0
                    goto failed;
8182
0
                }
8183
0
                asdl_seq_SET(targets, i, val);
8184
0
            }
8185
0
            Py_CLEAR(tmp);
8186
0
        }
8187
0
        *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
8188
0
                             end_col_offset, arena);
8189
0
        if (*out == NULL) goto failed;
8190
0
        return 0;
8191
0
    }
8192
0
    tp = state->Assign_type;
8193
0
    isinstance = PyObject_IsInstance(obj, tp);
8194
0
    if (isinstance == -1) {
8195
0
        return -1;
8196
0
    }
8197
0
    if (isinstance) {
8198
0
        asdl_expr_seq* targets;
8199
0
        expr_ty value;
8200
0
        string type_comment;
8201
8202
0
        if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
8203
0
            return -1;
8204
0
        }
8205
0
        if (tmp == NULL) {
8206
0
            tmp = PyList_New(0);
8207
0
            if (tmp == NULL) {
8208
0
                return -1;
8209
0
            }
8210
0
        }
8211
0
        {
8212
0
            int res;
8213
0
            Py_ssize_t len;
8214
0
            Py_ssize_t i;
8215
0
            if (!PyList_Check(tmp)) {
8216
0
                PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %T", tmp);
8217
0
                goto failed;
8218
0
            }
8219
0
            len = PyList_GET_SIZE(tmp);
8220
0
            targets = _Py_asdl_expr_seq_new(len, arena);
8221
0
            if (targets == NULL) goto failed;
8222
0
            for (i = 0; i < len; i++) {
8223
0
                expr_ty val;
8224
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8225
0
                if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8226
0
                    goto failed;
8227
0
                }
8228
0
                res = obj2ast_expr(state, tmp2, &val, "targets", arena);
8229
0
                _Py_LeaveRecursiveCall();
8230
0
                Py_DECREF(tmp2);
8231
0
                if (res != 0) goto failed;
8232
0
                if (len != PyList_GET_SIZE(tmp)) {
8233
0
                    PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
8234
0
                    goto failed;
8235
0
                }
8236
0
                asdl_seq_SET(targets, i, val);
8237
0
            }
8238
0
            Py_CLEAR(tmp);
8239
0
        }
8240
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8241
0
            return -1;
8242
0
        }
8243
0
        if (tmp == NULL) {
8244
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
8245
0
            return -1;
8246
0
        }
8247
0
        else {
8248
0
            int res;
8249
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8250
0
                goto failed;
8251
0
            }
8252
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8253
0
            _Py_LeaveRecursiveCall();
8254
0
            if (res != 0) goto failed;
8255
0
            Py_CLEAR(tmp);
8256
0
        }
8257
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8258
0
            return -1;
8259
0
        }
8260
0
        if (tmp == NULL || tmp == Py_None) {
8261
0
            Py_CLEAR(tmp);
8262
0
            type_comment = NULL;
8263
0
        }
8264
0
        else {
8265
0
            int res;
8266
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8267
0
                goto failed;
8268
0
            }
8269
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8270
0
                                 arena);
8271
0
            _Py_LeaveRecursiveCall();
8272
0
            if (res != 0) goto failed;
8273
0
            Py_CLEAR(tmp);
8274
0
        }
8275
0
        *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
8276
0
                             end_lineno, end_col_offset, arena);
8277
0
        if (*out == NULL) goto failed;
8278
0
        return 0;
8279
0
    }
8280
0
    tp = state->TypeAlias_type;
8281
0
    isinstance = PyObject_IsInstance(obj, tp);
8282
0
    if (isinstance == -1) {
8283
0
        return -1;
8284
0
    }
8285
0
    if (isinstance) {
8286
0
        expr_ty name;
8287
0
        asdl_type_param_seq* type_params;
8288
0
        expr_ty value;
8289
8290
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
8291
0
            return -1;
8292
0
        }
8293
0
        if (tmp == NULL) {
8294
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
8295
0
            return -1;
8296
0
        }
8297
0
        else {
8298
0
            int res;
8299
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8300
0
                goto failed;
8301
0
            }
8302
0
            res = obj2ast_expr(state, tmp, &name, "name", arena);
8303
0
            _Py_LeaveRecursiveCall();
8304
0
            if (res != 0) goto failed;
8305
0
            Py_CLEAR(tmp);
8306
0
        }
8307
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
8308
0
            return -1;
8309
0
        }
8310
0
        if (tmp == NULL) {
8311
0
            tmp = PyList_New(0);
8312
0
            if (tmp == NULL) {
8313
0
                return -1;
8314
0
            }
8315
0
        }
8316
0
        {
8317
0
            int res;
8318
0
            Py_ssize_t len;
8319
0
            Py_ssize_t i;
8320
0
            if (!PyList_Check(tmp)) {
8321
0
                PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %T", tmp);
8322
0
                goto failed;
8323
0
            }
8324
0
            len = PyList_GET_SIZE(tmp);
8325
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
8326
0
            if (type_params == NULL) goto failed;
8327
0
            for (i = 0; i < len; i++) {
8328
0
                type_param_ty val;
8329
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8330
0
                if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8331
0
                    goto failed;
8332
0
                }
8333
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
8334
0
                _Py_LeaveRecursiveCall();
8335
0
                Py_DECREF(tmp2);
8336
0
                if (res != 0) goto failed;
8337
0
                if (len != PyList_GET_SIZE(tmp)) {
8338
0
                    PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
8339
0
                    goto failed;
8340
0
                }
8341
0
                asdl_seq_SET(type_params, i, val);
8342
0
            }
8343
0
            Py_CLEAR(tmp);
8344
0
        }
8345
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8346
0
            return -1;
8347
0
        }
8348
0
        if (tmp == NULL) {
8349
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
8350
0
            return -1;
8351
0
        }
8352
0
        else {
8353
0
            int res;
8354
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8355
0
                goto failed;
8356
0
            }
8357
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8358
0
            _Py_LeaveRecursiveCall();
8359
0
            if (res != 0) goto failed;
8360
0
            Py_CLEAR(tmp);
8361
0
        }
8362
0
        *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
8363
0
                                end_lineno, end_col_offset, arena);
8364
0
        if (*out == NULL) goto failed;
8365
0
        return 0;
8366
0
    }
8367
0
    tp = state->AugAssign_type;
8368
0
    isinstance = PyObject_IsInstance(obj, tp);
8369
0
    if (isinstance == -1) {
8370
0
        return -1;
8371
0
    }
8372
0
    if (isinstance) {
8373
0
        expr_ty target;
8374
0
        operator_ty op;
8375
0
        expr_ty value;
8376
8377
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8378
0
            return -1;
8379
0
        }
8380
0
        if (tmp == NULL) {
8381
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
8382
0
            return -1;
8383
0
        }
8384
0
        else {
8385
0
            int res;
8386
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8387
0
                goto failed;
8388
0
            }
8389
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8390
0
            _Py_LeaveRecursiveCall();
8391
0
            if (res != 0) goto failed;
8392
0
            Py_CLEAR(tmp);
8393
0
        }
8394
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
8395
0
            return -1;
8396
0
        }
8397
0
        if (tmp == NULL) {
8398
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
8399
0
            return -1;
8400
0
        }
8401
0
        else {
8402
0
            int res;
8403
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8404
0
                goto failed;
8405
0
            }
8406
0
            res = obj2ast_operator(state, tmp, &op, "op", arena);
8407
0
            _Py_LeaveRecursiveCall();
8408
0
            if (res != 0) goto failed;
8409
0
            Py_CLEAR(tmp);
8410
0
        }
8411
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8412
0
            return -1;
8413
0
        }
8414
0
        if (tmp == NULL) {
8415
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
8416
0
            return -1;
8417
0
        }
8418
0
        else {
8419
0
            int res;
8420
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8421
0
                goto failed;
8422
0
            }
8423
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8424
0
            _Py_LeaveRecursiveCall();
8425
0
            if (res != 0) goto failed;
8426
0
            Py_CLEAR(tmp);
8427
0
        }
8428
0
        *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
8429
0
                                end_lineno, end_col_offset, arena);
8430
0
        if (*out == NULL) goto failed;
8431
0
        return 0;
8432
0
    }
8433
0
    tp = state->AnnAssign_type;
8434
0
    isinstance = PyObject_IsInstance(obj, tp);
8435
0
    if (isinstance == -1) {
8436
0
        return -1;
8437
0
    }
8438
0
    if (isinstance) {
8439
0
        expr_ty target;
8440
0
        expr_ty annotation;
8441
0
        expr_ty value;
8442
0
        int simple;
8443
8444
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8445
0
            return -1;
8446
0
        }
8447
0
        if (tmp == NULL) {
8448
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
8449
0
            return -1;
8450
0
        }
8451
0
        else {
8452
0
            int res;
8453
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8454
0
                goto failed;
8455
0
            }
8456
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8457
0
            _Py_LeaveRecursiveCall();
8458
0
            if (res != 0) goto failed;
8459
0
            Py_CLEAR(tmp);
8460
0
        }
8461
0
        if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
8462
0
            return -1;
8463
0
        }
8464
0
        if (tmp == NULL) {
8465
0
            PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
8466
0
            return -1;
8467
0
        }
8468
0
        else {
8469
0
            int res;
8470
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8471
0
                goto failed;
8472
0
            }
8473
0
            res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
8474
0
            _Py_LeaveRecursiveCall();
8475
0
            if (res != 0) goto failed;
8476
0
            Py_CLEAR(tmp);
8477
0
        }
8478
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8479
0
            return -1;
8480
0
        }
8481
0
        if (tmp == NULL || tmp == Py_None) {
8482
0
            Py_CLEAR(tmp);
8483
0
            value = NULL;
8484
0
        }
8485
0
        else {
8486
0
            int res;
8487
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8488
0
                goto failed;
8489
0
            }
8490
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8491
0
            _Py_LeaveRecursiveCall();
8492
0
            if (res != 0) goto failed;
8493
0
            Py_CLEAR(tmp);
8494
0
        }
8495
0
        if (PyObject_GetOptionalAttr(obj, state->simple, &tmp) < 0) {
8496
0
            return -1;
8497
0
        }
8498
0
        if (tmp == NULL) {
8499
0
            PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
8500
0
            return -1;
8501
0
        }
8502
0
        else {
8503
0
            int res;
8504
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8505
0
                goto failed;
8506
0
            }
8507
0
            res = obj2ast_int(state, tmp, &simple, "simple", arena);
8508
0
            _Py_LeaveRecursiveCall();
8509
0
            if (res != 0) goto failed;
8510
0
            Py_CLEAR(tmp);
8511
0
        }
8512
0
        *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
8513
0
                                col_offset, end_lineno, end_col_offset, arena);
8514
0
        if (*out == NULL) goto failed;
8515
0
        return 0;
8516
0
    }
8517
0
    tp = state->For_type;
8518
0
    isinstance = PyObject_IsInstance(obj, tp);
8519
0
    if (isinstance == -1) {
8520
0
        return -1;
8521
0
    }
8522
0
    if (isinstance) {
8523
0
        expr_ty target;
8524
0
        expr_ty iter;
8525
0
        asdl_stmt_seq* body;
8526
0
        asdl_stmt_seq* orelse;
8527
0
        string type_comment;
8528
8529
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8530
0
            return -1;
8531
0
        }
8532
0
        if (tmp == NULL) {
8533
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
8534
0
            return -1;
8535
0
        }
8536
0
        else {
8537
0
            int res;
8538
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8539
0
                goto failed;
8540
0
            }
8541
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8542
0
            _Py_LeaveRecursiveCall();
8543
0
            if (res != 0) goto failed;
8544
0
            Py_CLEAR(tmp);
8545
0
        }
8546
0
        if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
8547
0
            return -1;
8548
0
        }
8549
0
        if (tmp == NULL) {
8550
0
            PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
8551
0
            return -1;
8552
0
        }
8553
0
        else {
8554
0
            int res;
8555
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8556
0
                goto failed;
8557
0
            }
8558
0
            res = obj2ast_expr(state, tmp, &iter, "iter", arena);
8559
0
            _Py_LeaveRecursiveCall();
8560
0
            if (res != 0) goto failed;
8561
0
            Py_CLEAR(tmp);
8562
0
        }
8563
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8564
0
            return -1;
8565
0
        }
8566
0
        if (tmp == NULL) {
8567
0
            tmp = PyList_New(0);
8568
0
            if (tmp == NULL) {
8569
0
                return -1;
8570
0
            }
8571
0
        }
8572
0
        {
8573
0
            int res;
8574
0
            Py_ssize_t len;
8575
0
            Py_ssize_t i;
8576
0
            if (!PyList_Check(tmp)) {
8577
0
                PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %T", tmp);
8578
0
                goto failed;
8579
0
            }
8580
0
            len = PyList_GET_SIZE(tmp);
8581
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8582
0
            if (body == NULL) goto failed;
8583
0
            for (i = 0; i < len; i++) {
8584
0
                stmt_ty val;
8585
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8586
0
                if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8587
0
                    goto failed;
8588
0
                }
8589
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8590
0
                _Py_LeaveRecursiveCall();
8591
0
                Py_DECREF(tmp2);
8592
0
                if (res != 0) goto failed;
8593
0
                if (len != PyList_GET_SIZE(tmp)) {
8594
0
                    PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
8595
0
                    goto failed;
8596
0
                }
8597
0
                asdl_seq_SET(body, i, val);
8598
0
            }
8599
0
            Py_CLEAR(tmp);
8600
0
        }
8601
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8602
0
            return -1;
8603
0
        }
8604
0
        if (tmp == NULL) {
8605
0
            tmp = PyList_New(0);
8606
0
            if (tmp == NULL) {
8607
0
                return -1;
8608
0
            }
8609
0
        }
8610
0
        {
8611
0
            int res;
8612
0
            Py_ssize_t len;
8613
0
            Py_ssize_t i;
8614
0
            if (!PyList_Check(tmp)) {
8615
0
                PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %T", tmp);
8616
0
                goto failed;
8617
0
            }
8618
0
            len = PyList_GET_SIZE(tmp);
8619
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8620
0
            if (orelse == NULL) goto failed;
8621
0
            for (i = 0; i < len; i++) {
8622
0
                stmt_ty val;
8623
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8624
0
                if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8625
0
                    goto failed;
8626
0
                }
8627
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8628
0
                _Py_LeaveRecursiveCall();
8629
0
                Py_DECREF(tmp2);
8630
0
                if (res != 0) goto failed;
8631
0
                if (len != PyList_GET_SIZE(tmp)) {
8632
0
                    PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
8633
0
                    goto failed;
8634
0
                }
8635
0
                asdl_seq_SET(orelse, i, val);
8636
0
            }
8637
0
            Py_CLEAR(tmp);
8638
0
        }
8639
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8640
0
            return -1;
8641
0
        }
8642
0
        if (tmp == NULL || tmp == Py_None) {
8643
0
            Py_CLEAR(tmp);
8644
0
            type_comment = NULL;
8645
0
        }
8646
0
        else {
8647
0
            int res;
8648
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8649
0
                goto failed;
8650
0
            }
8651
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8652
0
                                 arena);
8653
0
            _Py_LeaveRecursiveCall();
8654
0
            if (res != 0) goto failed;
8655
0
            Py_CLEAR(tmp);
8656
0
        }
8657
0
        *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
8658
0
                          col_offset, end_lineno, end_col_offset, arena);
8659
0
        if (*out == NULL) goto failed;
8660
0
        return 0;
8661
0
    }
8662
0
    tp = state->AsyncFor_type;
8663
0
    isinstance = PyObject_IsInstance(obj, tp);
8664
0
    if (isinstance == -1) {
8665
0
        return -1;
8666
0
    }
8667
0
    if (isinstance) {
8668
0
        expr_ty target;
8669
0
        expr_ty iter;
8670
0
        asdl_stmt_seq* body;
8671
0
        asdl_stmt_seq* orelse;
8672
0
        string type_comment;
8673
8674
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8675
0
            return -1;
8676
0
        }
8677
0
        if (tmp == NULL) {
8678
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
8679
0
            return -1;
8680
0
        }
8681
0
        else {
8682
0
            int res;
8683
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8684
0
                goto failed;
8685
0
            }
8686
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8687
0
            _Py_LeaveRecursiveCall();
8688
0
            if (res != 0) goto failed;
8689
0
            Py_CLEAR(tmp);
8690
0
        }
8691
0
        if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
8692
0
            return -1;
8693
0
        }
8694
0
        if (tmp == NULL) {
8695
0
            PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
8696
0
            return -1;
8697
0
        }
8698
0
        else {
8699
0
            int res;
8700
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8701
0
                goto failed;
8702
0
            }
8703
0
            res = obj2ast_expr(state, tmp, &iter, "iter", arena);
8704
0
            _Py_LeaveRecursiveCall();
8705
0
            if (res != 0) goto failed;
8706
0
            Py_CLEAR(tmp);
8707
0
        }
8708
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8709
0
            return -1;
8710
0
        }
8711
0
        if (tmp == NULL) {
8712
0
            tmp = PyList_New(0);
8713
0
            if (tmp == NULL) {
8714
0
                return -1;
8715
0
            }
8716
0
        }
8717
0
        {
8718
0
            int res;
8719
0
            Py_ssize_t len;
8720
0
            Py_ssize_t i;
8721
0
            if (!PyList_Check(tmp)) {
8722
0
                PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %T", tmp);
8723
0
                goto failed;
8724
0
            }
8725
0
            len = PyList_GET_SIZE(tmp);
8726
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8727
0
            if (body == NULL) goto failed;
8728
0
            for (i = 0; i < len; i++) {
8729
0
                stmt_ty val;
8730
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8731
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8732
0
                    goto failed;
8733
0
                }
8734
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8735
0
                _Py_LeaveRecursiveCall();
8736
0
                Py_DECREF(tmp2);
8737
0
                if (res != 0) goto failed;
8738
0
                if (len != PyList_GET_SIZE(tmp)) {
8739
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
8740
0
                    goto failed;
8741
0
                }
8742
0
                asdl_seq_SET(body, i, val);
8743
0
            }
8744
0
            Py_CLEAR(tmp);
8745
0
        }
8746
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8747
0
            return -1;
8748
0
        }
8749
0
        if (tmp == NULL) {
8750
0
            tmp = PyList_New(0);
8751
0
            if (tmp == NULL) {
8752
0
                return -1;
8753
0
            }
8754
0
        }
8755
0
        {
8756
0
            int res;
8757
0
            Py_ssize_t len;
8758
0
            Py_ssize_t i;
8759
0
            if (!PyList_Check(tmp)) {
8760
0
                PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %T", tmp);
8761
0
                goto failed;
8762
0
            }
8763
0
            len = PyList_GET_SIZE(tmp);
8764
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8765
0
            if (orelse == NULL) goto failed;
8766
0
            for (i = 0; i < len; i++) {
8767
0
                stmt_ty val;
8768
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8769
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8770
0
                    goto failed;
8771
0
                }
8772
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8773
0
                _Py_LeaveRecursiveCall();
8774
0
                Py_DECREF(tmp2);
8775
0
                if (res != 0) goto failed;
8776
0
                if (len != PyList_GET_SIZE(tmp)) {
8777
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
8778
0
                    goto failed;
8779
0
                }
8780
0
                asdl_seq_SET(orelse, i, val);
8781
0
            }
8782
0
            Py_CLEAR(tmp);
8783
0
        }
8784
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8785
0
            return -1;
8786
0
        }
8787
0
        if (tmp == NULL || tmp == Py_None) {
8788
0
            Py_CLEAR(tmp);
8789
0
            type_comment = NULL;
8790
0
        }
8791
0
        else {
8792
0
            int res;
8793
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8794
0
                goto failed;
8795
0
            }
8796
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8797
0
                                 arena);
8798
0
            _Py_LeaveRecursiveCall();
8799
0
            if (res != 0) goto failed;
8800
0
            Py_CLEAR(tmp);
8801
0
        }
8802
0
        *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
8803
0
                               lineno, col_offset, end_lineno, end_col_offset,
8804
0
                               arena);
8805
0
        if (*out == NULL) goto failed;
8806
0
        return 0;
8807
0
    }
8808
0
    tp = state->While_type;
8809
0
    isinstance = PyObject_IsInstance(obj, tp);
8810
0
    if (isinstance == -1) {
8811
0
        return -1;
8812
0
    }
8813
0
    if (isinstance) {
8814
0
        expr_ty test;
8815
0
        asdl_stmt_seq* body;
8816
0
        asdl_stmt_seq* orelse;
8817
8818
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
8819
0
            return -1;
8820
0
        }
8821
0
        if (tmp == NULL) {
8822
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
8823
0
            return -1;
8824
0
        }
8825
0
        else {
8826
0
            int res;
8827
0
            if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8828
0
                goto failed;
8829
0
            }
8830
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
8831
0
            _Py_LeaveRecursiveCall();
8832
0
            if (res != 0) goto failed;
8833
0
            Py_CLEAR(tmp);
8834
0
        }
8835
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8836
0
            return -1;
8837
0
        }
8838
0
        if (tmp == NULL) {
8839
0
            tmp = PyList_New(0);
8840
0
            if (tmp == NULL) {
8841
0
                return -1;
8842
0
            }
8843
0
        }
8844
0
        {
8845
0
            int res;
8846
0
            Py_ssize_t len;
8847
0
            Py_ssize_t i;
8848
0
            if (!PyList_Check(tmp)) {
8849
0
                PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %T", tmp);
8850
0
                goto failed;
8851
0
            }
8852
0
            len = PyList_GET_SIZE(tmp);
8853
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8854
0
            if (body == NULL) goto failed;
8855
0
            for (i = 0; i < len; i++) {
8856
0
                stmt_ty val;
8857
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8858
0
                if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8859
0
                    goto failed;
8860
0
                }
8861
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8862
0
                _Py_LeaveRecursiveCall();
8863
0
                Py_DECREF(tmp2);
8864
0
                if (res != 0) goto failed;
8865
0
                if (len != PyList_GET_SIZE(tmp)) {
8866
0
                    PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
8867
0
                    goto failed;
8868
0
                }
8869
0
                asdl_seq_SET(body, i, val);
8870
0
            }
8871
0
            Py_CLEAR(tmp);
8872
0
        }
8873
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8874
0
            return -1;
8875
0
        }
8876
0
        if (tmp == NULL) {
8877
0
            tmp = PyList_New(0);
8878
0
            if (tmp == NULL) {
8879
0
                return -1;
8880
0
            }
8881
0
        }
8882
0
        {
8883
0
            int res;
8884
0
            Py_ssize_t len;
8885
0
            Py_ssize_t i;
8886
0
            if (!PyList_Check(tmp)) {
8887
0
                PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %T", tmp);
8888
0
                goto failed;
8889
0
            }
8890
0
            len = PyList_GET_SIZE(tmp);
8891
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8892
0
            if (orelse == NULL) goto failed;
8893
0
            for (i = 0; i < len; i++) {
8894
0
                stmt_ty val;
8895
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8896
0
                if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8897
0
                    goto failed;
8898
0
                }
8899
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8900
0
                _Py_LeaveRecursiveCall();
8901
0
                Py_DECREF(tmp2);
8902
0
                if (res != 0) goto failed;
8903
0
                if (len != PyList_GET_SIZE(tmp)) {
8904
0
                    PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
8905
0
                    goto failed;
8906
0
                }
8907
0
                asdl_seq_SET(orelse, i, val);
8908
0
            }
8909
0
            Py_CLEAR(tmp);
8910
0
        }
8911
0
        *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
8912
0
                            end_col_offset, arena);
8913
0
        if (*out == NULL) goto failed;
8914
0
        return 0;
8915
0
    }
8916
0
    tp = state->If_type;
8917
0
    isinstance = PyObject_IsInstance(obj, tp);
8918
0
    if (isinstance == -1) {
8919
0
        return -1;
8920
0
    }
8921
0
    if (isinstance) {
8922
0
        expr_ty test;
8923
0
        asdl_stmt_seq* body;
8924
0
        asdl_stmt_seq* orelse;
8925
8926
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
8927
0
            return -1;
8928
0
        }
8929
0
        if (tmp == NULL) {
8930
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
8931
0
            return -1;
8932
0
        }
8933
0
        else {
8934
0
            int res;
8935
0
            if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
8936
0
                goto failed;
8937
0
            }
8938
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
8939
0
            _Py_LeaveRecursiveCall();
8940
0
            if (res != 0) goto failed;
8941
0
            Py_CLEAR(tmp);
8942
0
        }
8943
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8944
0
            return -1;
8945
0
        }
8946
0
        if (tmp == NULL) {
8947
0
            tmp = PyList_New(0);
8948
0
            if (tmp == NULL) {
8949
0
                return -1;
8950
0
            }
8951
0
        }
8952
0
        {
8953
0
            int res;
8954
0
            Py_ssize_t len;
8955
0
            Py_ssize_t i;
8956
0
            if (!PyList_Check(tmp)) {
8957
0
                PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %T", tmp);
8958
0
                goto failed;
8959
0
            }
8960
0
            len = PyList_GET_SIZE(tmp);
8961
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8962
0
            if (body == NULL) goto failed;
8963
0
            for (i = 0; i < len; i++) {
8964
0
                stmt_ty val;
8965
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8966
0
                if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
8967
0
                    goto failed;
8968
0
                }
8969
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8970
0
                _Py_LeaveRecursiveCall();
8971
0
                Py_DECREF(tmp2);
8972
0
                if (res != 0) goto failed;
8973
0
                if (len != PyList_GET_SIZE(tmp)) {
8974
0
                    PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
8975
0
                    goto failed;
8976
0
                }
8977
0
                asdl_seq_SET(body, i, val);
8978
0
            }
8979
0
            Py_CLEAR(tmp);
8980
0
        }
8981
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8982
0
            return -1;
8983
0
        }
8984
0
        if (tmp == NULL) {
8985
0
            tmp = PyList_New(0);
8986
0
            if (tmp == NULL) {
8987
0
                return -1;
8988
0
            }
8989
0
        }
8990
0
        {
8991
0
            int res;
8992
0
            Py_ssize_t len;
8993
0
            Py_ssize_t i;
8994
0
            if (!PyList_Check(tmp)) {
8995
0
                PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %T", tmp);
8996
0
                goto failed;
8997
0
            }
8998
0
            len = PyList_GET_SIZE(tmp);
8999
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
9000
0
            if (orelse == NULL) goto failed;
9001
0
            for (i = 0; i < len; i++) {
9002
0
                stmt_ty val;
9003
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9004
0
                if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
9005
0
                    goto failed;
9006
0
                }
9007
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9008
0
                _Py_LeaveRecursiveCall();
9009
0
                Py_DECREF(tmp2);
9010
0
                if (res != 0) goto failed;
9011
0
                if (len != PyList_GET_SIZE(tmp)) {
9012
0
                    PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
9013
0
                    goto failed;
9014
0
                }
9015
0
                asdl_seq_SET(orelse, i, val);
9016
0
            }
9017
0
            Py_CLEAR(tmp);
9018
0
        }
9019
0
        *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
9020
0
                         end_col_offset, arena);
9021
0
        if (*out == NULL) goto failed;
9022
0
        return 0;
9023
0
    }
9024
0
    tp = state->With_type;
9025
0
    isinstance = PyObject_IsInstance(obj, tp);
9026
0
    if (isinstance == -1) {
9027
0
        return -1;
9028
0
    }
9029
0
    if (isinstance) {
9030
0
        asdl_withitem_seq* items;
9031
0
        asdl_stmt_seq* body;
9032
0
        string type_comment;
9033
9034
0
        if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
9035
0
            return -1;
9036
0
        }
9037
0
        if (tmp == NULL) {
9038
0
            tmp = PyList_New(0);
9039
0
            if (tmp == NULL) {
9040
0
                return -1;
9041
0
            }
9042
0
        }
9043
0
        {
9044
0
            int res;
9045
0
            Py_ssize_t len;
9046
0
            Py_ssize_t i;
9047
0
            if (!PyList_Check(tmp)) {
9048
0
                PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %T", tmp);
9049
0
                goto failed;
9050
0
            }
9051
0
            len = PyList_GET_SIZE(tmp);
9052
0
            items = _Py_asdl_withitem_seq_new(len, arena);
9053
0
            if (items == NULL) goto failed;
9054
0
            for (i = 0; i < len; i++) {
9055
0
                withitem_ty val;
9056
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9057
0
                if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9058
0
                    goto failed;
9059
0
                }
9060
0
                res = obj2ast_withitem(state, tmp2, &val, "items", arena);
9061
0
                _Py_LeaveRecursiveCall();
9062
0
                Py_DECREF(tmp2);
9063
0
                if (res != 0) goto failed;
9064
0
                if (len != PyList_GET_SIZE(tmp)) {
9065
0
                    PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
9066
0
                    goto failed;
9067
0
                }
9068
0
                asdl_seq_SET(items, i, val);
9069
0
            }
9070
0
            Py_CLEAR(tmp);
9071
0
        }
9072
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9073
0
            return -1;
9074
0
        }
9075
0
        if (tmp == NULL) {
9076
0
            tmp = PyList_New(0);
9077
0
            if (tmp == NULL) {
9078
0
                return -1;
9079
0
            }
9080
0
        }
9081
0
        {
9082
0
            int res;
9083
0
            Py_ssize_t len;
9084
0
            Py_ssize_t i;
9085
0
            if (!PyList_Check(tmp)) {
9086
0
                PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %T", tmp);
9087
0
                goto failed;
9088
0
            }
9089
0
            len = PyList_GET_SIZE(tmp);
9090
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9091
0
            if (body == NULL) goto failed;
9092
0
            for (i = 0; i < len; i++) {
9093
0
                stmt_ty val;
9094
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9095
0
                if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9096
0
                    goto failed;
9097
0
                }
9098
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9099
0
                _Py_LeaveRecursiveCall();
9100
0
                Py_DECREF(tmp2);
9101
0
                if (res != 0) goto failed;
9102
0
                if (len != PyList_GET_SIZE(tmp)) {
9103
0
                    PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
9104
0
                    goto failed;
9105
0
                }
9106
0
                asdl_seq_SET(body, i, val);
9107
0
            }
9108
0
            Py_CLEAR(tmp);
9109
0
        }
9110
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
9111
0
            return -1;
9112
0
        }
9113
0
        if (tmp == NULL || tmp == Py_None) {
9114
0
            Py_CLEAR(tmp);
9115
0
            type_comment = NULL;
9116
0
        }
9117
0
        else {
9118
0
            int res;
9119
0
            if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9120
0
                goto failed;
9121
0
            }
9122
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
9123
0
                                 arena);
9124
0
            _Py_LeaveRecursiveCall();
9125
0
            if (res != 0) goto failed;
9126
0
            Py_CLEAR(tmp);
9127
0
        }
9128
0
        *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
9129
0
                           end_lineno, end_col_offset, arena);
9130
0
        if (*out == NULL) goto failed;
9131
0
        return 0;
9132
0
    }
9133
0
    tp = state->AsyncWith_type;
9134
0
    isinstance = PyObject_IsInstance(obj, tp);
9135
0
    if (isinstance == -1) {
9136
0
        return -1;
9137
0
    }
9138
0
    if (isinstance) {
9139
0
        asdl_withitem_seq* items;
9140
0
        asdl_stmt_seq* body;
9141
0
        string type_comment;
9142
9143
0
        if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
9144
0
            return -1;
9145
0
        }
9146
0
        if (tmp == NULL) {
9147
0
            tmp = PyList_New(0);
9148
0
            if (tmp == NULL) {
9149
0
                return -1;
9150
0
            }
9151
0
        }
9152
0
        {
9153
0
            int res;
9154
0
            Py_ssize_t len;
9155
0
            Py_ssize_t i;
9156
0
            if (!PyList_Check(tmp)) {
9157
0
                PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %T", tmp);
9158
0
                goto failed;
9159
0
            }
9160
0
            len = PyList_GET_SIZE(tmp);
9161
0
            items = _Py_asdl_withitem_seq_new(len, arena);
9162
0
            if (items == NULL) goto failed;
9163
0
            for (i = 0; i < len; i++) {
9164
0
                withitem_ty val;
9165
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9166
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9167
0
                    goto failed;
9168
0
                }
9169
0
                res = obj2ast_withitem(state, tmp2, &val, "items", arena);
9170
0
                _Py_LeaveRecursiveCall();
9171
0
                Py_DECREF(tmp2);
9172
0
                if (res != 0) goto failed;
9173
0
                if (len != PyList_GET_SIZE(tmp)) {
9174
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
9175
0
                    goto failed;
9176
0
                }
9177
0
                asdl_seq_SET(items, i, val);
9178
0
            }
9179
0
            Py_CLEAR(tmp);
9180
0
        }
9181
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9182
0
            return -1;
9183
0
        }
9184
0
        if (tmp == NULL) {
9185
0
            tmp = PyList_New(0);
9186
0
            if (tmp == NULL) {
9187
0
                return -1;
9188
0
            }
9189
0
        }
9190
0
        {
9191
0
            int res;
9192
0
            Py_ssize_t len;
9193
0
            Py_ssize_t i;
9194
0
            if (!PyList_Check(tmp)) {
9195
0
                PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %T", tmp);
9196
0
                goto failed;
9197
0
            }
9198
0
            len = PyList_GET_SIZE(tmp);
9199
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9200
0
            if (body == NULL) goto failed;
9201
0
            for (i = 0; i < len; i++) {
9202
0
                stmt_ty val;
9203
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9204
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9205
0
                    goto failed;
9206
0
                }
9207
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9208
0
                _Py_LeaveRecursiveCall();
9209
0
                Py_DECREF(tmp2);
9210
0
                if (res != 0) goto failed;
9211
0
                if (len != PyList_GET_SIZE(tmp)) {
9212
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
9213
0
                    goto failed;
9214
0
                }
9215
0
                asdl_seq_SET(body, i, val);
9216
0
            }
9217
0
            Py_CLEAR(tmp);
9218
0
        }
9219
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
9220
0
            return -1;
9221
0
        }
9222
0
        if (tmp == NULL || tmp == Py_None) {
9223
0
            Py_CLEAR(tmp);
9224
0
            type_comment = NULL;
9225
0
        }
9226
0
        else {
9227
0
            int res;
9228
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9229
0
                goto failed;
9230
0
            }
9231
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
9232
0
                                 arena);
9233
0
            _Py_LeaveRecursiveCall();
9234
0
            if (res != 0) goto failed;
9235
0
            Py_CLEAR(tmp);
9236
0
        }
9237
0
        *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
9238
0
                                end_lineno, end_col_offset, arena);
9239
0
        if (*out == NULL) goto failed;
9240
0
        return 0;
9241
0
    }
9242
0
    tp = state->Match_type;
9243
0
    isinstance = PyObject_IsInstance(obj, tp);
9244
0
    if (isinstance == -1) {
9245
0
        return -1;
9246
0
    }
9247
0
    if (isinstance) {
9248
0
        expr_ty subject;
9249
0
        asdl_match_case_seq* cases;
9250
9251
0
        if (PyObject_GetOptionalAttr(obj, state->subject, &tmp) < 0) {
9252
0
            return -1;
9253
0
        }
9254
0
        if (tmp == NULL) {
9255
0
            PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
9256
0
            return -1;
9257
0
        }
9258
0
        else {
9259
0
            int res;
9260
0
            if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
9261
0
                goto failed;
9262
0
            }
9263
0
            res = obj2ast_expr(state, tmp, &subject, "subject", arena);
9264
0
            _Py_LeaveRecursiveCall();
9265
0
            if (res != 0) goto failed;
9266
0
            Py_CLEAR(tmp);
9267
0
        }
9268
0
        if (PyObject_GetOptionalAttr(obj, state->cases, &tmp) < 0) {
9269
0
            return -1;
9270
0
        }
9271
0
        if (tmp == NULL) {
9272
0
            tmp = PyList_New(0);
9273
0
            if (tmp == NULL) {
9274
0
                return -1;
9275
0
            }
9276
0
        }
9277
0
        {
9278
0
            int res;
9279
0
            Py_ssize_t len;
9280
0
            Py_ssize_t i;
9281
0
            if (!PyList_Check(tmp)) {
9282
0
                PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %T", tmp);
9283
0
                goto failed;
9284
0
            }
9285
0
            len = PyList_GET_SIZE(tmp);
9286
0
            cases = _Py_asdl_match_case_seq_new(len, arena);
9287
0
            if (cases == NULL) goto failed;
9288
0
            for (i = 0; i < len; i++) {
9289
0
                match_case_ty val;
9290
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9291
0
                if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
9292
0
                    goto failed;
9293
0
                }
9294
0
                res = obj2ast_match_case(state, tmp2, &val, "cases", arena);
9295
0
                _Py_LeaveRecursiveCall();
9296
0
                Py_DECREF(tmp2);
9297
0
                if (res != 0) goto failed;
9298
0
                if (len != PyList_GET_SIZE(tmp)) {
9299
0
                    PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
9300
0
                    goto failed;
9301
0
                }
9302
0
                asdl_seq_SET(cases, i, val);
9303
0
            }
9304
0
            Py_CLEAR(tmp);
9305
0
        }
9306
0
        *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
9307
0
                            end_col_offset, arena);
9308
0
        if (*out == NULL) goto failed;
9309
0
        return 0;
9310
0
    }
9311
0
    tp = state->Raise_type;
9312
0
    isinstance = PyObject_IsInstance(obj, tp);
9313
0
    if (isinstance == -1) {
9314
0
        return -1;
9315
0
    }
9316
0
    if (isinstance) {
9317
0
        expr_ty exc;
9318
0
        expr_ty cause;
9319
9320
0
        if (PyObject_GetOptionalAttr(obj, state->exc, &tmp) < 0) {
9321
0
            return -1;
9322
0
        }
9323
0
        if (tmp == NULL || tmp == Py_None) {
9324
0
            Py_CLEAR(tmp);
9325
0
            exc = NULL;
9326
0
        }
9327
0
        else {
9328
0
            int res;
9329
0
            if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
9330
0
                goto failed;
9331
0
            }
9332
0
            res = obj2ast_expr(state, tmp, &exc, "exc", arena);
9333
0
            _Py_LeaveRecursiveCall();
9334
0
            if (res != 0) goto failed;
9335
0
            Py_CLEAR(tmp);
9336
0
        }
9337
0
        if (PyObject_GetOptionalAttr(obj, state->cause, &tmp) < 0) {
9338
0
            return -1;
9339
0
        }
9340
0
        if (tmp == NULL || tmp == Py_None) {
9341
0
            Py_CLEAR(tmp);
9342
0
            cause = NULL;
9343
0
        }
9344
0
        else {
9345
0
            int res;
9346
0
            if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
9347
0
                goto failed;
9348
0
            }
9349
0
            res = obj2ast_expr(state, tmp, &cause, "cause", arena);
9350
0
            _Py_LeaveRecursiveCall();
9351
0
            if (res != 0) goto failed;
9352
0
            Py_CLEAR(tmp);
9353
0
        }
9354
0
        *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
9355
0
                            end_col_offset, arena);
9356
0
        if (*out == NULL) goto failed;
9357
0
        return 0;
9358
0
    }
9359
0
    tp = state->Try_type;
9360
0
    isinstance = PyObject_IsInstance(obj, tp);
9361
0
    if (isinstance == -1) {
9362
0
        return -1;
9363
0
    }
9364
0
    if (isinstance) {
9365
0
        asdl_stmt_seq* body;
9366
0
        asdl_excepthandler_seq* handlers;
9367
0
        asdl_stmt_seq* orelse;
9368
0
        asdl_stmt_seq* finalbody;
9369
9370
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9371
0
            return -1;
9372
0
        }
9373
0
        if (tmp == NULL) {
9374
0
            tmp = PyList_New(0);
9375
0
            if (tmp == NULL) {
9376
0
                return -1;
9377
0
            }
9378
0
        }
9379
0
        {
9380
0
            int res;
9381
0
            Py_ssize_t len;
9382
0
            Py_ssize_t i;
9383
0
            if (!PyList_Check(tmp)) {
9384
0
                PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %T", tmp);
9385
0
                goto failed;
9386
0
            }
9387
0
            len = PyList_GET_SIZE(tmp);
9388
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9389
0
            if (body == NULL) goto failed;
9390
0
            for (i = 0; i < len; i++) {
9391
0
                stmt_ty val;
9392
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9393
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9394
0
                    goto failed;
9395
0
                }
9396
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9397
0
                _Py_LeaveRecursiveCall();
9398
0
                Py_DECREF(tmp2);
9399
0
                if (res != 0) goto failed;
9400
0
                if (len != PyList_GET_SIZE(tmp)) {
9401
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
9402
0
                    goto failed;
9403
0
                }
9404
0
                asdl_seq_SET(body, i, val);
9405
0
            }
9406
0
            Py_CLEAR(tmp);
9407
0
        }
9408
0
        if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
9409
0
            return -1;
9410
0
        }
9411
0
        if (tmp == NULL) {
9412
0
            tmp = PyList_New(0);
9413
0
            if (tmp == NULL) {
9414
0
                return -1;
9415
0
            }
9416
0
        }
9417
0
        {
9418
0
            int res;
9419
0
            Py_ssize_t len;
9420
0
            Py_ssize_t i;
9421
0
            if (!PyList_Check(tmp)) {
9422
0
                PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %T", tmp);
9423
0
                goto failed;
9424
0
            }
9425
0
            len = PyList_GET_SIZE(tmp);
9426
0
            handlers = _Py_asdl_excepthandler_seq_new(len, arena);
9427
0
            if (handlers == NULL) goto failed;
9428
0
            for (i = 0; i < len; i++) {
9429
0
                excepthandler_ty val;
9430
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9431
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9432
0
                    goto failed;
9433
0
                }
9434
0
                res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
9435
0
                _Py_LeaveRecursiveCall();
9436
0
                Py_DECREF(tmp2);
9437
0
                if (res != 0) goto failed;
9438
0
                if (len != PyList_GET_SIZE(tmp)) {
9439
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
9440
0
                    goto failed;
9441
0
                }
9442
0
                asdl_seq_SET(handlers, i, val);
9443
0
            }
9444
0
            Py_CLEAR(tmp);
9445
0
        }
9446
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
9447
0
            return -1;
9448
0
        }
9449
0
        if (tmp == NULL) {
9450
0
            tmp = PyList_New(0);
9451
0
            if (tmp == NULL) {
9452
0
                return -1;
9453
0
            }
9454
0
        }
9455
0
        {
9456
0
            int res;
9457
0
            Py_ssize_t len;
9458
0
            Py_ssize_t i;
9459
0
            if (!PyList_Check(tmp)) {
9460
0
                PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %T", tmp);
9461
0
                goto failed;
9462
0
            }
9463
0
            len = PyList_GET_SIZE(tmp);
9464
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
9465
0
            if (orelse == NULL) goto failed;
9466
0
            for (i = 0; i < len; i++) {
9467
0
                stmt_ty val;
9468
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9469
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9470
0
                    goto failed;
9471
0
                }
9472
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9473
0
                _Py_LeaveRecursiveCall();
9474
0
                Py_DECREF(tmp2);
9475
0
                if (res != 0) goto failed;
9476
0
                if (len != PyList_GET_SIZE(tmp)) {
9477
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
9478
0
                    goto failed;
9479
0
                }
9480
0
                asdl_seq_SET(orelse, i, val);
9481
0
            }
9482
0
            Py_CLEAR(tmp);
9483
0
        }
9484
0
        if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
9485
0
            return -1;
9486
0
        }
9487
0
        if (tmp == NULL) {
9488
0
            tmp = PyList_New(0);
9489
0
            if (tmp == NULL) {
9490
0
                return -1;
9491
0
            }
9492
0
        }
9493
0
        {
9494
0
            int res;
9495
0
            Py_ssize_t len;
9496
0
            Py_ssize_t i;
9497
0
            if (!PyList_Check(tmp)) {
9498
0
                PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %T", tmp);
9499
0
                goto failed;
9500
0
            }
9501
0
            len = PyList_GET_SIZE(tmp);
9502
0
            finalbody = _Py_asdl_stmt_seq_new(len, arena);
9503
0
            if (finalbody == NULL) goto failed;
9504
0
            for (i = 0; i < len; i++) {
9505
0
                stmt_ty val;
9506
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9507
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9508
0
                    goto failed;
9509
0
                }
9510
0
                res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
9511
0
                _Py_LeaveRecursiveCall();
9512
0
                Py_DECREF(tmp2);
9513
0
                if (res != 0) goto failed;
9514
0
                if (len != PyList_GET_SIZE(tmp)) {
9515
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
9516
0
                    goto failed;
9517
0
                }
9518
0
                asdl_seq_SET(finalbody, i, val);
9519
0
            }
9520
0
            Py_CLEAR(tmp);
9521
0
        }
9522
0
        *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
9523
0
                          col_offset, end_lineno, end_col_offset, arena);
9524
0
        if (*out == NULL) goto failed;
9525
0
        return 0;
9526
0
    }
9527
0
    tp = state->TryStar_type;
9528
0
    isinstance = PyObject_IsInstance(obj, tp);
9529
0
    if (isinstance == -1) {
9530
0
        return -1;
9531
0
    }
9532
0
    if (isinstance) {
9533
0
        asdl_stmt_seq* body;
9534
0
        asdl_excepthandler_seq* handlers;
9535
0
        asdl_stmt_seq* orelse;
9536
0
        asdl_stmt_seq* finalbody;
9537
9538
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9539
0
            return -1;
9540
0
        }
9541
0
        if (tmp == NULL) {
9542
0
            tmp = PyList_New(0);
9543
0
            if (tmp == NULL) {
9544
0
                return -1;
9545
0
            }
9546
0
        }
9547
0
        {
9548
0
            int res;
9549
0
            Py_ssize_t len;
9550
0
            Py_ssize_t i;
9551
0
            if (!PyList_Check(tmp)) {
9552
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %T", tmp);
9553
0
                goto failed;
9554
0
            }
9555
0
            len = PyList_GET_SIZE(tmp);
9556
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9557
0
            if (body == NULL) goto failed;
9558
0
            for (i = 0; i < len; i++) {
9559
0
                stmt_ty val;
9560
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9561
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9562
0
                    goto failed;
9563
0
                }
9564
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9565
0
                _Py_LeaveRecursiveCall();
9566
0
                Py_DECREF(tmp2);
9567
0
                if (res != 0) goto failed;
9568
0
                if (len != PyList_GET_SIZE(tmp)) {
9569
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
9570
0
                    goto failed;
9571
0
                }
9572
0
                asdl_seq_SET(body, i, val);
9573
0
            }
9574
0
            Py_CLEAR(tmp);
9575
0
        }
9576
0
        if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
9577
0
            return -1;
9578
0
        }
9579
0
        if (tmp == NULL) {
9580
0
            tmp = PyList_New(0);
9581
0
            if (tmp == NULL) {
9582
0
                return -1;
9583
0
            }
9584
0
        }
9585
0
        {
9586
0
            int res;
9587
0
            Py_ssize_t len;
9588
0
            Py_ssize_t i;
9589
0
            if (!PyList_Check(tmp)) {
9590
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %T", tmp);
9591
0
                goto failed;
9592
0
            }
9593
0
            len = PyList_GET_SIZE(tmp);
9594
0
            handlers = _Py_asdl_excepthandler_seq_new(len, arena);
9595
0
            if (handlers == NULL) goto failed;
9596
0
            for (i = 0; i < len; i++) {
9597
0
                excepthandler_ty val;
9598
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9599
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9600
0
                    goto failed;
9601
0
                }
9602
0
                res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
9603
0
                _Py_LeaveRecursiveCall();
9604
0
                Py_DECREF(tmp2);
9605
0
                if (res != 0) goto failed;
9606
0
                if (len != PyList_GET_SIZE(tmp)) {
9607
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
9608
0
                    goto failed;
9609
0
                }
9610
0
                asdl_seq_SET(handlers, i, val);
9611
0
            }
9612
0
            Py_CLEAR(tmp);
9613
0
        }
9614
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
9615
0
            return -1;
9616
0
        }
9617
0
        if (tmp == NULL) {
9618
0
            tmp = PyList_New(0);
9619
0
            if (tmp == NULL) {
9620
0
                return -1;
9621
0
            }
9622
0
        }
9623
0
        {
9624
0
            int res;
9625
0
            Py_ssize_t len;
9626
0
            Py_ssize_t i;
9627
0
            if (!PyList_Check(tmp)) {
9628
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %T", tmp);
9629
0
                goto failed;
9630
0
            }
9631
0
            len = PyList_GET_SIZE(tmp);
9632
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
9633
0
            if (orelse == NULL) goto failed;
9634
0
            for (i = 0; i < len; i++) {
9635
0
                stmt_ty val;
9636
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9637
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9638
0
                    goto failed;
9639
0
                }
9640
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9641
0
                _Py_LeaveRecursiveCall();
9642
0
                Py_DECREF(tmp2);
9643
0
                if (res != 0) goto failed;
9644
0
                if (len != PyList_GET_SIZE(tmp)) {
9645
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
9646
0
                    goto failed;
9647
0
                }
9648
0
                asdl_seq_SET(orelse, i, val);
9649
0
            }
9650
0
            Py_CLEAR(tmp);
9651
0
        }
9652
0
        if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
9653
0
            return -1;
9654
0
        }
9655
0
        if (tmp == NULL) {
9656
0
            tmp = PyList_New(0);
9657
0
            if (tmp == NULL) {
9658
0
                return -1;
9659
0
            }
9660
0
        }
9661
0
        {
9662
0
            int res;
9663
0
            Py_ssize_t len;
9664
0
            Py_ssize_t i;
9665
0
            if (!PyList_Check(tmp)) {
9666
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %T", tmp);
9667
0
                goto failed;
9668
0
            }
9669
0
            len = PyList_GET_SIZE(tmp);
9670
0
            finalbody = _Py_asdl_stmt_seq_new(len, arena);
9671
0
            if (finalbody == NULL) goto failed;
9672
0
            for (i = 0; i < len; i++) {
9673
0
                stmt_ty val;
9674
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9675
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9676
0
                    goto failed;
9677
0
                }
9678
0
                res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
9679
0
                _Py_LeaveRecursiveCall();
9680
0
                Py_DECREF(tmp2);
9681
0
                if (res != 0) goto failed;
9682
0
                if (len != PyList_GET_SIZE(tmp)) {
9683
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
9684
0
                    goto failed;
9685
0
                }
9686
0
                asdl_seq_SET(finalbody, i, val);
9687
0
            }
9688
0
            Py_CLEAR(tmp);
9689
0
        }
9690
0
        *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
9691
0
                              col_offset, end_lineno, end_col_offset, arena);
9692
0
        if (*out == NULL) goto failed;
9693
0
        return 0;
9694
0
    }
9695
0
    tp = state->Assert_type;
9696
0
    isinstance = PyObject_IsInstance(obj, tp);
9697
0
    if (isinstance == -1) {
9698
0
        return -1;
9699
0
    }
9700
0
    if (isinstance) {
9701
0
        expr_ty test;
9702
0
        expr_ty msg;
9703
9704
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
9705
0
            return -1;
9706
0
        }
9707
0
        if (tmp == NULL) {
9708
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
9709
0
            return -1;
9710
0
        }
9711
0
        else {
9712
0
            int res;
9713
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
9714
0
                goto failed;
9715
0
            }
9716
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
9717
0
            _Py_LeaveRecursiveCall();
9718
0
            if (res != 0) goto failed;
9719
0
            Py_CLEAR(tmp);
9720
0
        }
9721
0
        if (PyObject_GetOptionalAttr(obj, state->msg, &tmp) < 0) {
9722
0
            return -1;
9723
0
        }
9724
0
        if (tmp == NULL || tmp == Py_None) {
9725
0
            Py_CLEAR(tmp);
9726
0
            msg = NULL;
9727
0
        }
9728
0
        else {
9729
0
            int res;
9730
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
9731
0
                goto failed;
9732
0
            }
9733
0
            res = obj2ast_expr(state, tmp, &msg, "msg", arena);
9734
0
            _Py_LeaveRecursiveCall();
9735
0
            if (res != 0) goto failed;
9736
0
            Py_CLEAR(tmp);
9737
0
        }
9738
0
        *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
9739
0
                             end_col_offset, arena);
9740
0
        if (*out == NULL) goto failed;
9741
0
        return 0;
9742
0
    }
9743
0
    tp = state->Import_type;
9744
0
    isinstance = PyObject_IsInstance(obj, tp);
9745
0
    if (isinstance == -1) {
9746
0
        return -1;
9747
0
    }
9748
0
    if (isinstance) {
9749
0
        asdl_alias_seq* names;
9750
0
        int is_lazy;
9751
9752
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9753
0
            return -1;
9754
0
        }
9755
0
        if (tmp == NULL) {
9756
0
            tmp = PyList_New(0);
9757
0
            if (tmp == NULL) {
9758
0
                return -1;
9759
0
            }
9760
0
        }
9761
0
        {
9762
0
            int res;
9763
0
            Py_ssize_t len;
9764
0
            Py_ssize_t i;
9765
0
            if (!PyList_Check(tmp)) {
9766
0
                PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %T", tmp);
9767
0
                goto failed;
9768
0
            }
9769
0
            len = PyList_GET_SIZE(tmp);
9770
0
            names = _Py_asdl_alias_seq_new(len, arena);
9771
0
            if (names == NULL) goto failed;
9772
0
            for (i = 0; i < len; i++) {
9773
0
                alias_ty val;
9774
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9775
0
                if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
9776
0
                    goto failed;
9777
0
                }
9778
0
                res = obj2ast_alias(state, tmp2, &val, "names", arena);
9779
0
                _Py_LeaveRecursiveCall();
9780
0
                Py_DECREF(tmp2);
9781
0
                if (res != 0) goto failed;
9782
0
                if (len != PyList_GET_SIZE(tmp)) {
9783
0
                    PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
9784
0
                    goto failed;
9785
0
                }
9786
0
                asdl_seq_SET(names, i, val);
9787
0
            }
9788
0
            Py_CLEAR(tmp);
9789
0
        }
9790
0
        if (PyObject_GetOptionalAttr(obj, state->is_lazy, &tmp) < 0) {
9791
0
            return -1;
9792
0
        }
9793
0
        if (tmp == NULL || tmp == Py_None) {
9794
0
            Py_CLEAR(tmp);
9795
0
            is_lazy = 0;
9796
0
        }
9797
0
        else {
9798
0
            int res;
9799
0
            if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
9800
0
                goto failed;
9801
0
            }
9802
0
            res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
9803
0
            _Py_LeaveRecursiveCall();
9804
0
            if (res != 0) goto failed;
9805
0
            Py_CLEAR(tmp);
9806
0
        }
9807
0
        *out = _PyAST_Import(names, is_lazy, lineno, col_offset, end_lineno,
9808
0
                             end_col_offset, arena);
9809
0
        if (*out == NULL) goto failed;
9810
0
        return 0;
9811
0
    }
9812
0
    tp = state->ImportFrom_type;
9813
0
    isinstance = PyObject_IsInstance(obj, tp);
9814
0
    if (isinstance == -1) {
9815
0
        return -1;
9816
0
    }
9817
0
    if (isinstance) {
9818
0
        identifier module;
9819
0
        asdl_alias_seq* names;
9820
0
        int level;
9821
0
        int is_lazy;
9822
9823
0
        if (PyObject_GetOptionalAttr(obj, state->module, &tmp) < 0) {
9824
0
            return -1;
9825
0
        }
9826
0
        if (tmp == NULL || tmp == Py_None) {
9827
0
            Py_CLEAR(tmp);
9828
0
            module = NULL;
9829
0
        }
9830
0
        else {
9831
0
            int res;
9832
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9833
0
                goto failed;
9834
0
            }
9835
0
            res = obj2ast_identifier(state, tmp, &module, "module", arena);
9836
0
            _Py_LeaveRecursiveCall();
9837
0
            if (res != 0) goto failed;
9838
0
            Py_CLEAR(tmp);
9839
0
        }
9840
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9841
0
            return -1;
9842
0
        }
9843
0
        if (tmp == NULL) {
9844
0
            tmp = PyList_New(0);
9845
0
            if (tmp == NULL) {
9846
0
                return -1;
9847
0
            }
9848
0
        }
9849
0
        {
9850
0
            int res;
9851
0
            Py_ssize_t len;
9852
0
            Py_ssize_t i;
9853
0
            if (!PyList_Check(tmp)) {
9854
0
                PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %T", tmp);
9855
0
                goto failed;
9856
0
            }
9857
0
            len = PyList_GET_SIZE(tmp);
9858
0
            names = _Py_asdl_alias_seq_new(len, arena);
9859
0
            if (names == NULL) goto failed;
9860
0
            for (i = 0; i < len; i++) {
9861
0
                alias_ty val;
9862
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9863
0
                if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9864
0
                    goto failed;
9865
0
                }
9866
0
                res = obj2ast_alias(state, tmp2, &val, "names", arena);
9867
0
                _Py_LeaveRecursiveCall();
9868
0
                Py_DECREF(tmp2);
9869
0
                if (res != 0) goto failed;
9870
0
                if (len != PyList_GET_SIZE(tmp)) {
9871
0
                    PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
9872
0
                    goto failed;
9873
0
                }
9874
0
                asdl_seq_SET(names, i, val);
9875
0
            }
9876
0
            Py_CLEAR(tmp);
9877
0
        }
9878
0
        if (PyObject_GetOptionalAttr(obj, state->level, &tmp) < 0) {
9879
0
            return -1;
9880
0
        }
9881
0
        if (tmp == NULL || tmp == Py_None) {
9882
0
            Py_CLEAR(tmp);
9883
0
            level = 0;
9884
0
        }
9885
0
        else {
9886
0
            int res;
9887
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9888
0
                goto failed;
9889
0
            }
9890
0
            res = obj2ast_int(state, tmp, &level, "level", arena);
9891
0
            _Py_LeaveRecursiveCall();
9892
0
            if (res != 0) goto failed;
9893
0
            Py_CLEAR(tmp);
9894
0
        }
9895
0
        if (PyObject_GetOptionalAttr(obj, state->is_lazy, &tmp) < 0) {
9896
0
            return -1;
9897
0
        }
9898
0
        if (tmp == NULL || tmp == Py_None) {
9899
0
            Py_CLEAR(tmp);
9900
0
            is_lazy = 0;
9901
0
        }
9902
0
        else {
9903
0
            int res;
9904
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9905
0
                goto failed;
9906
0
            }
9907
0
            res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
9908
0
            _Py_LeaveRecursiveCall();
9909
0
            if (res != 0) goto failed;
9910
0
            Py_CLEAR(tmp);
9911
0
        }
9912
0
        *out = _PyAST_ImportFrom(module, names, level, is_lazy, lineno,
9913
0
                                 col_offset, end_lineno, end_col_offset, arena);
9914
0
        if (*out == NULL) goto failed;
9915
0
        return 0;
9916
0
    }
9917
0
    tp = state->Global_type;
9918
0
    isinstance = PyObject_IsInstance(obj, tp);
9919
0
    if (isinstance == -1) {
9920
0
        return -1;
9921
0
    }
9922
0
    if (isinstance) {
9923
0
        asdl_identifier_seq* names;
9924
9925
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9926
0
            return -1;
9927
0
        }
9928
0
        if (tmp == NULL) {
9929
0
            tmp = PyList_New(0);
9930
0
            if (tmp == NULL) {
9931
0
                return -1;
9932
0
            }
9933
0
        }
9934
0
        {
9935
0
            int res;
9936
0
            Py_ssize_t len;
9937
0
            Py_ssize_t i;
9938
0
            if (!PyList_Check(tmp)) {
9939
0
                PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %T", tmp);
9940
0
                goto failed;
9941
0
            }
9942
0
            len = PyList_GET_SIZE(tmp);
9943
0
            names = _Py_asdl_identifier_seq_new(len, arena);
9944
0
            if (names == NULL) goto failed;
9945
0
            for (i = 0; i < len; i++) {
9946
0
                identifier val;
9947
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9948
0
                if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
9949
0
                    goto failed;
9950
0
                }
9951
0
                res = obj2ast_identifier(state, tmp2, &val, "names", arena);
9952
0
                _Py_LeaveRecursiveCall();
9953
0
                Py_DECREF(tmp2);
9954
0
                if (res != 0) goto failed;
9955
0
                if (len != PyList_GET_SIZE(tmp)) {
9956
0
                    PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
9957
0
                    goto failed;
9958
0
                }
9959
0
                asdl_seq_SET(names, i, val);
9960
0
            }
9961
0
            Py_CLEAR(tmp);
9962
0
        }
9963
0
        *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
9964
0
                             end_col_offset, arena);
9965
0
        if (*out == NULL) goto failed;
9966
0
        return 0;
9967
0
    }
9968
0
    tp = state->Nonlocal_type;
9969
0
    isinstance = PyObject_IsInstance(obj, tp);
9970
0
    if (isinstance == -1) {
9971
0
        return -1;
9972
0
    }
9973
0
    if (isinstance) {
9974
0
        asdl_identifier_seq* names;
9975
9976
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9977
0
            return -1;
9978
0
        }
9979
0
        if (tmp == NULL) {
9980
0
            tmp = PyList_New(0);
9981
0
            if (tmp == NULL) {
9982
0
                return -1;
9983
0
            }
9984
0
        }
9985
0
        {
9986
0
            int res;
9987
0
            Py_ssize_t len;
9988
0
            Py_ssize_t i;
9989
0
            if (!PyList_Check(tmp)) {
9990
0
                PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %T", tmp);
9991
0
                goto failed;
9992
0
            }
9993
0
            len = PyList_GET_SIZE(tmp);
9994
0
            names = _Py_asdl_identifier_seq_new(len, arena);
9995
0
            if (names == NULL) goto failed;
9996
0
            for (i = 0; i < len; i++) {
9997
0
                identifier val;
9998
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9999
0
                if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
10000
0
                    goto failed;
10001
0
                }
10002
0
                res = obj2ast_identifier(state, tmp2, &val, "names", arena);
10003
0
                _Py_LeaveRecursiveCall();
10004
0
                Py_DECREF(tmp2);
10005
0
                if (res != 0) goto failed;
10006
0
                if (len != PyList_GET_SIZE(tmp)) {
10007
0
                    PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
10008
0
                    goto failed;
10009
0
                }
10010
0
                asdl_seq_SET(names, i, val);
10011
0
            }
10012
0
            Py_CLEAR(tmp);
10013
0
        }
10014
0
        *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
10015
0
                               end_col_offset, arena);
10016
0
        if (*out == NULL) goto failed;
10017
0
        return 0;
10018
0
    }
10019
0
    tp = state->Expr_type;
10020
0
    isinstance = PyObject_IsInstance(obj, tp);
10021
0
    if (isinstance == -1) {
10022
0
        return -1;
10023
0
    }
10024
0
    if (isinstance) {
10025
0
        expr_ty value;
10026
10027
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10028
0
            return -1;
10029
0
        }
10030
0
        if (tmp == NULL) {
10031
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
10032
0
            return -1;
10033
0
        }
10034
0
        else {
10035
0
            int res;
10036
0
            if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
10037
0
                goto failed;
10038
0
            }
10039
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10040
0
            _Py_LeaveRecursiveCall();
10041
0
            if (res != 0) goto failed;
10042
0
            Py_CLEAR(tmp);
10043
0
        }
10044
0
        *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
10045
0
                           end_col_offset, arena);
10046
0
        if (*out == NULL) goto failed;
10047
0
        return 0;
10048
0
    }
10049
0
    tp = state->Pass_type;
10050
0
    isinstance = PyObject_IsInstance(obj, tp);
10051
0
    if (isinstance == -1) {
10052
0
        return -1;
10053
0
    }
10054
0
    if (isinstance) {
10055
10056
0
        *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
10057
0
                           arena);
10058
0
        if (*out == NULL) goto failed;
10059
0
        return 0;
10060
0
    }
10061
0
    tp = state->Break_type;
10062
0
    isinstance = PyObject_IsInstance(obj, tp);
10063
0
    if (isinstance == -1) {
10064
0
        return -1;
10065
0
    }
10066
0
    if (isinstance) {
10067
10068
0
        *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
10069
0
                            arena);
10070
0
        if (*out == NULL) goto failed;
10071
0
        return 0;
10072
0
    }
10073
0
    tp = state->Continue_type;
10074
0
    isinstance = PyObject_IsInstance(obj, tp);
10075
0
    if (isinstance == -1) {
10076
0
        return -1;
10077
0
    }
10078
0
    if (isinstance) {
10079
10080
0
        *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
10081
0
                               arena);
10082
0
        if (*out == NULL) goto failed;
10083
0
        return 0;
10084
0
    }
10085
10086
0
    PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
10087
0
    failed:
10088
0
    Py_XDECREF(tmp);
10089
0
    return -1;
10090
0
}
10091
10092
int
10093
obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, const char*
10094
             field, PyArena* arena)
10095
0
{
10096
0
    int isinstance;
10097
10098
0
    PyObject *tmp = NULL;
10099
0
    PyObject *tp;
10100
0
    int lineno;
10101
0
    int col_offset;
10102
0
    int end_lineno;
10103
0
    int end_col_offset;
10104
10105
0
    if (obj == Py_None) {
10106
0
        *out = NULL;
10107
0
        return 0;
10108
0
    }
10109
0
    tp = state->expr_type;
10110
0
    isinstance = PyObject_IsInstance(obj, tp);
10111
0
    if (isinstance == -1) {
10112
0
        return 1;
10113
0
    }
10114
0
    if (!isinstance && field != NULL) {
10115
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'expr', got '%T'", field, obj);
10116
0
        return 1;
10117
0
    }
10118
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
10119
0
        return -1;
10120
0
    }
10121
0
    if (tmp == NULL) {
10122
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
10123
0
        return -1;
10124
0
    }
10125
0
    else {
10126
0
        int res;
10127
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10128
0
            goto failed;
10129
0
        }
10130
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
10131
0
        _Py_LeaveRecursiveCall();
10132
0
        if (res != 0) goto failed;
10133
0
        Py_CLEAR(tmp);
10134
0
    }
10135
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
10136
0
        return -1;
10137
0
    }
10138
0
    if (tmp == NULL) {
10139
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
10140
0
        return -1;
10141
0
    }
10142
0
    else {
10143
0
        int res;
10144
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10145
0
            goto failed;
10146
0
        }
10147
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
10148
0
        _Py_LeaveRecursiveCall();
10149
0
        if (res != 0) goto failed;
10150
0
        Py_CLEAR(tmp);
10151
0
    }
10152
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
10153
0
        return -1;
10154
0
    }
10155
0
    if (tmp == NULL || tmp == Py_None) {
10156
0
        Py_CLEAR(tmp);
10157
0
        end_lineno = lineno;
10158
0
    }
10159
0
    else {
10160
0
        int res;
10161
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10162
0
            goto failed;
10163
0
        }
10164
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
10165
0
        _Py_LeaveRecursiveCall();
10166
0
        if (res != 0) goto failed;
10167
0
        Py_CLEAR(tmp);
10168
0
    }
10169
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
10170
0
        return -1;
10171
0
    }
10172
0
    if (tmp == NULL || tmp == Py_None) {
10173
0
        Py_CLEAR(tmp);
10174
0
        end_col_offset = col_offset;
10175
0
    }
10176
0
    else {
10177
0
        int res;
10178
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10179
0
            goto failed;
10180
0
        }
10181
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
10182
0
        _Py_LeaveRecursiveCall();
10183
0
        if (res != 0) goto failed;
10184
0
        Py_CLEAR(tmp);
10185
0
    }
10186
0
    tp = state->BoolOp_type;
10187
0
    isinstance = PyObject_IsInstance(obj, tp);
10188
0
    if (isinstance == -1) {
10189
0
        return -1;
10190
0
    }
10191
0
    if (isinstance) {
10192
0
        boolop_ty op;
10193
0
        asdl_expr_seq* values;
10194
10195
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10196
0
            return -1;
10197
0
        }
10198
0
        if (tmp == NULL) {
10199
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
10200
0
            return -1;
10201
0
        }
10202
0
        else {
10203
0
            int res;
10204
0
            if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
10205
0
                goto failed;
10206
0
            }
10207
0
            res = obj2ast_boolop(state, tmp, &op, "op", arena);
10208
0
            _Py_LeaveRecursiveCall();
10209
0
            if (res != 0) goto failed;
10210
0
            Py_CLEAR(tmp);
10211
0
        }
10212
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
10213
0
            return -1;
10214
0
        }
10215
0
        if (tmp == NULL) {
10216
0
            tmp = PyList_New(0);
10217
0
            if (tmp == NULL) {
10218
0
                return -1;
10219
0
            }
10220
0
        }
10221
0
        {
10222
0
            int res;
10223
0
            Py_ssize_t len;
10224
0
            Py_ssize_t i;
10225
0
            if (!PyList_Check(tmp)) {
10226
0
                PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %T", tmp);
10227
0
                goto failed;
10228
0
            }
10229
0
            len = PyList_GET_SIZE(tmp);
10230
0
            values = _Py_asdl_expr_seq_new(len, arena);
10231
0
            if (values == NULL) goto failed;
10232
0
            for (i = 0; i < len; i++) {
10233
0
                expr_ty val;
10234
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10235
0
                if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
10236
0
                    goto failed;
10237
0
                }
10238
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
10239
0
                _Py_LeaveRecursiveCall();
10240
0
                Py_DECREF(tmp2);
10241
0
                if (res != 0) goto failed;
10242
0
                if (len != PyList_GET_SIZE(tmp)) {
10243
0
                    PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
10244
0
                    goto failed;
10245
0
                }
10246
0
                asdl_seq_SET(values, i, val);
10247
0
            }
10248
0
            Py_CLEAR(tmp);
10249
0
        }
10250
0
        *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
10251
0
                             end_col_offset, arena);
10252
0
        if (*out == NULL) goto failed;
10253
0
        return 0;
10254
0
    }
10255
0
    tp = state->NamedExpr_type;
10256
0
    isinstance = PyObject_IsInstance(obj, tp);
10257
0
    if (isinstance == -1) {
10258
0
        return -1;
10259
0
    }
10260
0
    if (isinstance) {
10261
0
        expr_ty target;
10262
0
        expr_ty value;
10263
10264
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
10265
0
            return -1;
10266
0
        }
10267
0
        if (tmp == NULL) {
10268
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
10269
0
            return -1;
10270
0
        }
10271
0
        else {
10272
0
            int res;
10273
0
            if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
10274
0
                goto failed;
10275
0
            }
10276
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
10277
0
            _Py_LeaveRecursiveCall();
10278
0
            if (res != 0) goto failed;
10279
0
            Py_CLEAR(tmp);
10280
0
        }
10281
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10282
0
            return -1;
10283
0
        }
10284
0
        if (tmp == NULL) {
10285
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
10286
0
            return -1;
10287
0
        }
10288
0
        else {
10289
0
            int res;
10290
0
            if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
10291
0
                goto failed;
10292
0
            }
10293
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10294
0
            _Py_LeaveRecursiveCall();
10295
0
            if (res != 0) goto failed;
10296
0
            Py_CLEAR(tmp);
10297
0
        }
10298
0
        *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
10299
0
                                end_col_offset, arena);
10300
0
        if (*out == NULL) goto failed;
10301
0
        return 0;
10302
0
    }
10303
0
    tp = state->BinOp_type;
10304
0
    isinstance = PyObject_IsInstance(obj, tp);
10305
0
    if (isinstance == -1) {
10306
0
        return -1;
10307
0
    }
10308
0
    if (isinstance) {
10309
0
        expr_ty left;
10310
0
        operator_ty op;
10311
0
        expr_ty right;
10312
10313
0
        if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
10314
0
            return -1;
10315
0
        }
10316
0
        if (tmp == NULL) {
10317
0
            PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
10318
0
            return -1;
10319
0
        }
10320
0
        else {
10321
0
            int res;
10322
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10323
0
                goto failed;
10324
0
            }
10325
0
            res = obj2ast_expr(state, tmp, &left, "left", arena);
10326
0
            _Py_LeaveRecursiveCall();
10327
0
            if (res != 0) goto failed;
10328
0
            Py_CLEAR(tmp);
10329
0
        }
10330
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10331
0
            return -1;
10332
0
        }
10333
0
        if (tmp == NULL) {
10334
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
10335
0
            return -1;
10336
0
        }
10337
0
        else {
10338
0
            int res;
10339
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10340
0
                goto failed;
10341
0
            }
10342
0
            res = obj2ast_operator(state, tmp, &op, "op", arena);
10343
0
            _Py_LeaveRecursiveCall();
10344
0
            if (res != 0) goto failed;
10345
0
            Py_CLEAR(tmp);
10346
0
        }
10347
0
        if (PyObject_GetOptionalAttr(obj, state->right, &tmp) < 0) {
10348
0
            return -1;
10349
0
        }
10350
0
        if (tmp == NULL) {
10351
0
            PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
10352
0
            return -1;
10353
0
        }
10354
0
        else {
10355
0
            int res;
10356
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10357
0
                goto failed;
10358
0
            }
10359
0
            res = obj2ast_expr(state, tmp, &right, "right", arena);
10360
0
            _Py_LeaveRecursiveCall();
10361
0
            if (res != 0) goto failed;
10362
0
            Py_CLEAR(tmp);
10363
0
        }
10364
0
        *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
10365
0
                            end_col_offset, arena);
10366
0
        if (*out == NULL) goto failed;
10367
0
        return 0;
10368
0
    }
10369
0
    tp = state->UnaryOp_type;
10370
0
    isinstance = PyObject_IsInstance(obj, tp);
10371
0
    if (isinstance == -1) {
10372
0
        return -1;
10373
0
    }
10374
0
    if (isinstance) {
10375
0
        unaryop_ty op;
10376
0
        expr_ty operand;
10377
10378
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10379
0
            return -1;
10380
0
        }
10381
0
        if (tmp == NULL) {
10382
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
10383
0
            return -1;
10384
0
        }
10385
0
        else {
10386
0
            int res;
10387
0
            if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
10388
0
                goto failed;
10389
0
            }
10390
0
            res = obj2ast_unaryop(state, tmp, &op, "op", arena);
10391
0
            _Py_LeaveRecursiveCall();
10392
0
            if (res != 0) goto failed;
10393
0
            Py_CLEAR(tmp);
10394
0
        }
10395
0
        if (PyObject_GetOptionalAttr(obj, state->operand, &tmp) < 0) {
10396
0
            return -1;
10397
0
        }
10398
0
        if (tmp == NULL) {
10399
0
            PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
10400
0
            return -1;
10401
0
        }
10402
0
        else {
10403
0
            int res;
10404
0
            if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
10405
0
                goto failed;
10406
0
            }
10407
0
            res = obj2ast_expr(state, tmp, &operand, "operand", arena);
10408
0
            _Py_LeaveRecursiveCall();
10409
0
            if (res != 0) goto failed;
10410
0
            Py_CLEAR(tmp);
10411
0
        }
10412
0
        *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
10413
0
                              end_col_offset, arena);
10414
0
        if (*out == NULL) goto failed;
10415
0
        return 0;
10416
0
    }
10417
0
    tp = state->Lambda_type;
10418
0
    isinstance = PyObject_IsInstance(obj, tp);
10419
0
    if (isinstance == -1) {
10420
0
        return -1;
10421
0
    }
10422
0
    if (isinstance) {
10423
0
        arguments_ty args;
10424
0
        expr_ty body;
10425
10426
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
10427
0
            return -1;
10428
0
        }
10429
0
        if (tmp == NULL) {
10430
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
10431
0
            return -1;
10432
0
        }
10433
0
        else {
10434
0
            int res;
10435
0
            if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
10436
0
                goto failed;
10437
0
            }
10438
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
10439
0
            _Py_LeaveRecursiveCall();
10440
0
            if (res != 0) goto failed;
10441
0
            Py_CLEAR(tmp);
10442
0
        }
10443
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10444
0
            return -1;
10445
0
        }
10446
0
        if (tmp == NULL) {
10447
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
10448
0
            return -1;
10449
0
        }
10450
0
        else {
10451
0
            int res;
10452
0
            if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
10453
0
                goto failed;
10454
0
            }
10455
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
10456
0
            _Py_LeaveRecursiveCall();
10457
0
            if (res != 0) goto failed;
10458
0
            Py_CLEAR(tmp);
10459
0
        }
10460
0
        *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
10461
0
                             end_col_offset, arena);
10462
0
        if (*out == NULL) goto failed;
10463
0
        return 0;
10464
0
    }
10465
0
    tp = state->IfExp_type;
10466
0
    isinstance = PyObject_IsInstance(obj, tp);
10467
0
    if (isinstance == -1) {
10468
0
        return -1;
10469
0
    }
10470
0
    if (isinstance) {
10471
0
        expr_ty test;
10472
0
        expr_ty body;
10473
0
        expr_ty orelse;
10474
10475
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
10476
0
            return -1;
10477
0
        }
10478
0
        if (tmp == NULL) {
10479
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
10480
0
            return -1;
10481
0
        }
10482
0
        else {
10483
0
            int res;
10484
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10485
0
                goto failed;
10486
0
            }
10487
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
10488
0
            _Py_LeaveRecursiveCall();
10489
0
            if (res != 0) goto failed;
10490
0
            Py_CLEAR(tmp);
10491
0
        }
10492
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10493
0
            return -1;
10494
0
        }
10495
0
        if (tmp == NULL) {
10496
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
10497
0
            return -1;
10498
0
        }
10499
0
        else {
10500
0
            int res;
10501
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10502
0
                goto failed;
10503
0
            }
10504
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
10505
0
            _Py_LeaveRecursiveCall();
10506
0
            if (res != 0) goto failed;
10507
0
            Py_CLEAR(tmp);
10508
0
        }
10509
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
10510
0
            return -1;
10511
0
        }
10512
0
        if (tmp == NULL) {
10513
0
            PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
10514
0
            return -1;
10515
0
        }
10516
0
        else {
10517
0
            int res;
10518
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10519
0
                goto failed;
10520
0
            }
10521
0
            res = obj2ast_expr(state, tmp, &orelse, "orelse", arena);
10522
0
            _Py_LeaveRecursiveCall();
10523
0
            if (res != 0) goto failed;
10524
0
            Py_CLEAR(tmp);
10525
0
        }
10526
0
        *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
10527
0
                            end_col_offset, arena);
10528
0
        if (*out == NULL) goto failed;
10529
0
        return 0;
10530
0
    }
10531
0
    tp = state->Dict_type;
10532
0
    isinstance = PyObject_IsInstance(obj, tp);
10533
0
    if (isinstance == -1) {
10534
0
        return -1;
10535
0
    }
10536
0
    if (isinstance) {
10537
0
        asdl_expr_seq* keys;
10538
0
        asdl_expr_seq* values;
10539
10540
0
        if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
10541
0
            return -1;
10542
0
        }
10543
0
        if (tmp == NULL) {
10544
0
            tmp = PyList_New(0);
10545
0
            if (tmp == NULL) {
10546
0
                return -1;
10547
0
            }
10548
0
        }
10549
0
        {
10550
0
            int res;
10551
0
            Py_ssize_t len;
10552
0
            Py_ssize_t i;
10553
0
            if (!PyList_Check(tmp)) {
10554
0
                PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %T", tmp);
10555
0
                goto failed;
10556
0
            }
10557
0
            len = PyList_GET_SIZE(tmp);
10558
0
            keys = _Py_asdl_expr_seq_new(len, arena);
10559
0
            if (keys == NULL) goto failed;
10560
0
            for (i = 0; i < len; i++) {
10561
0
                expr_ty val;
10562
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10563
0
                if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
10564
0
                    goto failed;
10565
0
                }
10566
0
                res = obj2ast_expr(state, tmp2, &val, "keys", arena);
10567
0
                _Py_LeaveRecursiveCall();
10568
0
                Py_DECREF(tmp2);
10569
0
                if (res != 0) goto failed;
10570
0
                if (len != PyList_GET_SIZE(tmp)) {
10571
0
                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
10572
0
                    goto failed;
10573
0
                }
10574
0
                asdl_seq_SET(keys, i, val);
10575
0
            }
10576
0
            Py_CLEAR(tmp);
10577
0
        }
10578
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
10579
0
            return -1;
10580
0
        }
10581
0
        if (tmp == NULL) {
10582
0
            tmp = PyList_New(0);
10583
0
            if (tmp == NULL) {
10584
0
                return -1;
10585
0
            }
10586
0
        }
10587
0
        {
10588
0
            int res;
10589
0
            Py_ssize_t len;
10590
0
            Py_ssize_t i;
10591
0
            if (!PyList_Check(tmp)) {
10592
0
                PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %T", tmp);
10593
0
                goto failed;
10594
0
            }
10595
0
            len = PyList_GET_SIZE(tmp);
10596
0
            values = _Py_asdl_expr_seq_new(len, arena);
10597
0
            if (values == NULL) goto failed;
10598
0
            for (i = 0; i < len; i++) {
10599
0
                expr_ty val;
10600
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10601
0
                if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
10602
0
                    goto failed;
10603
0
                }
10604
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
10605
0
                _Py_LeaveRecursiveCall();
10606
0
                Py_DECREF(tmp2);
10607
0
                if (res != 0) goto failed;
10608
0
                if (len != PyList_GET_SIZE(tmp)) {
10609
0
                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
10610
0
                    goto failed;
10611
0
                }
10612
0
                asdl_seq_SET(values, i, val);
10613
0
            }
10614
0
            Py_CLEAR(tmp);
10615
0
        }
10616
0
        *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
10617
0
                           end_col_offset, arena);
10618
0
        if (*out == NULL) goto failed;
10619
0
        return 0;
10620
0
    }
10621
0
    tp = state->Set_type;
10622
0
    isinstance = PyObject_IsInstance(obj, tp);
10623
0
    if (isinstance == -1) {
10624
0
        return -1;
10625
0
    }
10626
0
    if (isinstance) {
10627
0
        asdl_expr_seq* elts;
10628
10629
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
10630
0
            return -1;
10631
0
        }
10632
0
        if (tmp == NULL) {
10633
0
            tmp = PyList_New(0);
10634
0
            if (tmp == NULL) {
10635
0
                return -1;
10636
0
            }
10637
0
        }
10638
0
        {
10639
0
            int res;
10640
0
            Py_ssize_t len;
10641
0
            Py_ssize_t i;
10642
0
            if (!PyList_Check(tmp)) {
10643
0
                PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %T", tmp);
10644
0
                goto failed;
10645
0
            }
10646
0
            len = PyList_GET_SIZE(tmp);
10647
0
            elts = _Py_asdl_expr_seq_new(len, arena);
10648
0
            if (elts == NULL) goto failed;
10649
0
            for (i = 0; i < len; i++) {
10650
0
                expr_ty val;
10651
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10652
0
                if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
10653
0
                    goto failed;
10654
0
                }
10655
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
10656
0
                _Py_LeaveRecursiveCall();
10657
0
                Py_DECREF(tmp2);
10658
0
                if (res != 0) goto failed;
10659
0
                if (len != PyList_GET_SIZE(tmp)) {
10660
0
                    PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
10661
0
                    goto failed;
10662
0
                }
10663
0
                asdl_seq_SET(elts, i, val);
10664
0
            }
10665
0
            Py_CLEAR(tmp);
10666
0
        }
10667
0
        *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
10668
0
                          arena);
10669
0
        if (*out == NULL) goto failed;
10670
0
        return 0;
10671
0
    }
10672
0
    tp = state->ListComp_type;
10673
0
    isinstance = PyObject_IsInstance(obj, tp);
10674
0
    if (isinstance == -1) {
10675
0
        return -1;
10676
0
    }
10677
0
    if (isinstance) {
10678
0
        expr_ty elt;
10679
0
        asdl_comprehension_seq* generators;
10680
10681
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10682
0
            return -1;
10683
0
        }
10684
0
        if (tmp == NULL) {
10685
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
10686
0
            return -1;
10687
0
        }
10688
0
        else {
10689
0
            int res;
10690
0
            if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
10691
0
                goto failed;
10692
0
            }
10693
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10694
0
            _Py_LeaveRecursiveCall();
10695
0
            if (res != 0) goto failed;
10696
0
            Py_CLEAR(tmp);
10697
0
        }
10698
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10699
0
            return -1;
10700
0
        }
10701
0
        if (tmp == NULL) {
10702
0
            tmp = PyList_New(0);
10703
0
            if (tmp == NULL) {
10704
0
                return -1;
10705
0
            }
10706
0
        }
10707
0
        {
10708
0
            int res;
10709
0
            Py_ssize_t len;
10710
0
            Py_ssize_t i;
10711
0
            if (!PyList_Check(tmp)) {
10712
0
                PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %T", tmp);
10713
0
                goto failed;
10714
0
            }
10715
0
            len = PyList_GET_SIZE(tmp);
10716
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10717
0
            if (generators == NULL) goto failed;
10718
0
            for (i = 0; i < len; i++) {
10719
0
                comprehension_ty val;
10720
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10721
0
                if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
10722
0
                    goto failed;
10723
0
                }
10724
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10725
0
                _Py_LeaveRecursiveCall();
10726
0
                Py_DECREF(tmp2);
10727
0
                if (res != 0) goto failed;
10728
0
                if (len != PyList_GET_SIZE(tmp)) {
10729
0
                    PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
10730
0
                    goto failed;
10731
0
                }
10732
0
                asdl_seq_SET(generators, i, val);
10733
0
            }
10734
0
            Py_CLEAR(tmp);
10735
0
        }
10736
0
        *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
10737
0
                               end_col_offset, arena);
10738
0
        if (*out == NULL) goto failed;
10739
0
        return 0;
10740
0
    }
10741
0
    tp = state->SetComp_type;
10742
0
    isinstance = PyObject_IsInstance(obj, tp);
10743
0
    if (isinstance == -1) {
10744
0
        return -1;
10745
0
    }
10746
0
    if (isinstance) {
10747
0
        expr_ty elt;
10748
0
        asdl_comprehension_seq* generators;
10749
10750
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10751
0
            return -1;
10752
0
        }
10753
0
        if (tmp == NULL) {
10754
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
10755
0
            return -1;
10756
0
        }
10757
0
        else {
10758
0
            int res;
10759
0
            if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
10760
0
                goto failed;
10761
0
            }
10762
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10763
0
            _Py_LeaveRecursiveCall();
10764
0
            if (res != 0) goto failed;
10765
0
            Py_CLEAR(tmp);
10766
0
        }
10767
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10768
0
            return -1;
10769
0
        }
10770
0
        if (tmp == NULL) {
10771
0
            tmp = PyList_New(0);
10772
0
            if (tmp == NULL) {
10773
0
                return -1;
10774
0
            }
10775
0
        }
10776
0
        {
10777
0
            int res;
10778
0
            Py_ssize_t len;
10779
0
            Py_ssize_t i;
10780
0
            if (!PyList_Check(tmp)) {
10781
0
                PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %T", tmp);
10782
0
                goto failed;
10783
0
            }
10784
0
            len = PyList_GET_SIZE(tmp);
10785
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10786
0
            if (generators == NULL) goto failed;
10787
0
            for (i = 0; i < len; i++) {
10788
0
                comprehension_ty val;
10789
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10790
0
                if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
10791
0
                    goto failed;
10792
0
                }
10793
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10794
0
                _Py_LeaveRecursiveCall();
10795
0
                Py_DECREF(tmp2);
10796
0
                if (res != 0) goto failed;
10797
0
                if (len != PyList_GET_SIZE(tmp)) {
10798
0
                    PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
10799
0
                    goto failed;
10800
0
                }
10801
0
                asdl_seq_SET(generators, i, val);
10802
0
            }
10803
0
            Py_CLEAR(tmp);
10804
0
        }
10805
0
        *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
10806
0
                              end_col_offset, arena);
10807
0
        if (*out == NULL) goto failed;
10808
0
        return 0;
10809
0
    }
10810
0
    tp = state->DictComp_type;
10811
0
    isinstance = PyObject_IsInstance(obj, tp);
10812
0
    if (isinstance == -1) {
10813
0
        return -1;
10814
0
    }
10815
0
    if (isinstance) {
10816
0
        expr_ty key;
10817
0
        expr_ty value;
10818
0
        asdl_comprehension_seq* generators;
10819
10820
0
        if (PyObject_GetOptionalAttr(obj, state->key, &tmp) < 0) {
10821
0
            return -1;
10822
0
        }
10823
0
        if (tmp == NULL) {
10824
0
            PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
10825
0
            return -1;
10826
0
        }
10827
0
        else {
10828
0
            int res;
10829
0
            if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10830
0
                goto failed;
10831
0
            }
10832
0
            res = obj2ast_expr(state, tmp, &key, "key", arena);
10833
0
            _Py_LeaveRecursiveCall();
10834
0
            if (res != 0) goto failed;
10835
0
            Py_CLEAR(tmp);
10836
0
        }
10837
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10838
0
            return -1;
10839
0
        }
10840
0
        if (tmp == NULL || tmp == Py_None) {
10841
0
            Py_CLEAR(tmp);
10842
0
            value = NULL;
10843
0
        }
10844
0
        else {
10845
0
            int res;
10846
0
            if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10847
0
                goto failed;
10848
0
            }
10849
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10850
0
            _Py_LeaveRecursiveCall();
10851
0
            if (res != 0) goto failed;
10852
0
            Py_CLEAR(tmp);
10853
0
        }
10854
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10855
0
            return -1;
10856
0
        }
10857
0
        if (tmp == NULL) {
10858
0
            tmp = PyList_New(0);
10859
0
            if (tmp == NULL) {
10860
0
                return -1;
10861
0
            }
10862
0
        }
10863
0
        {
10864
0
            int res;
10865
0
            Py_ssize_t len;
10866
0
            Py_ssize_t i;
10867
0
            if (!PyList_Check(tmp)) {
10868
0
                PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %T", tmp);
10869
0
                goto failed;
10870
0
            }
10871
0
            len = PyList_GET_SIZE(tmp);
10872
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10873
0
            if (generators == NULL) goto failed;
10874
0
            for (i = 0; i < len; i++) {
10875
0
                comprehension_ty val;
10876
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10877
0
                if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10878
0
                    goto failed;
10879
0
                }
10880
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10881
0
                _Py_LeaveRecursiveCall();
10882
0
                Py_DECREF(tmp2);
10883
0
                if (res != 0) goto failed;
10884
0
                if (len != PyList_GET_SIZE(tmp)) {
10885
0
                    PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
10886
0
                    goto failed;
10887
0
                }
10888
0
                asdl_seq_SET(generators, i, val);
10889
0
            }
10890
0
            Py_CLEAR(tmp);
10891
0
        }
10892
0
        *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
10893
0
                               end_lineno, end_col_offset, arena);
10894
0
        if (*out == NULL) goto failed;
10895
0
        return 0;
10896
0
    }
10897
0
    tp = state->GeneratorExp_type;
10898
0
    isinstance = PyObject_IsInstance(obj, tp);
10899
0
    if (isinstance == -1) {
10900
0
        return -1;
10901
0
    }
10902
0
    if (isinstance) {
10903
0
        expr_ty elt;
10904
0
        asdl_comprehension_seq* generators;
10905
10906
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10907
0
            return -1;
10908
0
        }
10909
0
        if (tmp == NULL) {
10910
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
10911
0
            return -1;
10912
0
        }
10913
0
        else {
10914
0
            int res;
10915
0
            if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
10916
0
                goto failed;
10917
0
            }
10918
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10919
0
            _Py_LeaveRecursiveCall();
10920
0
            if (res != 0) goto failed;
10921
0
            Py_CLEAR(tmp);
10922
0
        }
10923
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10924
0
            return -1;
10925
0
        }
10926
0
        if (tmp == NULL) {
10927
0
            tmp = PyList_New(0);
10928
0
            if (tmp == NULL) {
10929
0
                return -1;
10930
0
            }
10931
0
        }
10932
0
        {
10933
0
            int res;
10934
0
            Py_ssize_t len;
10935
0
            Py_ssize_t i;
10936
0
            if (!PyList_Check(tmp)) {
10937
0
                PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %T", tmp);
10938
0
                goto failed;
10939
0
            }
10940
0
            len = PyList_GET_SIZE(tmp);
10941
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10942
0
            if (generators == NULL) goto failed;
10943
0
            for (i = 0; i < len; i++) {
10944
0
                comprehension_ty val;
10945
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10946
0
                if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
10947
0
                    goto failed;
10948
0
                }
10949
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10950
0
                _Py_LeaveRecursiveCall();
10951
0
                Py_DECREF(tmp2);
10952
0
                if (res != 0) goto failed;
10953
0
                if (len != PyList_GET_SIZE(tmp)) {
10954
0
                    PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
10955
0
                    goto failed;
10956
0
                }
10957
0
                asdl_seq_SET(generators, i, val);
10958
0
            }
10959
0
            Py_CLEAR(tmp);
10960
0
        }
10961
0
        *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
10962
0
                                   end_lineno, end_col_offset, arena);
10963
0
        if (*out == NULL) goto failed;
10964
0
        return 0;
10965
0
    }
10966
0
    tp = state->Await_type;
10967
0
    isinstance = PyObject_IsInstance(obj, tp);
10968
0
    if (isinstance == -1) {
10969
0
        return -1;
10970
0
    }
10971
0
    if (isinstance) {
10972
0
        expr_ty value;
10973
10974
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10975
0
            return -1;
10976
0
        }
10977
0
        if (tmp == NULL) {
10978
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
10979
0
            return -1;
10980
0
        }
10981
0
        else {
10982
0
            int res;
10983
0
            if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
10984
0
                goto failed;
10985
0
            }
10986
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10987
0
            _Py_LeaveRecursiveCall();
10988
0
            if (res != 0) goto failed;
10989
0
            Py_CLEAR(tmp);
10990
0
        }
10991
0
        *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
10992
0
                            end_col_offset, arena);
10993
0
        if (*out == NULL) goto failed;
10994
0
        return 0;
10995
0
    }
10996
0
    tp = state->Yield_type;
10997
0
    isinstance = PyObject_IsInstance(obj, tp);
10998
0
    if (isinstance == -1) {
10999
0
        return -1;
11000
0
    }
11001
0
    if (isinstance) {
11002
0
        expr_ty value;
11003
11004
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11005
0
            return -1;
11006
0
        }
11007
0
        if (tmp == NULL || tmp == Py_None) {
11008
0
            Py_CLEAR(tmp);
11009
0
            value = NULL;
11010
0
        }
11011
0
        else {
11012
0
            int res;
11013
0
            if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
11014
0
                goto failed;
11015
0
            }
11016
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11017
0
            _Py_LeaveRecursiveCall();
11018
0
            if (res != 0) goto failed;
11019
0
            Py_CLEAR(tmp);
11020
0
        }
11021
0
        *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
11022
0
                            end_col_offset, arena);
11023
0
        if (*out == NULL) goto failed;
11024
0
        return 0;
11025
0
    }
11026
0
    tp = state->YieldFrom_type;
11027
0
    isinstance = PyObject_IsInstance(obj, tp);
11028
0
    if (isinstance == -1) {
11029
0
        return -1;
11030
0
    }
11031
0
    if (isinstance) {
11032
0
        expr_ty value;
11033
11034
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11035
0
            return -1;
11036
0
        }
11037
0
        if (tmp == NULL) {
11038
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
11039
0
            return -1;
11040
0
        }
11041
0
        else {
11042
0
            int res;
11043
0
            if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
11044
0
                goto failed;
11045
0
            }
11046
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11047
0
            _Py_LeaveRecursiveCall();
11048
0
            if (res != 0) goto failed;
11049
0
            Py_CLEAR(tmp);
11050
0
        }
11051
0
        *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
11052
0
                                end_col_offset, arena);
11053
0
        if (*out == NULL) goto failed;
11054
0
        return 0;
11055
0
    }
11056
0
    tp = state->Compare_type;
11057
0
    isinstance = PyObject_IsInstance(obj, tp);
11058
0
    if (isinstance == -1) {
11059
0
        return -1;
11060
0
    }
11061
0
    if (isinstance) {
11062
0
        expr_ty left;
11063
0
        asdl_int_seq* ops;
11064
0
        asdl_expr_seq* comparators;
11065
11066
0
        if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
11067
0
            return -1;
11068
0
        }
11069
0
        if (tmp == NULL) {
11070
0
            PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
11071
0
            return -1;
11072
0
        }
11073
0
        else {
11074
0
            int res;
11075
0
            if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11076
0
                goto failed;
11077
0
            }
11078
0
            res = obj2ast_expr(state, tmp, &left, "left", arena);
11079
0
            _Py_LeaveRecursiveCall();
11080
0
            if (res != 0) goto failed;
11081
0
            Py_CLEAR(tmp);
11082
0
        }
11083
0
        if (PyObject_GetOptionalAttr(obj, state->ops, &tmp) < 0) {
11084
0
            return -1;
11085
0
        }
11086
0
        if (tmp == NULL) {
11087
0
            tmp = PyList_New(0);
11088
0
            if (tmp == NULL) {
11089
0
                return -1;
11090
0
            }
11091
0
        }
11092
0
        {
11093
0
            int res;
11094
0
            Py_ssize_t len;
11095
0
            Py_ssize_t i;
11096
0
            if (!PyList_Check(tmp)) {
11097
0
                PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %T", tmp);
11098
0
                goto failed;
11099
0
            }
11100
0
            len = PyList_GET_SIZE(tmp);
11101
0
            ops = _Py_asdl_int_seq_new(len, arena);
11102
0
            if (ops == NULL) goto failed;
11103
0
            for (i = 0; i < len; i++) {
11104
0
                cmpop_ty val;
11105
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11106
0
                if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11107
0
                    goto failed;
11108
0
                }
11109
0
                res = obj2ast_cmpop(state, tmp2, &val, "ops", arena);
11110
0
                _Py_LeaveRecursiveCall();
11111
0
                Py_DECREF(tmp2);
11112
0
                if (res != 0) goto failed;
11113
0
                if (len != PyList_GET_SIZE(tmp)) {
11114
0
                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
11115
0
                    goto failed;
11116
0
                }
11117
0
                asdl_seq_SET(ops, i, val);
11118
0
            }
11119
0
            Py_CLEAR(tmp);
11120
0
        }
11121
0
        if (PyObject_GetOptionalAttr(obj, state->comparators, &tmp) < 0) {
11122
0
            return -1;
11123
0
        }
11124
0
        if (tmp == NULL) {
11125
0
            tmp = PyList_New(0);
11126
0
            if (tmp == NULL) {
11127
0
                return -1;
11128
0
            }
11129
0
        }
11130
0
        {
11131
0
            int res;
11132
0
            Py_ssize_t len;
11133
0
            Py_ssize_t i;
11134
0
            if (!PyList_Check(tmp)) {
11135
0
                PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %T", tmp);
11136
0
                goto failed;
11137
0
            }
11138
0
            len = PyList_GET_SIZE(tmp);
11139
0
            comparators = _Py_asdl_expr_seq_new(len, arena);
11140
0
            if (comparators == NULL) goto failed;
11141
0
            for (i = 0; i < len; i++) {
11142
0
                expr_ty val;
11143
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11144
0
                if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11145
0
                    goto failed;
11146
0
                }
11147
0
                res = obj2ast_expr(state, tmp2, &val, "comparators", arena);
11148
0
                _Py_LeaveRecursiveCall();
11149
0
                Py_DECREF(tmp2);
11150
0
                if (res != 0) goto failed;
11151
0
                if (len != PyList_GET_SIZE(tmp)) {
11152
0
                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
11153
0
                    goto failed;
11154
0
                }
11155
0
                asdl_seq_SET(comparators, i, val);
11156
0
            }
11157
0
            Py_CLEAR(tmp);
11158
0
        }
11159
0
        *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
11160
0
                              end_lineno, end_col_offset, arena);
11161
0
        if (*out == NULL) goto failed;
11162
0
        return 0;
11163
0
    }
11164
0
    tp = state->Call_type;
11165
0
    isinstance = PyObject_IsInstance(obj, tp);
11166
0
    if (isinstance == -1) {
11167
0
        return -1;
11168
0
    }
11169
0
    if (isinstance) {
11170
0
        expr_ty func;
11171
0
        asdl_expr_seq* args;
11172
0
        asdl_keyword_seq* keywords;
11173
11174
0
        if (PyObject_GetOptionalAttr(obj, state->func, &tmp) < 0) {
11175
0
            return -1;
11176
0
        }
11177
0
        if (tmp == NULL) {
11178
0
            PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
11179
0
            return -1;
11180
0
        }
11181
0
        else {
11182
0
            int res;
11183
0
            if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11184
0
                goto failed;
11185
0
            }
11186
0
            res = obj2ast_expr(state, tmp, &func, "func", arena);
11187
0
            _Py_LeaveRecursiveCall();
11188
0
            if (res != 0) goto failed;
11189
0
            Py_CLEAR(tmp);
11190
0
        }
11191
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
11192
0
            return -1;
11193
0
        }
11194
0
        if (tmp == NULL) {
11195
0
            tmp = PyList_New(0);
11196
0
            if (tmp == NULL) {
11197
0
                return -1;
11198
0
            }
11199
0
        }
11200
0
        {
11201
0
            int res;
11202
0
            Py_ssize_t len;
11203
0
            Py_ssize_t i;
11204
0
            if (!PyList_Check(tmp)) {
11205
0
                PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %T", tmp);
11206
0
                goto failed;
11207
0
            }
11208
0
            len = PyList_GET_SIZE(tmp);
11209
0
            args = _Py_asdl_expr_seq_new(len, arena);
11210
0
            if (args == NULL) goto failed;
11211
0
            for (i = 0; i < len; i++) {
11212
0
                expr_ty val;
11213
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11214
0
                if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11215
0
                    goto failed;
11216
0
                }
11217
0
                res = obj2ast_expr(state, tmp2, &val, "args", arena);
11218
0
                _Py_LeaveRecursiveCall();
11219
0
                Py_DECREF(tmp2);
11220
0
                if (res != 0) goto failed;
11221
0
                if (len != PyList_GET_SIZE(tmp)) {
11222
0
                    PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
11223
0
                    goto failed;
11224
0
                }
11225
0
                asdl_seq_SET(args, i, val);
11226
0
            }
11227
0
            Py_CLEAR(tmp);
11228
0
        }
11229
0
        if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
11230
0
            return -1;
11231
0
        }
11232
0
        if (tmp == NULL) {
11233
0
            tmp = PyList_New(0);
11234
0
            if (tmp == NULL) {
11235
0
                return -1;
11236
0
            }
11237
0
        }
11238
0
        {
11239
0
            int res;
11240
0
            Py_ssize_t len;
11241
0
            Py_ssize_t i;
11242
0
            if (!PyList_Check(tmp)) {
11243
0
                PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %T", tmp);
11244
0
                goto failed;
11245
0
            }
11246
0
            len = PyList_GET_SIZE(tmp);
11247
0
            keywords = _Py_asdl_keyword_seq_new(len, arena);
11248
0
            if (keywords == NULL) goto failed;
11249
0
            for (i = 0; i < len; i++) {
11250
0
                keyword_ty val;
11251
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11252
0
                if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11253
0
                    goto failed;
11254
0
                }
11255
0
                res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
11256
0
                _Py_LeaveRecursiveCall();
11257
0
                Py_DECREF(tmp2);
11258
0
                if (res != 0) goto failed;
11259
0
                if (len != PyList_GET_SIZE(tmp)) {
11260
0
                    PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
11261
0
                    goto failed;
11262
0
                }
11263
0
                asdl_seq_SET(keywords, i, val);
11264
0
            }
11265
0
            Py_CLEAR(tmp);
11266
0
        }
11267
0
        *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
11268
0
                           end_lineno, end_col_offset, arena);
11269
0
        if (*out == NULL) goto failed;
11270
0
        return 0;
11271
0
    }
11272
0
    tp = state->FormattedValue_type;
11273
0
    isinstance = PyObject_IsInstance(obj, tp);
11274
0
    if (isinstance == -1) {
11275
0
        return -1;
11276
0
    }
11277
0
    if (isinstance) {
11278
0
        expr_ty value;
11279
0
        int conversion;
11280
0
        expr_ty format_spec;
11281
11282
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11283
0
            return -1;
11284
0
        }
11285
0
        if (tmp == NULL) {
11286
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
11287
0
            return -1;
11288
0
        }
11289
0
        else {
11290
0
            int res;
11291
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11292
0
                goto failed;
11293
0
            }
11294
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11295
0
            _Py_LeaveRecursiveCall();
11296
0
            if (res != 0) goto failed;
11297
0
            Py_CLEAR(tmp);
11298
0
        }
11299
0
        if (PyObject_GetOptionalAttr(obj, state->conversion, &tmp) < 0) {
11300
0
            return -1;
11301
0
        }
11302
0
        if (tmp == NULL) {
11303
0
            PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
11304
0
            return -1;
11305
0
        }
11306
0
        else {
11307
0
            int res;
11308
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11309
0
                goto failed;
11310
0
            }
11311
0
            res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
11312
0
            _Py_LeaveRecursiveCall();
11313
0
            if (res != 0) goto failed;
11314
0
            Py_CLEAR(tmp);
11315
0
        }
11316
0
        if (PyObject_GetOptionalAttr(obj, state->format_spec, &tmp) < 0) {
11317
0
            return -1;
11318
0
        }
11319
0
        if (tmp == NULL || tmp == Py_None) {
11320
0
            Py_CLEAR(tmp);
11321
0
            format_spec = NULL;
11322
0
        }
11323
0
        else {
11324
0
            int res;
11325
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11326
0
                goto failed;
11327
0
            }
11328
0
            res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
11329
0
            _Py_LeaveRecursiveCall();
11330
0
            if (res != 0) goto failed;
11331
0
            Py_CLEAR(tmp);
11332
0
        }
11333
0
        *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
11334
0
                                     col_offset, end_lineno, end_col_offset,
11335
0
                                     arena);
11336
0
        if (*out == NULL) goto failed;
11337
0
        return 0;
11338
0
    }
11339
0
    tp = state->Interpolation_type;
11340
0
    isinstance = PyObject_IsInstance(obj, tp);
11341
0
    if (isinstance == -1) {
11342
0
        return -1;
11343
0
    }
11344
0
    if (isinstance) {
11345
0
        expr_ty value;
11346
0
        constant str;
11347
0
        int conversion;
11348
0
        expr_ty format_spec;
11349
11350
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11351
0
            return -1;
11352
0
        }
11353
0
        if (tmp == NULL) {
11354
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Interpolation");
11355
0
            return -1;
11356
0
        }
11357
0
        else {
11358
0
            int res;
11359
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11360
0
                goto failed;
11361
0
            }
11362
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11363
0
            _Py_LeaveRecursiveCall();
11364
0
            if (res != 0) goto failed;
11365
0
            Py_CLEAR(tmp);
11366
0
        }
11367
0
        if (PyObject_GetOptionalAttr(obj, state->str, &tmp) < 0) {
11368
0
            return -1;
11369
0
        }
11370
0
        if (tmp == NULL) {
11371
0
            PyErr_SetString(PyExc_TypeError, "required field \"str\" missing from Interpolation");
11372
0
            return -1;
11373
0
        }
11374
0
        else {
11375
0
            int res;
11376
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11377
0
                goto failed;
11378
0
            }
11379
0
            res = obj2ast_constant(state, tmp, &str, "str", arena);
11380
0
            _Py_LeaveRecursiveCall();
11381
0
            if (res != 0) goto failed;
11382
0
            Py_CLEAR(tmp);
11383
0
        }
11384
0
        if (PyObject_GetOptionalAttr(obj, state->conversion, &tmp) < 0) {
11385
0
            return -1;
11386
0
        }
11387
0
        if (tmp == NULL) {
11388
0
            PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from Interpolation");
11389
0
            return -1;
11390
0
        }
11391
0
        else {
11392
0
            int res;
11393
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11394
0
                goto failed;
11395
0
            }
11396
0
            res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
11397
0
            _Py_LeaveRecursiveCall();
11398
0
            if (res != 0) goto failed;
11399
0
            Py_CLEAR(tmp);
11400
0
        }
11401
0
        if (PyObject_GetOptionalAttr(obj, state->format_spec, &tmp) < 0) {
11402
0
            return -1;
11403
0
        }
11404
0
        if (tmp == NULL || tmp == Py_None) {
11405
0
            Py_CLEAR(tmp);
11406
0
            format_spec = NULL;
11407
0
        }
11408
0
        else {
11409
0
            int res;
11410
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11411
0
                goto failed;
11412
0
            }
11413
0
            res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
11414
0
            _Py_LeaveRecursiveCall();
11415
0
            if (res != 0) goto failed;
11416
0
            Py_CLEAR(tmp);
11417
0
        }
11418
0
        *out = _PyAST_Interpolation(value, str, conversion, format_spec,
11419
0
                                    lineno, col_offset, end_lineno,
11420
0
                                    end_col_offset, arena);
11421
0
        if (*out == NULL) goto failed;
11422
0
        return 0;
11423
0
    }
11424
0
    tp = state->JoinedStr_type;
11425
0
    isinstance = PyObject_IsInstance(obj, tp);
11426
0
    if (isinstance == -1) {
11427
0
        return -1;
11428
0
    }
11429
0
    if (isinstance) {
11430
0
        asdl_expr_seq* values;
11431
11432
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
11433
0
            return -1;
11434
0
        }
11435
0
        if (tmp == NULL) {
11436
0
            tmp = PyList_New(0);
11437
0
            if (tmp == NULL) {
11438
0
                return -1;
11439
0
            }
11440
0
        }
11441
0
        {
11442
0
            int res;
11443
0
            Py_ssize_t len;
11444
0
            Py_ssize_t i;
11445
0
            if (!PyList_Check(tmp)) {
11446
0
                PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %T", tmp);
11447
0
                goto failed;
11448
0
            }
11449
0
            len = PyList_GET_SIZE(tmp);
11450
0
            values = _Py_asdl_expr_seq_new(len, arena);
11451
0
            if (values == NULL) goto failed;
11452
0
            for (i = 0; i < len; i++) {
11453
0
                expr_ty val;
11454
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11455
0
                if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
11456
0
                    goto failed;
11457
0
                }
11458
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
11459
0
                _Py_LeaveRecursiveCall();
11460
0
                Py_DECREF(tmp2);
11461
0
                if (res != 0) goto failed;
11462
0
                if (len != PyList_GET_SIZE(tmp)) {
11463
0
                    PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
11464
0
                    goto failed;
11465
0
                }
11466
0
                asdl_seq_SET(values, i, val);
11467
0
            }
11468
0
            Py_CLEAR(tmp);
11469
0
        }
11470
0
        *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
11471
0
                                end_col_offset, arena);
11472
0
        if (*out == NULL) goto failed;
11473
0
        return 0;
11474
0
    }
11475
0
    tp = state->TemplateStr_type;
11476
0
    isinstance = PyObject_IsInstance(obj, tp);
11477
0
    if (isinstance == -1) {
11478
0
        return -1;
11479
0
    }
11480
0
    if (isinstance) {
11481
0
        asdl_expr_seq* values;
11482
11483
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
11484
0
            return -1;
11485
0
        }
11486
0
        if (tmp == NULL) {
11487
0
            tmp = PyList_New(0);
11488
0
            if (tmp == NULL) {
11489
0
                return -1;
11490
0
            }
11491
0
        }
11492
0
        {
11493
0
            int res;
11494
0
            Py_ssize_t len;
11495
0
            Py_ssize_t i;
11496
0
            if (!PyList_Check(tmp)) {
11497
0
                PyErr_Format(PyExc_TypeError, "TemplateStr field \"values\" must be a list, not a %T", tmp);
11498
0
                goto failed;
11499
0
            }
11500
0
            len = PyList_GET_SIZE(tmp);
11501
0
            values = _Py_asdl_expr_seq_new(len, arena);
11502
0
            if (values == NULL) goto failed;
11503
0
            for (i = 0; i < len; i++) {
11504
0
                expr_ty val;
11505
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11506
0
                if (_Py_EnterRecursiveCall(" while traversing 'TemplateStr' node")) {
11507
0
                    goto failed;
11508
0
                }
11509
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
11510
0
                _Py_LeaveRecursiveCall();
11511
0
                Py_DECREF(tmp2);
11512
0
                if (res != 0) goto failed;
11513
0
                if (len != PyList_GET_SIZE(tmp)) {
11514
0
                    PyErr_SetString(PyExc_RuntimeError, "TemplateStr field \"values\" changed size during iteration");
11515
0
                    goto failed;
11516
0
                }
11517
0
                asdl_seq_SET(values, i, val);
11518
0
            }
11519
0
            Py_CLEAR(tmp);
11520
0
        }
11521
0
        *out = _PyAST_TemplateStr(values, lineno, col_offset, end_lineno,
11522
0
                                  end_col_offset, arena);
11523
0
        if (*out == NULL) goto failed;
11524
0
        return 0;
11525
0
    }
11526
0
    tp = state->Constant_type;
11527
0
    isinstance = PyObject_IsInstance(obj, tp);
11528
0
    if (isinstance == -1) {
11529
0
        return -1;
11530
0
    }
11531
0
    if (isinstance) {
11532
0
        constant value;
11533
0
        string kind;
11534
11535
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11536
0
            return -1;
11537
0
        }
11538
0
        if (tmp == NULL) {
11539
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
11540
0
            return -1;
11541
0
        }
11542
0
        else {
11543
0
            int res;
11544
0
            if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
11545
0
                goto failed;
11546
0
            }
11547
0
            res = obj2ast_constant(state, tmp, &value, "value", arena);
11548
0
            _Py_LeaveRecursiveCall();
11549
0
            if (res != 0) goto failed;
11550
0
            Py_CLEAR(tmp);
11551
0
        }
11552
0
        if (PyObject_GetOptionalAttr(obj, state->kind, &tmp) < 0) {
11553
0
            return -1;
11554
0
        }
11555
0
        if (tmp == NULL || tmp == Py_None) {
11556
0
            Py_CLEAR(tmp);
11557
0
            kind = NULL;
11558
0
        }
11559
0
        else {
11560
0
            int res;
11561
0
            if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
11562
0
                goto failed;
11563
0
            }
11564
0
            res = obj2ast_string(state, tmp, &kind, "kind", arena);
11565
0
            _Py_LeaveRecursiveCall();
11566
0
            if (res != 0) goto failed;
11567
0
            Py_CLEAR(tmp);
11568
0
        }
11569
0
        *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
11570
0
                               end_col_offset, arena);
11571
0
        if (*out == NULL) goto failed;
11572
0
        return 0;
11573
0
    }
11574
0
    tp = state->Attribute_type;
11575
0
    isinstance = PyObject_IsInstance(obj, tp);
11576
0
    if (isinstance == -1) {
11577
0
        return -1;
11578
0
    }
11579
0
    if (isinstance) {
11580
0
        expr_ty value;
11581
0
        identifier attr;
11582
0
        expr_context_ty ctx;
11583
11584
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11585
0
            return -1;
11586
0
        }
11587
0
        if (tmp == NULL) {
11588
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
11589
0
            return -1;
11590
0
        }
11591
0
        else {
11592
0
            int res;
11593
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11594
0
                goto failed;
11595
0
            }
11596
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11597
0
            _Py_LeaveRecursiveCall();
11598
0
            if (res != 0) goto failed;
11599
0
            Py_CLEAR(tmp);
11600
0
        }
11601
0
        if (PyObject_GetOptionalAttr(obj, state->attr, &tmp) < 0) {
11602
0
            return -1;
11603
0
        }
11604
0
        if (tmp == NULL) {
11605
0
            PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
11606
0
            return -1;
11607
0
        }
11608
0
        else {
11609
0
            int res;
11610
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11611
0
                goto failed;
11612
0
            }
11613
0
            res = obj2ast_identifier(state, tmp, &attr, "attr", arena);
11614
0
            _Py_LeaveRecursiveCall();
11615
0
            if (res != 0) goto failed;
11616
0
            Py_CLEAR(tmp);
11617
0
        }
11618
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11619
0
            return -1;
11620
0
        }
11621
0
        if (tmp == NULL) {
11622
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
11623
0
            return -1;
11624
0
        }
11625
0
        else {
11626
0
            int res;
11627
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11628
0
                goto failed;
11629
0
            }
11630
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11631
0
            _Py_LeaveRecursiveCall();
11632
0
            if (res != 0) goto failed;
11633
0
            Py_CLEAR(tmp);
11634
0
        }
11635
0
        *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
11636
0
                                end_lineno, end_col_offset, arena);
11637
0
        if (*out == NULL) goto failed;
11638
0
        return 0;
11639
0
    }
11640
0
    tp = state->Subscript_type;
11641
0
    isinstance = PyObject_IsInstance(obj, tp);
11642
0
    if (isinstance == -1) {
11643
0
        return -1;
11644
0
    }
11645
0
    if (isinstance) {
11646
0
        expr_ty value;
11647
0
        expr_ty slice;
11648
0
        expr_context_ty ctx;
11649
11650
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11651
0
            return -1;
11652
0
        }
11653
0
        if (tmp == NULL) {
11654
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
11655
0
            return -1;
11656
0
        }
11657
0
        else {
11658
0
            int res;
11659
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11660
0
                goto failed;
11661
0
            }
11662
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11663
0
            _Py_LeaveRecursiveCall();
11664
0
            if (res != 0) goto failed;
11665
0
            Py_CLEAR(tmp);
11666
0
        }
11667
0
        if (PyObject_GetOptionalAttr(obj, state->slice, &tmp) < 0) {
11668
0
            return -1;
11669
0
        }
11670
0
        if (tmp == NULL) {
11671
0
            PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
11672
0
            return -1;
11673
0
        }
11674
0
        else {
11675
0
            int res;
11676
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11677
0
                goto failed;
11678
0
            }
11679
0
            res = obj2ast_expr(state, tmp, &slice, "slice", arena);
11680
0
            _Py_LeaveRecursiveCall();
11681
0
            if (res != 0) goto failed;
11682
0
            Py_CLEAR(tmp);
11683
0
        }
11684
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11685
0
            return -1;
11686
0
        }
11687
0
        if (tmp == NULL) {
11688
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
11689
0
            return -1;
11690
0
        }
11691
0
        else {
11692
0
            int res;
11693
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11694
0
                goto failed;
11695
0
            }
11696
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11697
0
            _Py_LeaveRecursiveCall();
11698
0
            if (res != 0) goto failed;
11699
0
            Py_CLEAR(tmp);
11700
0
        }
11701
0
        *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
11702
0
                                end_lineno, end_col_offset, arena);
11703
0
        if (*out == NULL) goto failed;
11704
0
        return 0;
11705
0
    }
11706
0
    tp = state->Starred_type;
11707
0
    isinstance = PyObject_IsInstance(obj, tp);
11708
0
    if (isinstance == -1) {
11709
0
        return -1;
11710
0
    }
11711
0
    if (isinstance) {
11712
0
        expr_ty value;
11713
0
        expr_context_ty ctx;
11714
11715
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11716
0
            return -1;
11717
0
        }
11718
0
        if (tmp == NULL) {
11719
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
11720
0
            return -1;
11721
0
        }
11722
0
        else {
11723
0
            int res;
11724
0
            if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
11725
0
                goto failed;
11726
0
            }
11727
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11728
0
            _Py_LeaveRecursiveCall();
11729
0
            if (res != 0) goto failed;
11730
0
            Py_CLEAR(tmp);
11731
0
        }
11732
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11733
0
            return -1;
11734
0
        }
11735
0
        if (tmp == NULL) {
11736
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
11737
0
            return -1;
11738
0
        }
11739
0
        else {
11740
0
            int res;
11741
0
            if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
11742
0
                goto failed;
11743
0
            }
11744
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11745
0
            _Py_LeaveRecursiveCall();
11746
0
            if (res != 0) goto failed;
11747
0
            Py_CLEAR(tmp);
11748
0
        }
11749
0
        *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
11750
0
                              end_col_offset, arena);
11751
0
        if (*out == NULL) goto failed;
11752
0
        return 0;
11753
0
    }
11754
0
    tp = state->Name_type;
11755
0
    isinstance = PyObject_IsInstance(obj, tp);
11756
0
    if (isinstance == -1) {
11757
0
        return -1;
11758
0
    }
11759
0
    if (isinstance) {
11760
0
        identifier id;
11761
0
        expr_context_ty ctx;
11762
11763
0
        if (PyObject_GetOptionalAttr(obj, state->id, &tmp) < 0) {
11764
0
            return -1;
11765
0
        }
11766
0
        if (tmp == NULL) {
11767
0
            PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
11768
0
            return -1;
11769
0
        }
11770
0
        else {
11771
0
            int res;
11772
0
            if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
11773
0
                goto failed;
11774
0
            }
11775
0
            res = obj2ast_identifier(state, tmp, &id, "id", arena);
11776
0
            _Py_LeaveRecursiveCall();
11777
0
            if (res != 0) goto failed;
11778
0
            Py_CLEAR(tmp);
11779
0
        }
11780
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11781
0
            return -1;
11782
0
        }
11783
0
        if (tmp == NULL) {
11784
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
11785
0
            return -1;
11786
0
        }
11787
0
        else {
11788
0
            int res;
11789
0
            if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
11790
0
                goto failed;
11791
0
            }
11792
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11793
0
            _Py_LeaveRecursiveCall();
11794
0
            if (res != 0) goto failed;
11795
0
            Py_CLEAR(tmp);
11796
0
        }
11797
0
        *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
11798
0
                           end_col_offset, arena);
11799
0
        if (*out == NULL) goto failed;
11800
0
        return 0;
11801
0
    }
11802
0
    tp = state->List_type;
11803
0
    isinstance = PyObject_IsInstance(obj, tp);
11804
0
    if (isinstance == -1) {
11805
0
        return -1;
11806
0
    }
11807
0
    if (isinstance) {
11808
0
        asdl_expr_seq* elts;
11809
0
        expr_context_ty ctx;
11810
11811
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
11812
0
            return -1;
11813
0
        }
11814
0
        if (tmp == NULL) {
11815
0
            tmp = PyList_New(0);
11816
0
            if (tmp == NULL) {
11817
0
                return -1;
11818
0
            }
11819
0
        }
11820
0
        {
11821
0
            int res;
11822
0
            Py_ssize_t len;
11823
0
            Py_ssize_t i;
11824
0
            if (!PyList_Check(tmp)) {
11825
0
                PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %T", tmp);
11826
0
                goto failed;
11827
0
            }
11828
0
            len = PyList_GET_SIZE(tmp);
11829
0
            elts = _Py_asdl_expr_seq_new(len, arena);
11830
0
            if (elts == NULL) goto failed;
11831
0
            for (i = 0; i < len; i++) {
11832
0
                expr_ty val;
11833
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11834
0
                if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
11835
0
                    goto failed;
11836
0
                }
11837
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
11838
0
                _Py_LeaveRecursiveCall();
11839
0
                Py_DECREF(tmp2);
11840
0
                if (res != 0) goto failed;
11841
0
                if (len != PyList_GET_SIZE(tmp)) {
11842
0
                    PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
11843
0
                    goto failed;
11844
0
                }
11845
0
                asdl_seq_SET(elts, i, val);
11846
0
            }
11847
0
            Py_CLEAR(tmp);
11848
0
        }
11849
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11850
0
            return -1;
11851
0
        }
11852
0
        if (tmp == NULL) {
11853
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
11854
0
            return -1;
11855
0
        }
11856
0
        else {
11857
0
            int res;
11858
0
            if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
11859
0
                goto failed;
11860
0
            }
11861
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11862
0
            _Py_LeaveRecursiveCall();
11863
0
            if (res != 0) goto failed;
11864
0
            Py_CLEAR(tmp);
11865
0
        }
11866
0
        *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
11867
0
                           end_col_offset, arena);
11868
0
        if (*out == NULL) goto failed;
11869
0
        return 0;
11870
0
    }
11871
0
    tp = state->Tuple_type;
11872
0
    isinstance = PyObject_IsInstance(obj, tp);
11873
0
    if (isinstance == -1) {
11874
0
        return -1;
11875
0
    }
11876
0
    if (isinstance) {
11877
0
        asdl_expr_seq* elts;
11878
0
        expr_context_ty ctx;
11879
11880
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
11881
0
            return -1;
11882
0
        }
11883
0
        if (tmp == NULL) {
11884
0
            tmp = PyList_New(0);
11885
0
            if (tmp == NULL) {
11886
0
                return -1;
11887
0
            }
11888
0
        }
11889
0
        {
11890
0
            int res;
11891
0
            Py_ssize_t len;
11892
0
            Py_ssize_t i;
11893
0
            if (!PyList_Check(tmp)) {
11894
0
                PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %T", tmp);
11895
0
                goto failed;
11896
0
            }
11897
0
            len = PyList_GET_SIZE(tmp);
11898
0
            elts = _Py_asdl_expr_seq_new(len, arena);
11899
0
            if (elts == NULL) goto failed;
11900
0
            for (i = 0; i < len; i++) {
11901
0
                expr_ty val;
11902
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11903
0
                if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
11904
0
                    goto failed;
11905
0
                }
11906
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
11907
0
                _Py_LeaveRecursiveCall();
11908
0
                Py_DECREF(tmp2);
11909
0
                if (res != 0) goto failed;
11910
0
                if (len != PyList_GET_SIZE(tmp)) {
11911
0
                    PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
11912
0
                    goto failed;
11913
0
                }
11914
0
                asdl_seq_SET(elts, i, val);
11915
0
            }
11916
0
            Py_CLEAR(tmp);
11917
0
        }
11918
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11919
0
            return -1;
11920
0
        }
11921
0
        if (tmp == NULL) {
11922
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
11923
0
            return -1;
11924
0
        }
11925
0
        else {
11926
0
            int res;
11927
0
            if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
11928
0
                goto failed;
11929
0
            }
11930
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11931
0
            _Py_LeaveRecursiveCall();
11932
0
            if (res != 0) goto failed;
11933
0
            Py_CLEAR(tmp);
11934
0
        }
11935
0
        *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
11936
0
                            end_col_offset, arena);
11937
0
        if (*out == NULL) goto failed;
11938
0
        return 0;
11939
0
    }
11940
0
    tp = state->Slice_type;
11941
0
    isinstance = PyObject_IsInstance(obj, tp);
11942
0
    if (isinstance == -1) {
11943
0
        return -1;
11944
0
    }
11945
0
    if (isinstance) {
11946
0
        expr_ty lower;
11947
0
        expr_ty upper;
11948
0
        expr_ty step;
11949
11950
0
        if (PyObject_GetOptionalAttr(obj, state->lower, &tmp) < 0) {
11951
0
            return -1;
11952
0
        }
11953
0
        if (tmp == NULL || tmp == Py_None) {
11954
0
            Py_CLEAR(tmp);
11955
0
            lower = NULL;
11956
0
        }
11957
0
        else {
11958
0
            int res;
11959
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11960
0
                goto failed;
11961
0
            }
11962
0
            res = obj2ast_expr(state, tmp, &lower, "lower", arena);
11963
0
            _Py_LeaveRecursiveCall();
11964
0
            if (res != 0) goto failed;
11965
0
            Py_CLEAR(tmp);
11966
0
        }
11967
0
        if (PyObject_GetOptionalAttr(obj, state->upper, &tmp) < 0) {
11968
0
            return -1;
11969
0
        }
11970
0
        if (tmp == NULL || tmp == Py_None) {
11971
0
            Py_CLEAR(tmp);
11972
0
            upper = NULL;
11973
0
        }
11974
0
        else {
11975
0
            int res;
11976
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11977
0
                goto failed;
11978
0
            }
11979
0
            res = obj2ast_expr(state, tmp, &upper, "upper", arena);
11980
0
            _Py_LeaveRecursiveCall();
11981
0
            if (res != 0) goto failed;
11982
0
            Py_CLEAR(tmp);
11983
0
        }
11984
0
        if (PyObject_GetOptionalAttr(obj, state->step, &tmp) < 0) {
11985
0
            return -1;
11986
0
        }
11987
0
        if (tmp == NULL || tmp == Py_None) {
11988
0
            Py_CLEAR(tmp);
11989
0
            step = NULL;
11990
0
        }
11991
0
        else {
11992
0
            int res;
11993
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11994
0
                goto failed;
11995
0
            }
11996
0
            res = obj2ast_expr(state, tmp, &step, "step", arena);
11997
0
            _Py_LeaveRecursiveCall();
11998
0
            if (res != 0) goto failed;
11999
0
            Py_CLEAR(tmp);
12000
0
        }
12001
0
        *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
12002
0
                            end_col_offset, arena);
12003
0
        if (*out == NULL) goto failed;
12004
0
        return 0;
12005
0
    }
12006
12007
0
    PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
12008
0
    failed:
12009
0
    Py_XDECREF(tmp);
12010
0
    return -1;
12011
0
}
12012
12013
int
12014
obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
12015
                     out, const char* field, PyArena* arena)
12016
0
{
12017
0
    int isinstance;
12018
12019
0
    isinstance = PyObject_IsInstance(obj, state->Load_type);
12020
0
    if (isinstance == -1) {
12021
0
        return -1;
12022
0
    }
12023
0
    if (isinstance) {
12024
0
        *out = Load;
12025
0
        return 0;
12026
0
    }
12027
0
    isinstance = PyObject_IsInstance(obj, state->Store_type);
12028
0
    if (isinstance == -1) {
12029
0
        return -1;
12030
0
    }
12031
0
    if (isinstance) {
12032
0
        *out = Store;
12033
0
        return 0;
12034
0
    }
12035
0
    isinstance = PyObject_IsInstance(obj, state->Del_type);
12036
0
    if (isinstance == -1) {
12037
0
        return -1;
12038
0
    }
12039
0
    if (isinstance) {
12040
0
        *out = Del;
12041
0
        return 0;
12042
0
    }
12043
12044
0
    PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
12045
0
    return -1;
12046
0
}
12047
12048
int
12049
obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, const
12050
               char* field, PyArena* arena)
12051
0
{
12052
0
    int isinstance;
12053
12054
0
    isinstance = PyObject_IsInstance(obj, state->And_type);
12055
0
    if (isinstance == -1) {
12056
0
        return -1;
12057
0
    }
12058
0
    if (isinstance) {
12059
0
        *out = And;
12060
0
        return 0;
12061
0
    }
12062
0
    isinstance = PyObject_IsInstance(obj, state->Or_type);
12063
0
    if (isinstance == -1) {
12064
0
        return -1;
12065
0
    }
12066
0
    if (isinstance) {
12067
0
        *out = Or;
12068
0
        return 0;
12069
0
    }
12070
12071
0
    PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
12072
0
    return -1;
12073
0
}
12074
12075
int
12076
obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
12077
                 const char* field, PyArena* arena)
12078
0
{
12079
0
    int isinstance;
12080
12081
0
    isinstance = PyObject_IsInstance(obj, state->Add_type);
12082
0
    if (isinstance == -1) {
12083
0
        return -1;
12084
0
    }
12085
0
    if (isinstance) {
12086
0
        *out = Add;
12087
0
        return 0;
12088
0
    }
12089
0
    isinstance = PyObject_IsInstance(obj, state->Sub_type);
12090
0
    if (isinstance == -1) {
12091
0
        return -1;
12092
0
    }
12093
0
    if (isinstance) {
12094
0
        *out = Sub;
12095
0
        return 0;
12096
0
    }
12097
0
    isinstance = PyObject_IsInstance(obj, state->Mult_type);
12098
0
    if (isinstance == -1) {
12099
0
        return -1;
12100
0
    }
12101
0
    if (isinstance) {
12102
0
        *out = Mult;
12103
0
        return 0;
12104
0
    }
12105
0
    isinstance = PyObject_IsInstance(obj, state->MatMult_type);
12106
0
    if (isinstance == -1) {
12107
0
        return -1;
12108
0
    }
12109
0
    if (isinstance) {
12110
0
        *out = MatMult;
12111
0
        return 0;
12112
0
    }
12113
0
    isinstance = PyObject_IsInstance(obj, state->Div_type);
12114
0
    if (isinstance == -1) {
12115
0
        return -1;
12116
0
    }
12117
0
    if (isinstance) {
12118
0
        *out = Div;
12119
0
        return 0;
12120
0
    }
12121
0
    isinstance = PyObject_IsInstance(obj, state->Mod_type);
12122
0
    if (isinstance == -1) {
12123
0
        return -1;
12124
0
    }
12125
0
    if (isinstance) {
12126
0
        *out = Mod;
12127
0
        return 0;
12128
0
    }
12129
0
    isinstance = PyObject_IsInstance(obj, state->Pow_type);
12130
0
    if (isinstance == -1) {
12131
0
        return -1;
12132
0
    }
12133
0
    if (isinstance) {
12134
0
        *out = Pow;
12135
0
        return 0;
12136
0
    }
12137
0
    isinstance = PyObject_IsInstance(obj, state->LShift_type);
12138
0
    if (isinstance == -1) {
12139
0
        return -1;
12140
0
    }
12141
0
    if (isinstance) {
12142
0
        *out = LShift;
12143
0
        return 0;
12144
0
    }
12145
0
    isinstance = PyObject_IsInstance(obj, state->RShift_type);
12146
0
    if (isinstance == -1) {
12147
0
        return -1;
12148
0
    }
12149
0
    if (isinstance) {
12150
0
        *out = RShift;
12151
0
        return 0;
12152
0
    }
12153
0
    isinstance = PyObject_IsInstance(obj, state->BitOr_type);
12154
0
    if (isinstance == -1) {
12155
0
        return -1;
12156
0
    }
12157
0
    if (isinstance) {
12158
0
        *out = BitOr;
12159
0
        return 0;
12160
0
    }
12161
0
    isinstance = PyObject_IsInstance(obj, state->BitXor_type);
12162
0
    if (isinstance == -1) {
12163
0
        return -1;
12164
0
    }
12165
0
    if (isinstance) {
12166
0
        *out = BitXor;
12167
0
        return 0;
12168
0
    }
12169
0
    isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
12170
0
    if (isinstance == -1) {
12171
0
        return -1;
12172
0
    }
12173
0
    if (isinstance) {
12174
0
        *out = BitAnd;
12175
0
        return 0;
12176
0
    }
12177
0
    isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
12178
0
    if (isinstance == -1) {
12179
0
        return -1;
12180
0
    }
12181
0
    if (isinstance) {
12182
0
        *out = FloorDiv;
12183
0
        return 0;
12184
0
    }
12185
12186
0
    PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
12187
0
    return -1;
12188
0
}
12189
12190
int
12191
obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out, const
12192
                char* field, PyArena* arena)
12193
0
{
12194
0
    int isinstance;
12195
12196
0
    isinstance = PyObject_IsInstance(obj, state->Invert_type);
12197
0
    if (isinstance == -1) {
12198
0
        return -1;
12199
0
    }
12200
0
    if (isinstance) {
12201
0
        *out = Invert;
12202
0
        return 0;
12203
0
    }
12204
0
    isinstance = PyObject_IsInstance(obj, state->Not_type);
12205
0
    if (isinstance == -1) {
12206
0
        return -1;
12207
0
    }
12208
0
    if (isinstance) {
12209
0
        *out = Not;
12210
0
        return 0;
12211
0
    }
12212
0
    isinstance = PyObject_IsInstance(obj, state->UAdd_type);
12213
0
    if (isinstance == -1) {
12214
0
        return -1;
12215
0
    }
12216
0
    if (isinstance) {
12217
0
        *out = UAdd;
12218
0
        return 0;
12219
0
    }
12220
0
    isinstance = PyObject_IsInstance(obj, state->USub_type);
12221
0
    if (isinstance == -1) {
12222
0
        return -1;
12223
0
    }
12224
0
    if (isinstance) {
12225
0
        *out = USub;
12226
0
        return 0;
12227
0
    }
12228
12229
0
    PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
12230
0
    return -1;
12231
0
}
12232
12233
int
12234
obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, const
12235
              char* field, PyArena* arena)
12236
0
{
12237
0
    int isinstance;
12238
12239
0
    isinstance = PyObject_IsInstance(obj, state->Eq_type);
12240
0
    if (isinstance == -1) {
12241
0
        return -1;
12242
0
    }
12243
0
    if (isinstance) {
12244
0
        *out = Eq;
12245
0
        return 0;
12246
0
    }
12247
0
    isinstance = PyObject_IsInstance(obj, state->NotEq_type);
12248
0
    if (isinstance == -1) {
12249
0
        return -1;
12250
0
    }
12251
0
    if (isinstance) {
12252
0
        *out = NotEq;
12253
0
        return 0;
12254
0
    }
12255
0
    isinstance = PyObject_IsInstance(obj, state->Lt_type);
12256
0
    if (isinstance == -1) {
12257
0
        return -1;
12258
0
    }
12259
0
    if (isinstance) {
12260
0
        *out = Lt;
12261
0
        return 0;
12262
0
    }
12263
0
    isinstance = PyObject_IsInstance(obj, state->LtE_type);
12264
0
    if (isinstance == -1) {
12265
0
        return -1;
12266
0
    }
12267
0
    if (isinstance) {
12268
0
        *out = LtE;
12269
0
        return 0;
12270
0
    }
12271
0
    isinstance = PyObject_IsInstance(obj, state->Gt_type);
12272
0
    if (isinstance == -1) {
12273
0
        return -1;
12274
0
    }
12275
0
    if (isinstance) {
12276
0
        *out = Gt;
12277
0
        return 0;
12278
0
    }
12279
0
    isinstance = PyObject_IsInstance(obj, state->GtE_type);
12280
0
    if (isinstance == -1) {
12281
0
        return -1;
12282
0
    }
12283
0
    if (isinstance) {
12284
0
        *out = GtE;
12285
0
        return 0;
12286
0
    }
12287
0
    isinstance = PyObject_IsInstance(obj, state->Is_type);
12288
0
    if (isinstance == -1) {
12289
0
        return -1;
12290
0
    }
12291
0
    if (isinstance) {
12292
0
        *out = Is;
12293
0
        return 0;
12294
0
    }
12295
0
    isinstance = PyObject_IsInstance(obj, state->IsNot_type);
12296
0
    if (isinstance == -1) {
12297
0
        return -1;
12298
0
    }
12299
0
    if (isinstance) {
12300
0
        *out = IsNot;
12301
0
        return 0;
12302
0
    }
12303
0
    isinstance = PyObject_IsInstance(obj, state->In_type);
12304
0
    if (isinstance == -1) {
12305
0
        return -1;
12306
0
    }
12307
0
    if (isinstance) {
12308
0
        *out = In;
12309
0
        return 0;
12310
0
    }
12311
0
    isinstance = PyObject_IsInstance(obj, state->NotIn_type);
12312
0
    if (isinstance == -1) {
12313
0
        return -1;
12314
0
    }
12315
0
    if (isinstance) {
12316
0
        *out = NotIn;
12317
0
        return 0;
12318
0
    }
12319
12320
0
    PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
12321
0
    return -1;
12322
0
}
12323
12324
int
12325
obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
12326
                      out, const char* field, PyArena* arena)
12327
0
{
12328
0
    PyObject* tmp = NULL;
12329
0
    expr_ty target;
12330
0
    expr_ty iter;
12331
0
    asdl_expr_seq* ifs;
12332
0
    int is_async;
12333
12334
0
    if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
12335
0
        return -1;
12336
0
    }
12337
0
    if (tmp == NULL) {
12338
0
        PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
12339
0
        return -1;
12340
0
    }
12341
0
    else {
12342
0
        int res;
12343
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12344
0
            goto failed;
12345
0
        }
12346
0
        res = obj2ast_expr(state, tmp, &target, "target", arena);
12347
0
        _Py_LeaveRecursiveCall();
12348
0
        if (res != 0) goto failed;
12349
0
        Py_CLEAR(tmp);
12350
0
    }
12351
0
    if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
12352
0
        return -1;
12353
0
    }
12354
0
    if (tmp == NULL) {
12355
0
        PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
12356
0
        return -1;
12357
0
    }
12358
0
    else {
12359
0
        int res;
12360
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12361
0
            goto failed;
12362
0
        }
12363
0
        res = obj2ast_expr(state, tmp, &iter, "iter", arena);
12364
0
        _Py_LeaveRecursiveCall();
12365
0
        if (res != 0) goto failed;
12366
0
        Py_CLEAR(tmp);
12367
0
    }
12368
0
    if (PyObject_GetOptionalAttr(obj, state->ifs, &tmp) < 0) {
12369
0
        return -1;
12370
0
    }
12371
0
    if (tmp == NULL) {
12372
0
        tmp = PyList_New(0);
12373
0
        if (tmp == NULL) {
12374
0
            return -1;
12375
0
        }
12376
0
    }
12377
0
    {
12378
0
        int res;
12379
0
        Py_ssize_t len;
12380
0
        Py_ssize_t i;
12381
0
        if (!PyList_Check(tmp)) {
12382
0
            PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %T", tmp);
12383
0
            goto failed;
12384
0
        }
12385
0
        len = PyList_GET_SIZE(tmp);
12386
0
        ifs = _Py_asdl_expr_seq_new(len, arena);
12387
0
        if (ifs == NULL) goto failed;
12388
0
        for (i = 0; i < len; i++) {
12389
0
            expr_ty val;
12390
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12391
0
            if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12392
0
                goto failed;
12393
0
            }
12394
0
            res = obj2ast_expr(state, tmp2, &val, "ifs", arena);
12395
0
            _Py_LeaveRecursiveCall();
12396
0
            Py_DECREF(tmp2);
12397
0
            if (res != 0) goto failed;
12398
0
            if (len != PyList_GET_SIZE(tmp)) {
12399
0
                PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
12400
0
                goto failed;
12401
0
            }
12402
0
            asdl_seq_SET(ifs, i, val);
12403
0
        }
12404
0
        Py_CLEAR(tmp);
12405
0
    }
12406
0
    if (PyObject_GetOptionalAttr(obj, state->is_async, &tmp) < 0) {
12407
0
        return -1;
12408
0
    }
12409
0
    if (tmp == NULL) {
12410
0
        PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
12411
0
        return -1;
12412
0
    }
12413
0
    else {
12414
0
        int res;
12415
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12416
0
            goto failed;
12417
0
        }
12418
0
        res = obj2ast_int(state, tmp, &is_async, "is_async", arena);
12419
0
        _Py_LeaveRecursiveCall();
12420
0
        if (res != 0) goto failed;
12421
0
        Py_CLEAR(tmp);
12422
0
    }
12423
0
    *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
12424
0
    if (*out == NULL) goto failed;
12425
0
    return 0;
12426
0
failed:
12427
0
    Py_XDECREF(tmp);
12428
0
    return -1;
12429
0
}
12430
12431
int
12432
obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
12433
                      out, const char* field, PyArena* arena)
12434
0
{
12435
0
    int isinstance;
12436
12437
0
    PyObject *tmp = NULL;
12438
0
    PyObject *tp;
12439
0
    int lineno;
12440
0
    int col_offset;
12441
0
    int end_lineno;
12442
0
    int end_col_offset;
12443
12444
0
    if (obj == Py_None) {
12445
0
        *out = NULL;
12446
0
        return 0;
12447
0
    }
12448
0
    tp = state->excepthandler_type;
12449
0
    isinstance = PyObject_IsInstance(obj, tp);
12450
0
    if (isinstance == -1) {
12451
0
        return 1;
12452
0
    }
12453
0
    if (!isinstance && field != NULL) {
12454
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'excepthandler', got '%T'", field, obj);
12455
0
        return 1;
12456
0
    }
12457
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
12458
0
        return -1;
12459
0
    }
12460
0
    if (tmp == NULL) {
12461
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
12462
0
        return -1;
12463
0
    }
12464
0
    else {
12465
0
        int res;
12466
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12467
0
            goto failed;
12468
0
        }
12469
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
12470
0
        _Py_LeaveRecursiveCall();
12471
0
        if (res != 0) goto failed;
12472
0
        Py_CLEAR(tmp);
12473
0
    }
12474
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
12475
0
        return -1;
12476
0
    }
12477
0
    if (tmp == NULL) {
12478
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
12479
0
        return -1;
12480
0
    }
12481
0
    else {
12482
0
        int res;
12483
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12484
0
            goto failed;
12485
0
        }
12486
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
12487
0
        _Py_LeaveRecursiveCall();
12488
0
        if (res != 0) goto failed;
12489
0
        Py_CLEAR(tmp);
12490
0
    }
12491
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
12492
0
        return -1;
12493
0
    }
12494
0
    if (tmp == NULL || tmp == Py_None) {
12495
0
        Py_CLEAR(tmp);
12496
0
        end_lineno = lineno;
12497
0
    }
12498
0
    else {
12499
0
        int res;
12500
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12501
0
            goto failed;
12502
0
        }
12503
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
12504
0
        _Py_LeaveRecursiveCall();
12505
0
        if (res != 0) goto failed;
12506
0
        Py_CLEAR(tmp);
12507
0
    }
12508
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
12509
0
        return -1;
12510
0
    }
12511
0
    if (tmp == NULL || tmp == Py_None) {
12512
0
        Py_CLEAR(tmp);
12513
0
        end_col_offset = col_offset;
12514
0
    }
12515
0
    else {
12516
0
        int res;
12517
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12518
0
            goto failed;
12519
0
        }
12520
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
12521
0
        _Py_LeaveRecursiveCall();
12522
0
        if (res != 0) goto failed;
12523
0
        Py_CLEAR(tmp);
12524
0
    }
12525
0
    tp = state->ExceptHandler_type;
12526
0
    isinstance = PyObject_IsInstance(obj, tp);
12527
0
    if (isinstance == -1) {
12528
0
        return -1;
12529
0
    }
12530
0
    if (isinstance) {
12531
0
        expr_ty type;
12532
0
        identifier name;
12533
0
        asdl_stmt_seq* body;
12534
12535
0
        if (PyObject_GetOptionalAttr(obj, state->type, &tmp) < 0) {
12536
0
            return -1;
12537
0
        }
12538
0
        if (tmp == NULL || tmp == Py_None) {
12539
0
            Py_CLEAR(tmp);
12540
0
            type = NULL;
12541
0
        }
12542
0
        else {
12543
0
            int res;
12544
0
            if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12545
0
                goto failed;
12546
0
            }
12547
0
            res = obj2ast_expr(state, tmp, &type, "type", arena);
12548
0
            _Py_LeaveRecursiveCall();
12549
0
            if (res != 0) goto failed;
12550
0
            Py_CLEAR(tmp);
12551
0
        }
12552
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
12553
0
            return -1;
12554
0
        }
12555
0
        if (tmp == NULL || tmp == Py_None) {
12556
0
            Py_CLEAR(tmp);
12557
0
            name = NULL;
12558
0
        }
12559
0
        else {
12560
0
            int res;
12561
0
            if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12562
0
                goto failed;
12563
0
            }
12564
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
12565
0
            _Py_LeaveRecursiveCall();
12566
0
            if (res != 0) goto failed;
12567
0
            Py_CLEAR(tmp);
12568
0
        }
12569
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12570
0
            return -1;
12571
0
        }
12572
0
        if (tmp == NULL) {
12573
0
            tmp = PyList_New(0);
12574
0
            if (tmp == NULL) {
12575
0
                return -1;
12576
0
            }
12577
0
        }
12578
0
        {
12579
0
            int res;
12580
0
            Py_ssize_t len;
12581
0
            Py_ssize_t i;
12582
0
            if (!PyList_Check(tmp)) {
12583
0
                PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %T", tmp);
12584
0
                goto failed;
12585
0
            }
12586
0
            len = PyList_GET_SIZE(tmp);
12587
0
            body = _Py_asdl_stmt_seq_new(len, arena);
12588
0
            if (body == NULL) goto failed;
12589
0
            for (i = 0; i < len; i++) {
12590
0
                stmt_ty val;
12591
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12592
0
                if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12593
0
                    goto failed;
12594
0
                }
12595
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
12596
0
                _Py_LeaveRecursiveCall();
12597
0
                Py_DECREF(tmp2);
12598
0
                if (res != 0) goto failed;
12599
0
                if (len != PyList_GET_SIZE(tmp)) {
12600
0
                    PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
12601
0
                    goto failed;
12602
0
                }
12603
0
                asdl_seq_SET(body, i, val);
12604
0
            }
12605
0
            Py_CLEAR(tmp);
12606
0
        }
12607
0
        *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
12608
0
                                    end_lineno, end_col_offset, arena);
12609
0
        if (*out == NULL) goto failed;
12610
0
        return 0;
12611
0
    }
12612
12613
0
    PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
12614
0
    failed:
12615
0
    Py_XDECREF(tmp);
12616
0
    return -1;
12617
0
}
12618
12619
int
12620
obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
12621
                  const char* field, PyArena* arena)
12622
0
{
12623
0
    PyObject* tmp = NULL;
12624
0
    asdl_arg_seq* posonlyargs;
12625
0
    asdl_arg_seq* args;
12626
0
    arg_ty vararg;
12627
0
    asdl_arg_seq* kwonlyargs;
12628
0
    asdl_expr_seq* kw_defaults;
12629
0
    arg_ty kwarg;
12630
0
    asdl_expr_seq* defaults;
12631
12632
0
    if (PyObject_GetOptionalAttr(obj, state->posonlyargs, &tmp) < 0) {
12633
0
        return -1;
12634
0
    }
12635
0
    if (tmp == NULL) {
12636
0
        tmp = PyList_New(0);
12637
0
        if (tmp == NULL) {
12638
0
            return -1;
12639
0
        }
12640
0
    }
12641
0
    {
12642
0
        int res;
12643
0
        Py_ssize_t len;
12644
0
        Py_ssize_t i;
12645
0
        if (!PyList_Check(tmp)) {
12646
0
            PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %T", tmp);
12647
0
            goto failed;
12648
0
        }
12649
0
        len = PyList_GET_SIZE(tmp);
12650
0
        posonlyargs = _Py_asdl_arg_seq_new(len, arena);
12651
0
        if (posonlyargs == NULL) goto failed;
12652
0
        for (i = 0; i < len; i++) {
12653
0
            arg_ty val;
12654
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12655
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12656
0
                goto failed;
12657
0
            }
12658
0
            res = obj2ast_arg(state, tmp2, &val, "posonlyargs", arena);
12659
0
            _Py_LeaveRecursiveCall();
12660
0
            Py_DECREF(tmp2);
12661
0
            if (res != 0) goto failed;
12662
0
            if (len != PyList_GET_SIZE(tmp)) {
12663
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
12664
0
                goto failed;
12665
0
            }
12666
0
            asdl_seq_SET(posonlyargs, i, val);
12667
0
        }
12668
0
        Py_CLEAR(tmp);
12669
0
    }
12670
0
    if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
12671
0
        return -1;
12672
0
    }
12673
0
    if (tmp == NULL) {
12674
0
        tmp = PyList_New(0);
12675
0
        if (tmp == NULL) {
12676
0
            return -1;
12677
0
        }
12678
0
    }
12679
0
    {
12680
0
        int res;
12681
0
        Py_ssize_t len;
12682
0
        Py_ssize_t i;
12683
0
        if (!PyList_Check(tmp)) {
12684
0
            PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %T", tmp);
12685
0
            goto failed;
12686
0
        }
12687
0
        len = PyList_GET_SIZE(tmp);
12688
0
        args = _Py_asdl_arg_seq_new(len, arena);
12689
0
        if (args == NULL) goto failed;
12690
0
        for (i = 0; i < len; i++) {
12691
0
            arg_ty val;
12692
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12693
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12694
0
                goto failed;
12695
0
            }
12696
0
            res = obj2ast_arg(state, tmp2, &val, "args", arena);
12697
0
            _Py_LeaveRecursiveCall();
12698
0
            Py_DECREF(tmp2);
12699
0
            if (res != 0) goto failed;
12700
0
            if (len != PyList_GET_SIZE(tmp)) {
12701
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
12702
0
                goto failed;
12703
0
            }
12704
0
            asdl_seq_SET(args, i, val);
12705
0
        }
12706
0
        Py_CLEAR(tmp);
12707
0
    }
12708
0
    if (PyObject_GetOptionalAttr(obj, state->vararg, &tmp) < 0) {
12709
0
        return -1;
12710
0
    }
12711
0
    if (tmp == NULL || tmp == Py_None) {
12712
0
        Py_CLEAR(tmp);
12713
0
        vararg = NULL;
12714
0
    }
12715
0
    else {
12716
0
        int res;
12717
0
        if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12718
0
            goto failed;
12719
0
        }
12720
0
        res = obj2ast_arg(state, tmp, &vararg, "vararg", arena);
12721
0
        _Py_LeaveRecursiveCall();
12722
0
        if (res != 0) goto failed;
12723
0
        Py_CLEAR(tmp);
12724
0
    }
12725
0
    if (PyObject_GetOptionalAttr(obj, state->kwonlyargs, &tmp) < 0) {
12726
0
        return -1;
12727
0
    }
12728
0
    if (tmp == NULL) {
12729
0
        tmp = PyList_New(0);
12730
0
        if (tmp == NULL) {
12731
0
            return -1;
12732
0
        }
12733
0
    }
12734
0
    {
12735
0
        int res;
12736
0
        Py_ssize_t len;
12737
0
        Py_ssize_t i;
12738
0
        if (!PyList_Check(tmp)) {
12739
0
            PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %T", tmp);
12740
0
            goto failed;
12741
0
        }
12742
0
        len = PyList_GET_SIZE(tmp);
12743
0
        kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
12744
0
        if (kwonlyargs == NULL) goto failed;
12745
0
        for (i = 0; i < len; i++) {
12746
0
            arg_ty val;
12747
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12748
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12749
0
                goto failed;
12750
0
            }
12751
0
            res = obj2ast_arg(state, tmp2, &val, "kwonlyargs", arena);
12752
0
            _Py_LeaveRecursiveCall();
12753
0
            Py_DECREF(tmp2);
12754
0
            if (res != 0) goto failed;
12755
0
            if (len != PyList_GET_SIZE(tmp)) {
12756
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
12757
0
                goto failed;
12758
0
            }
12759
0
            asdl_seq_SET(kwonlyargs, i, val);
12760
0
        }
12761
0
        Py_CLEAR(tmp);
12762
0
    }
12763
0
    if (PyObject_GetOptionalAttr(obj, state->kw_defaults, &tmp) < 0) {
12764
0
        return -1;
12765
0
    }
12766
0
    if (tmp == NULL) {
12767
0
        tmp = PyList_New(0);
12768
0
        if (tmp == NULL) {
12769
0
            return -1;
12770
0
        }
12771
0
    }
12772
0
    {
12773
0
        int res;
12774
0
        Py_ssize_t len;
12775
0
        Py_ssize_t i;
12776
0
        if (!PyList_Check(tmp)) {
12777
0
            PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %T", tmp);
12778
0
            goto failed;
12779
0
        }
12780
0
        len = PyList_GET_SIZE(tmp);
12781
0
        kw_defaults = _Py_asdl_expr_seq_new(len, arena);
12782
0
        if (kw_defaults == NULL) goto failed;
12783
0
        for (i = 0; i < len; i++) {
12784
0
            expr_ty val;
12785
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12786
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12787
0
                goto failed;
12788
0
            }
12789
0
            res = obj2ast_expr(state, tmp2, &val, "kw_defaults", arena);
12790
0
            _Py_LeaveRecursiveCall();
12791
0
            Py_DECREF(tmp2);
12792
0
            if (res != 0) goto failed;
12793
0
            if (len != PyList_GET_SIZE(tmp)) {
12794
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
12795
0
                goto failed;
12796
0
            }
12797
0
            asdl_seq_SET(kw_defaults, i, val);
12798
0
        }
12799
0
        Py_CLEAR(tmp);
12800
0
    }
12801
0
    if (PyObject_GetOptionalAttr(obj, state->kwarg, &tmp) < 0) {
12802
0
        return -1;
12803
0
    }
12804
0
    if (tmp == NULL || tmp == Py_None) {
12805
0
        Py_CLEAR(tmp);
12806
0
        kwarg = NULL;
12807
0
    }
12808
0
    else {
12809
0
        int res;
12810
0
        if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12811
0
            goto failed;
12812
0
        }
12813
0
        res = obj2ast_arg(state, tmp, &kwarg, "kwarg", arena);
12814
0
        _Py_LeaveRecursiveCall();
12815
0
        if (res != 0) goto failed;
12816
0
        Py_CLEAR(tmp);
12817
0
    }
12818
0
    if (PyObject_GetOptionalAttr(obj, state->defaults, &tmp) < 0) {
12819
0
        return -1;
12820
0
    }
12821
0
    if (tmp == NULL) {
12822
0
        tmp = PyList_New(0);
12823
0
        if (tmp == NULL) {
12824
0
            return -1;
12825
0
        }
12826
0
    }
12827
0
    {
12828
0
        int res;
12829
0
        Py_ssize_t len;
12830
0
        Py_ssize_t i;
12831
0
        if (!PyList_Check(tmp)) {
12832
0
            PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %T", tmp);
12833
0
            goto failed;
12834
0
        }
12835
0
        len = PyList_GET_SIZE(tmp);
12836
0
        defaults = _Py_asdl_expr_seq_new(len, arena);
12837
0
        if (defaults == NULL) goto failed;
12838
0
        for (i = 0; i < len; i++) {
12839
0
            expr_ty val;
12840
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12841
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12842
0
                goto failed;
12843
0
            }
12844
0
            res = obj2ast_expr(state, tmp2, &val, "defaults", arena);
12845
0
            _Py_LeaveRecursiveCall();
12846
0
            Py_DECREF(tmp2);
12847
0
            if (res != 0) goto failed;
12848
0
            if (len != PyList_GET_SIZE(tmp)) {
12849
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
12850
0
                goto failed;
12851
0
            }
12852
0
            asdl_seq_SET(defaults, i, val);
12853
0
        }
12854
0
        Py_CLEAR(tmp);
12855
0
    }
12856
0
    *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
12857
0
                            kwarg, defaults, arena);
12858
0
    if (*out == NULL) goto failed;
12859
0
    return 0;
12860
0
failed:
12861
0
    Py_XDECREF(tmp);
12862
0
    return -1;
12863
0
}
12864
12865
int
12866
obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, const char*
12867
            field, PyArena* arena)
12868
0
{
12869
0
    PyObject* tmp = NULL;
12870
0
    identifier arg;
12871
0
    expr_ty annotation;
12872
0
    string type_comment;
12873
0
    int lineno;
12874
0
    int col_offset;
12875
0
    int end_lineno;
12876
0
    int end_col_offset;
12877
12878
0
    if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
12879
0
        return -1;
12880
0
    }
12881
0
    if (tmp == NULL) {
12882
0
        PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
12883
0
        return -1;
12884
0
    }
12885
0
    else {
12886
0
        int res;
12887
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12888
0
            goto failed;
12889
0
        }
12890
0
        res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
12891
0
        _Py_LeaveRecursiveCall();
12892
0
        if (res != 0) goto failed;
12893
0
        Py_CLEAR(tmp);
12894
0
    }
12895
0
    if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
12896
0
        return -1;
12897
0
    }
12898
0
    if (tmp == NULL || tmp == Py_None) {
12899
0
        Py_CLEAR(tmp);
12900
0
        annotation = NULL;
12901
0
    }
12902
0
    else {
12903
0
        int res;
12904
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12905
0
            goto failed;
12906
0
        }
12907
0
        res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
12908
0
        _Py_LeaveRecursiveCall();
12909
0
        if (res != 0) goto failed;
12910
0
        Py_CLEAR(tmp);
12911
0
    }
12912
0
    if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
12913
0
        return -1;
12914
0
    }
12915
0
    if (tmp == NULL || tmp == Py_None) {
12916
0
        Py_CLEAR(tmp);
12917
0
        type_comment = NULL;
12918
0
    }
12919
0
    else {
12920
0
        int res;
12921
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12922
0
            goto failed;
12923
0
        }
12924
0
        res = obj2ast_string(state, tmp, &type_comment, "type_comment", arena);
12925
0
        _Py_LeaveRecursiveCall();
12926
0
        if (res != 0) goto failed;
12927
0
        Py_CLEAR(tmp);
12928
0
    }
12929
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
12930
0
        return -1;
12931
0
    }
12932
0
    if (tmp == NULL) {
12933
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
12934
0
        return -1;
12935
0
    }
12936
0
    else {
12937
0
        int res;
12938
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12939
0
            goto failed;
12940
0
        }
12941
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
12942
0
        _Py_LeaveRecursiveCall();
12943
0
        if (res != 0) goto failed;
12944
0
        Py_CLEAR(tmp);
12945
0
    }
12946
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
12947
0
        return -1;
12948
0
    }
12949
0
    if (tmp == NULL) {
12950
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
12951
0
        return -1;
12952
0
    }
12953
0
    else {
12954
0
        int res;
12955
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12956
0
            goto failed;
12957
0
        }
12958
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
12959
0
        _Py_LeaveRecursiveCall();
12960
0
        if (res != 0) goto failed;
12961
0
        Py_CLEAR(tmp);
12962
0
    }
12963
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
12964
0
        return -1;
12965
0
    }
12966
0
    if (tmp == NULL || tmp == Py_None) {
12967
0
        Py_CLEAR(tmp);
12968
0
        end_lineno = lineno;
12969
0
    }
12970
0
    else {
12971
0
        int res;
12972
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12973
0
            goto failed;
12974
0
        }
12975
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
12976
0
        _Py_LeaveRecursiveCall();
12977
0
        if (res != 0) goto failed;
12978
0
        Py_CLEAR(tmp);
12979
0
    }
12980
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
12981
0
        return -1;
12982
0
    }
12983
0
    if (tmp == NULL || tmp == Py_None) {
12984
0
        Py_CLEAR(tmp);
12985
0
        end_col_offset = col_offset;
12986
0
    }
12987
0
    else {
12988
0
        int res;
12989
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12990
0
            goto failed;
12991
0
        }
12992
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
12993
0
        _Py_LeaveRecursiveCall();
12994
0
        if (res != 0) goto failed;
12995
0
        Py_CLEAR(tmp);
12996
0
    }
12997
0
    *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
12998
0
                      end_lineno, end_col_offset, arena);
12999
0
    if (*out == NULL) goto failed;
13000
0
    return 0;
13001
0
failed:
13002
0
    Py_XDECREF(tmp);
13003
0
    return -1;
13004
0
}
13005
13006
int
13007
obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out, const
13008
                char* field, PyArena* arena)
13009
0
{
13010
0
    PyObject* tmp = NULL;
13011
0
    identifier arg;
13012
0
    expr_ty value;
13013
0
    int lineno;
13014
0
    int col_offset;
13015
0
    int end_lineno;
13016
0
    int end_col_offset;
13017
13018
0
    if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
13019
0
        return -1;
13020
0
    }
13021
0
    if (tmp == NULL || tmp == Py_None) {
13022
0
        Py_CLEAR(tmp);
13023
0
        arg = NULL;
13024
0
    }
13025
0
    else {
13026
0
        int res;
13027
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13028
0
            goto failed;
13029
0
        }
13030
0
        res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
13031
0
        _Py_LeaveRecursiveCall();
13032
0
        if (res != 0) goto failed;
13033
0
        Py_CLEAR(tmp);
13034
0
    }
13035
0
    if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13036
0
        return -1;
13037
0
    }
13038
0
    if (tmp == NULL) {
13039
0
        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
13040
0
        return -1;
13041
0
    }
13042
0
    else {
13043
0
        int res;
13044
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13045
0
            goto failed;
13046
0
        }
13047
0
        res = obj2ast_expr(state, tmp, &value, "value", arena);
13048
0
        _Py_LeaveRecursiveCall();
13049
0
        if (res != 0) goto failed;
13050
0
        Py_CLEAR(tmp);
13051
0
    }
13052
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13053
0
        return -1;
13054
0
    }
13055
0
    if (tmp == NULL) {
13056
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
13057
0
        return -1;
13058
0
    }
13059
0
    else {
13060
0
        int res;
13061
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13062
0
            goto failed;
13063
0
        }
13064
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13065
0
        _Py_LeaveRecursiveCall();
13066
0
        if (res != 0) goto failed;
13067
0
        Py_CLEAR(tmp);
13068
0
    }
13069
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13070
0
        return -1;
13071
0
    }
13072
0
    if (tmp == NULL) {
13073
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
13074
0
        return -1;
13075
0
    }
13076
0
    else {
13077
0
        int res;
13078
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13079
0
            goto failed;
13080
0
        }
13081
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13082
0
        _Py_LeaveRecursiveCall();
13083
0
        if (res != 0) goto failed;
13084
0
        Py_CLEAR(tmp);
13085
0
    }
13086
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13087
0
        return -1;
13088
0
    }
13089
0
    if (tmp == NULL || tmp == Py_None) {
13090
0
        Py_CLEAR(tmp);
13091
0
        end_lineno = lineno;
13092
0
    }
13093
0
    else {
13094
0
        int res;
13095
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13096
0
            goto failed;
13097
0
        }
13098
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13099
0
        _Py_LeaveRecursiveCall();
13100
0
        if (res != 0) goto failed;
13101
0
        Py_CLEAR(tmp);
13102
0
    }
13103
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13104
0
        return -1;
13105
0
    }
13106
0
    if (tmp == NULL || tmp == Py_None) {
13107
0
        Py_CLEAR(tmp);
13108
0
        end_col_offset = col_offset;
13109
0
    }
13110
0
    else {
13111
0
        int res;
13112
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13113
0
            goto failed;
13114
0
        }
13115
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13116
0
        _Py_LeaveRecursiveCall();
13117
0
        if (res != 0) goto failed;
13118
0
        Py_CLEAR(tmp);
13119
0
    }
13120
0
    *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
13121
0
                          end_col_offset, arena);
13122
0
    if (*out == NULL) goto failed;
13123
0
    return 0;
13124
0
failed:
13125
0
    Py_XDECREF(tmp);
13126
0
    return -1;
13127
0
}
13128
13129
int
13130
obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, const
13131
              char* field, PyArena* arena)
13132
0
{
13133
0
    PyObject* tmp = NULL;
13134
0
    identifier name;
13135
0
    identifier asname;
13136
0
    int lineno;
13137
0
    int col_offset;
13138
0
    int end_lineno;
13139
0
    int end_col_offset;
13140
13141
0
    if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13142
0
        return -1;
13143
0
    }
13144
0
    if (tmp == NULL) {
13145
0
        PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
13146
0
        return -1;
13147
0
    }
13148
0
    else {
13149
0
        int res;
13150
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13151
0
            goto failed;
13152
0
        }
13153
0
        res = obj2ast_identifier(state, tmp, &name, "name", arena);
13154
0
        _Py_LeaveRecursiveCall();
13155
0
        if (res != 0) goto failed;
13156
0
        Py_CLEAR(tmp);
13157
0
    }
13158
0
    if (PyObject_GetOptionalAttr(obj, state->asname, &tmp) < 0) {
13159
0
        return -1;
13160
0
    }
13161
0
    if (tmp == NULL || tmp == Py_None) {
13162
0
        Py_CLEAR(tmp);
13163
0
        asname = NULL;
13164
0
    }
13165
0
    else {
13166
0
        int res;
13167
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13168
0
            goto failed;
13169
0
        }
13170
0
        res = obj2ast_identifier(state, tmp, &asname, "asname", arena);
13171
0
        _Py_LeaveRecursiveCall();
13172
0
        if (res != 0) goto failed;
13173
0
        Py_CLEAR(tmp);
13174
0
    }
13175
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13176
0
        return -1;
13177
0
    }
13178
0
    if (tmp == NULL) {
13179
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
13180
0
        return -1;
13181
0
    }
13182
0
    else {
13183
0
        int res;
13184
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13185
0
            goto failed;
13186
0
        }
13187
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13188
0
        _Py_LeaveRecursiveCall();
13189
0
        if (res != 0) goto failed;
13190
0
        Py_CLEAR(tmp);
13191
0
    }
13192
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13193
0
        return -1;
13194
0
    }
13195
0
    if (tmp == NULL) {
13196
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
13197
0
        return -1;
13198
0
    }
13199
0
    else {
13200
0
        int res;
13201
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13202
0
            goto failed;
13203
0
        }
13204
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13205
0
        _Py_LeaveRecursiveCall();
13206
0
        if (res != 0) goto failed;
13207
0
        Py_CLEAR(tmp);
13208
0
    }
13209
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13210
0
        return -1;
13211
0
    }
13212
0
    if (tmp == NULL || tmp == Py_None) {
13213
0
        Py_CLEAR(tmp);
13214
0
        end_lineno = lineno;
13215
0
    }
13216
0
    else {
13217
0
        int res;
13218
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13219
0
            goto failed;
13220
0
        }
13221
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13222
0
        _Py_LeaveRecursiveCall();
13223
0
        if (res != 0) goto failed;
13224
0
        Py_CLEAR(tmp);
13225
0
    }
13226
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13227
0
        return -1;
13228
0
    }
13229
0
    if (tmp == NULL || tmp == Py_None) {
13230
0
        Py_CLEAR(tmp);
13231
0
        end_col_offset = col_offset;
13232
0
    }
13233
0
    else {
13234
0
        int res;
13235
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13236
0
            goto failed;
13237
0
        }
13238
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13239
0
        _Py_LeaveRecursiveCall();
13240
0
        if (res != 0) goto failed;
13241
0
        Py_CLEAR(tmp);
13242
0
    }
13243
0
    *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
13244
0
                        end_col_offset, arena);
13245
0
    if (*out == NULL) goto failed;
13246
0
    return 0;
13247
0
failed:
13248
0
    Py_XDECREF(tmp);
13249
0
    return -1;
13250
0
}
13251
13252
int
13253
obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
13254
                 const char* field, PyArena* arena)
13255
0
{
13256
0
    PyObject* tmp = NULL;
13257
0
    expr_ty context_expr;
13258
0
    expr_ty optional_vars;
13259
13260
0
    if (PyObject_GetOptionalAttr(obj, state->context_expr, &tmp) < 0) {
13261
0
        return -1;
13262
0
    }
13263
0
    if (tmp == NULL) {
13264
0
        PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
13265
0
        return -1;
13266
0
    }
13267
0
    else {
13268
0
        int res;
13269
0
        if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
13270
0
            goto failed;
13271
0
        }
13272
0
        res = obj2ast_expr(state, tmp, &context_expr, "context_expr", arena);
13273
0
        _Py_LeaveRecursiveCall();
13274
0
        if (res != 0) goto failed;
13275
0
        Py_CLEAR(tmp);
13276
0
    }
13277
0
    if (PyObject_GetOptionalAttr(obj, state->optional_vars, &tmp) < 0) {
13278
0
        return -1;
13279
0
    }
13280
0
    if (tmp == NULL || tmp == Py_None) {
13281
0
        Py_CLEAR(tmp);
13282
0
        optional_vars = NULL;
13283
0
    }
13284
0
    else {
13285
0
        int res;
13286
0
        if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
13287
0
            goto failed;
13288
0
        }
13289
0
        res = obj2ast_expr(state, tmp, &optional_vars, "optional_vars", arena);
13290
0
        _Py_LeaveRecursiveCall();
13291
0
        if (res != 0) goto failed;
13292
0
        Py_CLEAR(tmp);
13293
0
    }
13294
0
    *out = _PyAST_withitem(context_expr, optional_vars, arena);
13295
0
    if (*out == NULL) goto failed;
13296
0
    return 0;
13297
0
failed:
13298
0
    Py_XDECREF(tmp);
13299
0
    return -1;
13300
0
}
13301
13302
int
13303
obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
13304
                   const char* field, PyArena* arena)
13305
0
{
13306
0
    PyObject* tmp = NULL;
13307
0
    pattern_ty pattern;
13308
0
    expr_ty guard;
13309
0
    asdl_stmt_seq* body;
13310
13311
0
    if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
13312
0
        return -1;
13313
0
    }
13314
0
    if (tmp == NULL) {
13315
0
        PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
13316
0
        return -1;
13317
0
    }
13318
0
    else {
13319
0
        int res;
13320
0
        if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13321
0
            goto failed;
13322
0
        }
13323
0
        res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
13324
0
        _Py_LeaveRecursiveCall();
13325
0
        if (res != 0) goto failed;
13326
0
        Py_CLEAR(tmp);
13327
0
    }
13328
0
    if (PyObject_GetOptionalAttr(obj, state->guard, &tmp) < 0) {
13329
0
        return -1;
13330
0
    }
13331
0
    if (tmp == NULL || tmp == Py_None) {
13332
0
        Py_CLEAR(tmp);
13333
0
        guard = NULL;
13334
0
    }
13335
0
    else {
13336
0
        int res;
13337
0
        if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13338
0
            goto failed;
13339
0
        }
13340
0
        res = obj2ast_expr(state, tmp, &guard, "guard", arena);
13341
0
        _Py_LeaveRecursiveCall();
13342
0
        if (res != 0) goto failed;
13343
0
        Py_CLEAR(tmp);
13344
0
    }
13345
0
    if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
13346
0
        return -1;
13347
0
    }
13348
0
    if (tmp == NULL) {
13349
0
        tmp = PyList_New(0);
13350
0
        if (tmp == NULL) {
13351
0
            return -1;
13352
0
        }
13353
0
    }
13354
0
    {
13355
0
        int res;
13356
0
        Py_ssize_t len;
13357
0
        Py_ssize_t i;
13358
0
        if (!PyList_Check(tmp)) {
13359
0
            PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %T", tmp);
13360
0
            goto failed;
13361
0
        }
13362
0
        len = PyList_GET_SIZE(tmp);
13363
0
        body = _Py_asdl_stmt_seq_new(len, arena);
13364
0
        if (body == NULL) goto failed;
13365
0
        for (i = 0; i < len; i++) {
13366
0
            stmt_ty val;
13367
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13368
0
            if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13369
0
                goto failed;
13370
0
            }
13371
0
            res = obj2ast_stmt(state, tmp2, &val, "body", arena);
13372
0
            _Py_LeaveRecursiveCall();
13373
0
            Py_DECREF(tmp2);
13374
0
            if (res != 0) goto failed;
13375
0
            if (len != PyList_GET_SIZE(tmp)) {
13376
0
                PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
13377
0
                goto failed;
13378
0
            }
13379
0
            asdl_seq_SET(body, i, val);
13380
0
        }
13381
0
        Py_CLEAR(tmp);
13382
0
    }
13383
0
    *out = _PyAST_match_case(pattern, guard, body, arena);
13384
0
    if (*out == NULL) goto failed;
13385
0
    return 0;
13386
0
failed:
13387
0
    Py_XDECREF(tmp);
13388
0
    return -1;
13389
0
}
13390
13391
int
13392
obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out, const
13393
                char* field, PyArena* arena)
13394
0
{
13395
0
    int isinstance;
13396
13397
0
    PyObject *tmp = NULL;
13398
0
    PyObject *tp;
13399
0
    int lineno;
13400
0
    int col_offset;
13401
0
    int end_lineno;
13402
0
    int end_col_offset;
13403
13404
0
    if (obj == Py_None) {
13405
0
        *out = NULL;
13406
0
        return 0;
13407
0
    }
13408
0
    tp = state->pattern_type;
13409
0
    isinstance = PyObject_IsInstance(obj, tp);
13410
0
    if (isinstance == -1) {
13411
0
        return 1;
13412
0
    }
13413
0
    if (!isinstance && field != NULL) {
13414
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'pattern', got '%T'", field, obj);
13415
0
        return 1;
13416
0
    }
13417
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13418
0
        return -1;
13419
0
    }
13420
0
    if (tmp == NULL) {
13421
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
13422
0
        return -1;
13423
0
    }
13424
0
    else {
13425
0
        int res;
13426
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13427
0
            goto failed;
13428
0
        }
13429
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13430
0
        _Py_LeaveRecursiveCall();
13431
0
        if (res != 0) goto failed;
13432
0
        Py_CLEAR(tmp);
13433
0
    }
13434
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13435
0
        return -1;
13436
0
    }
13437
0
    if (tmp == NULL) {
13438
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
13439
0
        return -1;
13440
0
    }
13441
0
    else {
13442
0
        int res;
13443
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13444
0
            goto failed;
13445
0
        }
13446
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13447
0
        _Py_LeaveRecursiveCall();
13448
0
        if (res != 0) goto failed;
13449
0
        Py_CLEAR(tmp);
13450
0
    }
13451
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13452
0
        return -1;
13453
0
    }
13454
0
    if (tmp == NULL) {
13455
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
13456
0
        return -1;
13457
0
    }
13458
0
    else {
13459
0
        int res;
13460
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13461
0
            goto failed;
13462
0
        }
13463
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13464
0
        _Py_LeaveRecursiveCall();
13465
0
        if (res != 0) goto failed;
13466
0
        Py_CLEAR(tmp);
13467
0
    }
13468
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13469
0
        return -1;
13470
0
    }
13471
0
    if (tmp == NULL) {
13472
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
13473
0
        return -1;
13474
0
    }
13475
0
    else {
13476
0
        int res;
13477
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13478
0
            goto failed;
13479
0
        }
13480
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13481
0
        _Py_LeaveRecursiveCall();
13482
0
        if (res != 0) goto failed;
13483
0
        Py_CLEAR(tmp);
13484
0
    }
13485
0
    tp = state->MatchValue_type;
13486
0
    isinstance = PyObject_IsInstance(obj, tp);
13487
0
    if (isinstance == -1) {
13488
0
        return -1;
13489
0
    }
13490
0
    if (isinstance) {
13491
0
        expr_ty value;
13492
13493
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13494
0
            return -1;
13495
0
        }
13496
0
        if (tmp == NULL) {
13497
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
13498
0
            return -1;
13499
0
        }
13500
0
        else {
13501
0
            int res;
13502
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
13503
0
                goto failed;
13504
0
            }
13505
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
13506
0
            _Py_LeaveRecursiveCall();
13507
0
            if (res != 0) goto failed;
13508
0
            Py_CLEAR(tmp);
13509
0
        }
13510
0
        *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
13511
0
                                 end_col_offset, arena);
13512
0
        if (*out == NULL) goto failed;
13513
0
        return 0;
13514
0
    }
13515
0
    tp = state->MatchSingleton_type;
13516
0
    isinstance = PyObject_IsInstance(obj, tp);
13517
0
    if (isinstance == -1) {
13518
0
        return -1;
13519
0
    }
13520
0
    if (isinstance) {
13521
0
        constant value;
13522
13523
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13524
0
            return -1;
13525
0
        }
13526
0
        if (tmp == NULL) {
13527
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
13528
0
            return -1;
13529
0
        }
13530
0
        else {
13531
0
            int res;
13532
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
13533
0
                goto failed;
13534
0
            }
13535
0
            res = obj2ast_constant(state, tmp, &value, "value", arena);
13536
0
            _Py_LeaveRecursiveCall();
13537
0
            if (res != 0) goto failed;
13538
0
            Py_CLEAR(tmp);
13539
0
        }
13540
0
        *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
13541
0
                                     end_col_offset, arena);
13542
0
        if (*out == NULL) goto failed;
13543
0
        return 0;
13544
0
    }
13545
0
    tp = state->MatchSequence_type;
13546
0
    isinstance = PyObject_IsInstance(obj, tp);
13547
0
    if (isinstance == -1) {
13548
0
        return -1;
13549
0
    }
13550
0
    if (isinstance) {
13551
0
        asdl_pattern_seq* patterns;
13552
13553
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13554
0
            return -1;
13555
0
        }
13556
0
        if (tmp == NULL) {
13557
0
            tmp = PyList_New(0);
13558
0
            if (tmp == NULL) {
13559
0
                return -1;
13560
0
            }
13561
0
        }
13562
0
        {
13563
0
            int res;
13564
0
            Py_ssize_t len;
13565
0
            Py_ssize_t i;
13566
0
            if (!PyList_Check(tmp)) {
13567
0
                PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %T", tmp);
13568
0
                goto failed;
13569
0
            }
13570
0
            len = PyList_GET_SIZE(tmp);
13571
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13572
0
            if (patterns == NULL) goto failed;
13573
0
            for (i = 0; i < len; i++) {
13574
0
                pattern_ty val;
13575
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13576
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
13577
0
                    goto failed;
13578
0
                }
13579
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13580
0
                _Py_LeaveRecursiveCall();
13581
0
                Py_DECREF(tmp2);
13582
0
                if (res != 0) goto failed;
13583
0
                if (len != PyList_GET_SIZE(tmp)) {
13584
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
13585
0
                    goto failed;
13586
0
                }
13587
0
                asdl_seq_SET(patterns, i, val);
13588
0
            }
13589
0
            Py_CLEAR(tmp);
13590
0
        }
13591
0
        *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
13592
0
                                    end_col_offset, arena);
13593
0
        if (*out == NULL) goto failed;
13594
0
        return 0;
13595
0
    }
13596
0
    tp = state->MatchMapping_type;
13597
0
    isinstance = PyObject_IsInstance(obj, tp);
13598
0
    if (isinstance == -1) {
13599
0
        return -1;
13600
0
    }
13601
0
    if (isinstance) {
13602
0
        asdl_expr_seq* keys;
13603
0
        asdl_pattern_seq* patterns;
13604
0
        identifier rest;
13605
13606
0
        if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
13607
0
            return -1;
13608
0
        }
13609
0
        if (tmp == NULL) {
13610
0
            tmp = PyList_New(0);
13611
0
            if (tmp == NULL) {
13612
0
                return -1;
13613
0
            }
13614
0
        }
13615
0
        {
13616
0
            int res;
13617
0
            Py_ssize_t len;
13618
0
            Py_ssize_t i;
13619
0
            if (!PyList_Check(tmp)) {
13620
0
                PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %T", tmp);
13621
0
                goto failed;
13622
0
            }
13623
0
            len = PyList_GET_SIZE(tmp);
13624
0
            keys = _Py_asdl_expr_seq_new(len, arena);
13625
0
            if (keys == NULL) goto failed;
13626
0
            for (i = 0; i < len; i++) {
13627
0
                expr_ty val;
13628
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13629
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13630
0
                    goto failed;
13631
0
                }
13632
0
                res = obj2ast_expr(state, tmp2, &val, "keys", arena);
13633
0
                _Py_LeaveRecursiveCall();
13634
0
                Py_DECREF(tmp2);
13635
0
                if (res != 0) goto failed;
13636
0
                if (len != PyList_GET_SIZE(tmp)) {
13637
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
13638
0
                    goto failed;
13639
0
                }
13640
0
                asdl_seq_SET(keys, i, val);
13641
0
            }
13642
0
            Py_CLEAR(tmp);
13643
0
        }
13644
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13645
0
            return -1;
13646
0
        }
13647
0
        if (tmp == NULL) {
13648
0
            tmp = PyList_New(0);
13649
0
            if (tmp == NULL) {
13650
0
                return -1;
13651
0
            }
13652
0
        }
13653
0
        {
13654
0
            int res;
13655
0
            Py_ssize_t len;
13656
0
            Py_ssize_t i;
13657
0
            if (!PyList_Check(tmp)) {
13658
0
                PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %T", tmp);
13659
0
                goto failed;
13660
0
            }
13661
0
            len = PyList_GET_SIZE(tmp);
13662
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13663
0
            if (patterns == NULL) goto failed;
13664
0
            for (i = 0; i < len; i++) {
13665
0
                pattern_ty val;
13666
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13667
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13668
0
                    goto failed;
13669
0
                }
13670
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13671
0
                _Py_LeaveRecursiveCall();
13672
0
                Py_DECREF(tmp2);
13673
0
                if (res != 0) goto failed;
13674
0
                if (len != PyList_GET_SIZE(tmp)) {
13675
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
13676
0
                    goto failed;
13677
0
                }
13678
0
                asdl_seq_SET(patterns, i, val);
13679
0
            }
13680
0
            Py_CLEAR(tmp);
13681
0
        }
13682
0
        if (PyObject_GetOptionalAttr(obj, state->rest, &tmp) < 0) {
13683
0
            return -1;
13684
0
        }
13685
0
        if (tmp == NULL || tmp == Py_None) {
13686
0
            Py_CLEAR(tmp);
13687
0
            rest = NULL;
13688
0
        }
13689
0
        else {
13690
0
            int res;
13691
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13692
0
                goto failed;
13693
0
            }
13694
0
            res = obj2ast_identifier(state, tmp, &rest, "rest", arena);
13695
0
            _Py_LeaveRecursiveCall();
13696
0
            if (res != 0) goto failed;
13697
0
            Py_CLEAR(tmp);
13698
0
        }
13699
0
        *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
13700
0
                                   end_lineno, end_col_offset, arena);
13701
0
        if (*out == NULL) goto failed;
13702
0
        return 0;
13703
0
    }
13704
0
    tp = state->MatchClass_type;
13705
0
    isinstance = PyObject_IsInstance(obj, tp);
13706
0
    if (isinstance == -1) {
13707
0
        return -1;
13708
0
    }
13709
0
    if (isinstance) {
13710
0
        expr_ty cls;
13711
0
        asdl_pattern_seq* patterns;
13712
0
        asdl_identifier_seq* kwd_attrs;
13713
0
        asdl_pattern_seq* kwd_patterns;
13714
13715
0
        if (PyObject_GetOptionalAttr(obj, state->cls, &tmp) < 0) {
13716
0
            return -1;
13717
0
        }
13718
0
        if (tmp == NULL) {
13719
0
            PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
13720
0
            return -1;
13721
0
        }
13722
0
        else {
13723
0
            int res;
13724
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13725
0
                goto failed;
13726
0
            }
13727
0
            res = obj2ast_expr(state, tmp, &cls, "cls", arena);
13728
0
            _Py_LeaveRecursiveCall();
13729
0
            if (res != 0) goto failed;
13730
0
            Py_CLEAR(tmp);
13731
0
        }
13732
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13733
0
            return -1;
13734
0
        }
13735
0
        if (tmp == NULL) {
13736
0
            tmp = PyList_New(0);
13737
0
            if (tmp == NULL) {
13738
0
                return -1;
13739
0
            }
13740
0
        }
13741
0
        {
13742
0
            int res;
13743
0
            Py_ssize_t len;
13744
0
            Py_ssize_t i;
13745
0
            if (!PyList_Check(tmp)) {
13746
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %T", tmp);
13747
0
                goto failed;
13748
0
            }
13749
0
            len = PyList_GET_SIZE(tmp);
13750
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13751
0
            if (patterns == NULL) goto failed;
13752
0
            for (i = 0; i < len; i++) {
13753
0
                pattern_ty val;
13754
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13755
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13756
0
                    goto failed;
13757
0
                }
13758
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13759
0
                _Py_LeaveRecursiveCall();
13760
0
                Py_DECREF(tmp2);
13761
0
                if (res != 0) goto failed;
13762
0
                if (len != PyList_GET_SIZE(tmp)) {
13763
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
13764
0
                    goto failed;
13765
0
                }
13766
0
                asdl_seq_SET(patterns, i, val);
13767
0
            }
13768
0
            Py_CLEAR(tmp);
13769
0
        }
13770
0
        if (PyObject_GetOptionalAttr(obj, state->kwd_attrs, &tmp) < 0) {
13771
0
            return -1;
13772
0
        }
13773
0
        if (tmp == NULL) {
13774
0
            tmp = PyList_New(0);
13775
0
            if (tmp == NULL) {
13776
0
                return -1;
13777
0
            }
13778
0
        }
13779
0
        {
13780
0
            int res;
13781
0
            Py_ssize_t len;
13782
0
            Py_ssize_t i;
13783
0
            if (!PyList_Check(tmp)) {
13784
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %T", tmp);
13785
0
                goto failed;
13786
0
            }
13787
0
            len = PyList_GET_SIZE(tmp);
13788
0
            kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
13789
0
            if (kwd_attrs == NULL) goto failed;
13790
0
            for (i = 0; i < len; i++) {
13791
0
                identifier val;
13792
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13793
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13794
0
                    goto failed;
13795
0
                }
13796
0
                res = obj2ast_identifier(state, tmp2, &val, "kwd_attrs", arena);
13797
0
                _Py_LeaveRecursiveCall();
13798
0
                Py_DECREF(tmp2);
13799
0
                if (res != 0) goto failed;
13800
0
                if (len != PyList_GET_SIZE(tmp)) {
13801
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
13802
0
                    goto failed;
13803
0
                }
13804
0
                asdl_seq_SET(kwd_attrs, i, val);
13805
0
            }
13806
0
            Py_CLEAR(tmp);
13807
0
        }
13808
0
        if (PyObject_GetOptionalAttr(obj, state->kwd_patterns, &tmp) < 0) {
13809
0
            return -1;
13810
0
        }
13811
0
        if (tmp == NULL) {
13812
0
            tmp = PyList_New(0);
13813
0
            if (tmp == NULL) {
13814
0
                return -1;
13815
0
            }
13816
0
        }
13817
0
        {
13818
0
            int res;
13819
0
            Py_ssize_t len;
13820
0
            Py_ssize_t i;
13821
0
            if (!PyList_Check(tmp)) {
13822
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %T", tmp);
13823
0
                goto failed;
13824
0
            }
13825
0
            len = PyList_GET_SIZE(tmp);
13826
0
            kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
13827
0
            if (kwd_patterns == NULL) goto failed;
13828
0
            for (i = 0; i < len; i++) {
13829
0
                pattern_ty val;
13830
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13831
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13832
0
                    goto failed;
13833
0
                }
13834
0
                res = obj2ast_pattern(state, tmp2, &val, "kwd_patterns", arena);
13835
0
                _Py_LeaveRecursiveCall();
13836
0
                Py_DECREF(tmp2);
13837
0
                if (res != 0) goto failed;
13838
0
                if (len != PyList_GET_SIZE(tmp)) {
13839
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
13840
0
                    goto failed;
13841
0
                }
13842
0
                asdl_seq_SET(kwd_patterns, i, val);
13843
0
            }
13844
0
            Py_CLEAR(tmp);
13845
0
        }
13846
0
        *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
13847
0
                                 lineno, col_offset, end_lineno,
13848
0
                                 end_col_offset, arena);
13849
0
        if (*out == NULL) goto failed;
13850
0
        return 0;
13851
0
    }
13852
0
    tp = state->MatchStar_type;
13853
0
    isinstance = PyObject_IsInstance(obj, tp);
13854
0
    if (isinstance == -1) {
13855
0
        return -1;
13856
0
    }
13857
0
    if (isinstance) {
13858
0
        identifier name;
13859
13860
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13861
0
            return -1;
13862
0
        }
13863
0
        if (tmp == NULL || tmp == Py_None) {
13864
0
            Py_CLEAR(tmp);
13865
0
            name = NULL;
13866
0
        }
13867
0
        else {
13868
0
            int res;
13869
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
13870
0
                goto failed;
13871
0
            }
13872
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
13873
0
            _Py_LeaveRecursiveCall();
13874
0
            if (res != 0) goto failed;
13875
0
            Py_CLEAR(tmp);
13876
0
        }
13877
0
        *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
13878
0
                                end_col_offset, arena);
13879
0
        if (*out == NULL) goto failed;
13880
0
        return 0;
13881
0
    }
13882
0
    tp = state->MatchAs_type;
13883
0
    isinstance = PyObject_IsInstance(obj, tp);
13884
0
    if (isinstance == -1) {
13885
0
        return -1;
13886
0
    }
13887
0
    if (isinstance) {
13888
0
        pattern_ty pattern;
13889
0
        identifier name;
13890
13891
0
        if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
13892
0
            return -1;
13893
0
        }
13894
0
        if (tmp == NULL || tmp == Py_None) {
13895
0
            Py_CLEAR(tmp);
13896
0
            pattern = NULL;
13897
0
        }
13898
0
        else {
13899
0
            int res;
13900
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
13901
0
                goto failed;
13902
0
            }
13903
0
            res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
13904
0
            _Py_LeaveRecursiveCall();
13905
0
            if (res != 0) goto failed;
13906
0
            Py_CLEAR(tmp);
13907
0
        }
13908
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13909
0
            return -1;
13910
0
        }
13911
0
        if (tmp == NULL || tmp == Py_None) {
13912
0
            Py_CLEAR(tmp);
13913
0
            name = NULL;
13914
0
        }
13915
0
        else {
13916
0
            int res;
13917
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
13918
0
                goto failed;
13919
0
            }
13920
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
13921
0
            _Py_LeaveRecursiveCall();
13922
0
            if (res != 0) goto failed;
13923
0
            Py_CLEAR(tmp);
13924
0
        }
13925
0
        *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
13926
0
                              end_col_offset, arena);
13927
0
        if (*out == NULL) goto failed;
13928
0
        return 0;
13929
0
    }
13930
0
    tp = state->MatchOr_type;
13931
0
    isinstance = PyObject_IsInstance(obj, tp);
13932
0
    if (isinstance == -1) {
13933
0
        return -1;
13934
0
    }
13935
0
    if (isinstance) {
13936
0
        asdl_pattern_seq* patterns;
13937
13938
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13939
0
            return -1;
13940
0
        }
13941
0
        if (tmp == NULL) {
13942
0
            tmp = PyList_New(0);
13943
0
            if (tmp == NULL) {
13944
0
                return -1;
13945
0
            }
13946
0
        }
13947
0
        {
13948
0
            int res;
13949
0
            Py_ssize_t len;
13950
0
            Py_ssize_t i;
13951
0
            if (!PyList_Check(tmp)) {
13952
0
                PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %T", tmp);
13953
0
                goto failed;
13954
0
            }
13955
0
            len = PyList_GET_SIZE(tmp);
13956
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13957
0
            if (patterns == NULL) goto failed;
13958
0
            for (i = 0; i < len; i++) {
13959
0
                pattern_ty val;
13960
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13961
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
13962
0
                    goto failed;
13963
0
                }
13964
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13965
0
                _Py_LeaveRecursiveCall();
13966
0
                Py_DECREF(tmp2);
13967
0
                if (res != 0) goto failed;
13968
0
                if (len != PyList_GET_SIZE(tmp)) {
13969
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
13970
0
                    goto failed;
13971
0
                }
13972
0
                asdl_seq_SET(patterns, i, val);
13973
0
            }
13974
0
            Py_CLEAR(tmp);
13975
0
        }
13976
0
        *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
13977
0
                              end_col_offset, arena);
13978
0
        if (*out == NULL) goto failed;
13979
0
        return 0;
13980
0
    }
13981
13982
0
    PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
13983
0
    failed:
13984
0
    Py_XDECREF(tmp);
13985
0
    return -1;
13986
0
}
13987
13988
int
13989
obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
13990
                    out, const char* field, PyArena* arena)
13991
0
{
13992
0
    int isinstance;
13993
13994
0
    PyObject *tmp = NULL;
13995
0
    PyObject *tp;
13996
13997
0
    if (obj == Py_None) {
13998
0
        *out = NULL;
13999
0
        return 0;
14000
0
    }
14001
0
    tp = state->type_ignore_type;
14002
0
    isinstance = PyObject_IsInstance(obj, tp);
14003
0
    if (isinstance == -1) {
14004
0
        return 1;
14005
0
    }
14006
0
    if (!isinstance && field != NULL) {
14007
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_ignore', got '%T'", field, obj);
14008
0
        return 1;
14009
0
    }
14010
0
    tp = state->TypeIgnore_type;
14011
0
    isinstance = PyObject_IsInstance(obj, tp);
14012
0
    if (isinstance == -1) {
14013
0
        return -1;
14014
0
    }
14015
0
    if (isinstance) {
14016
0
        int lineno;
14017
0
        string tag;
14018
14019
0
        if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
14020
0
            return -1;
14021
0
        }
14022
0
        if (tmp == NULL) {
14023
0
            PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
14024
0
            return -1;
14025
0
        }
14026
0
        else {
14027
0
            int res;
14028
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
14029
0
                goto failed;
14030
0
            }
14031
0
            res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
14032
0
            _Py_LeaveRecursiveCall();
14033
0
            if (res != 0) goto failed;
14034
0
            Py_CLEAR(tmp);
14035
0
        }
14036
0
        if (PyObject_GetOptionalAttr(obj, state->tag, &tmp) < 0) {
14037
0
            return -1;
14038
0
        }
14039
0
        if (tmp == NULL) {
14040
0
            PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
14041
0
            return -1;
14042
0
        }
14043
0
        else {
14044
0
            int res;
14045
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
14046
0
                goto failed;
14047
0
            }
14048
0
            res = obj2ast_string(state, tmp, &tag, "tag", arena);
14049
0
            _Py_LeaveRecursiveCall();
14050
0
            if (res != 0) goto failed;
14051
0
            Py_CLEAR(tmp);
14052
0
        }
14053
0
        *out = _PyAST_TypeIgnore(lineno, tag, arena);
14054
0
        if (*out == NULL) goto failed;
14055
0
        return 0;
14056
0
    }
14057
14058
0
    PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
14059
0
    failed:
14060
0
    Py_XDECREF(tmp);
14061
0
    return -1;
14062
0
}
14063
14064
int
14065
obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
14066
                   const char* field, PyArena* arena)
14067
0
{
14068
0
    int isinstance;
14069
14070
0
    PyObject *tmp = NULL;
14071
0
    PyObject *tp;
14072
0
    int lineno;
14073
0
    int col_offset;
14074
0
    int end_lineno;
14075
0
    int end_col_offset;
14076
14077
0
    if (obj == Py_None) {
14078
0
        *out = NULL;
14079
0
        return 0;
14080
0
    }
14081
0
    tp = state->type_param_type;
14082
0
    isinstance = PyObject_IsInstance(obj, tp);
14083
0
    if (isinstance == -1) {
14084
0
        return 1;
14085
0
    }
14086
0
    if (!isinstance && field != NULL) {
14087
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_param', got '%T'", field, obj);
14088
0
        return 1;
14089
0
    }
14090
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
14091
0
        return -1;
14092
0
    }
14093
0
    if (tmp == NULL) {
14094
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
14095
0
        return -1;
14096
0
    }
14097
0
    else {
14098
0
        int res;
14099
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14100
0
            goto failed;
14101
0
        }
14102
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
14103
0
        _Py_LeaveRecursiveCall();
14104
0
        if (res != 0) goto failed;
14105
0
        Py_CLEAR(tmp);
14106
0
    }
14107
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
14108
0
        return -1;
14109
0
    }
14110
0
    if (tmp == NULL) {
14111
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
14112
0
        return -1;
14113
0
    }
14114
0
    else {
14115
0
        int res;
14116
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14117
0
            goto failed;
14118
0
        }
14119
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
14120
0
        _Py_LeaveRecursiveCall();
14121
0
        if (res != 0) goto failed;
14122
0
        Py_CLEAR(tmp);
14123
0
    }
14124
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
14125
0
        return -1;
14126
0
    }
14127
0
    if (tmp == NULL) {
14128
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
14129
0
        return -1;
14130
0
    }
14131
0
    else {
14132
0
        int res;
14133
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14134
0
            goto failed;
14135
0
        }
14136
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
14137
0
        _Py_LeaveRecursiveCall();
14138
0
        if (res != 0) goto failed;
14139
0
        Py_CLEAR(tmp);
14140
0
    }
14141
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
14142
0
        return -1;
14143
0
    }
14144
0
    if (tmp == NULL) {
14145
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
14146
0
        return -1;
14147
0
    }
14148
0
    else {
14149
0
        int res;
14150
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14151
0
            goto failed;
14152
0
        }
14153
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
14154
0
        _Py_LeaveRecursiveCall();
14155
0
        if (res != 0) goto failed;
14156
0
        Py_CLEAR(tmp);
14157
0
    }
14158
0
    tp = state->TypeVar_type;
14159
0
    isinstance = PyObject_IsInstance(obj, tp);
14160
0
    if (isinstance == -1) {
14161
0
        return -1;
14162
0
    }
14163
0
    if (isinstance) {
14164
0
        identifier name;
14165
0
        expr_ty bound;
14166
0
        expr_ty default_value;
14167
14168
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14169
0
            return -1;
14170
0
        }
14171
0
        if (tmp == NULL) {
14172
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
14173
0
            return -1;
14174
0
        }
14175
0
        else {
14176
0
            int res;
14177
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14178
0
                goto failed;
14179
0
            }
14180
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14181
0
            _Py_LeaveRecursiveCall();
14182
0
            if (res != 0) goto failed;
14183
0
            Py_CLEAR(tmp);
14184
0
        }
14185
0
        if (PyObject_GetOptionalAttr(obj, state->bound, &tmp) < 0) {
14186
0
            return -1;
14187
0
        }
14188
0
        if (tmp == NULL || tmp == Py_None) {
14189
0
            Py_CLEAR(tmp);
14190
0
            bound = NULL;
14191
0
        }
14192
0
        else {
14193
0
            int res;
14194
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14195
0
                goto failed;
14196
0
            }
14197
0
            res = obj2ast_expr(state, tmp, &bound, "bound", arena);
14198
0
            _Py_LeaveRecursiveCall();
14199
0
            if (res != 0) goto failed;
14200
0
            Py_CLEAR(tmp);
14201
0
        }
14202
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14203
0
            return -1;
14204
0
        }
14205
0
        if (tmp == NULL || tmp == Py_None) {
14206
0
            Py_CLEAR(tmp);
14207
0
            default_value = NULL;
14208
0
        }
14209
0
        else {
14210
0
            int res;
14211
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14212
0
                goto failed;
14213
0
            }
14214
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14215
0
                               arena);
14216
0
            _Py_LeaveRecursiveCall();
14217
0
            if (res != 0) goto failed;
14218
0
            Py_CLEAR(tmp);
14219
0
        }
14220
0
        *out = _PyAST_TypeVar(name, bound, default_value, lineno, col_offset,
14221
0
                              end_lineno, end_col_offset, arena);
14222
0
        if (*out == NULL) goto failed;
14223
0
        return 0;
14224
0
    }
14225
0
    tp = state->ParamSpec_type;
14226
0
    isinstance = PyObject_IsInstance(obj, tp);
14227
0
    if (isinstance == -1) {
14228
0
        return -1;
14229
0
    }
14230
0
    if (isinstance) {
14231
0
        identifier name;
14232
0
        expr_ty default_value;
14233
14234
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14235
0
            return -1;
14236
0
        }
14237
0
        if (tmp == NULL) {
14238
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
14239
0
            return -1;
14240
0
        }
14241
0
        else {
14242
0
            int res;
14243
0
            if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
14244
0
                goto failed;
14245
0
            }
14246
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14247
0
            _Py_LeaveRecursiveCall();
14248
0
            if (res != 0) goto failed;
14249
0
            Py_CLEAR(tmp);
14250
0
        }
14251
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14252
0
            return -1;
14253
0
        }
14254
0
        if (tmp == NULL || tmp == Py_None) {
14255
0
            Py_CLEAR(tmp);
14256
0
            default_value = NULL;
14257
0
        }
14258
0
        else {
14259
0
            int res;
14260
0
            if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
14261
0
                goto failed;
14262
0
            }
14263
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14264
0
                               arena);
14265
0
            _Py_LeaveRecursiveCall();
14266
0
            if (res != 0) goto failed;
14267
0
            Py_CLEAR(tmp);
14268
0
        }
14269
0
        *out = _PyAST_ParamSpec(name, default_value, lineno, col_offset,
14270
0
                                end_lineno, end_col_offset, arena);
14271
0
        if (*out == NULL) goto failed;
14272
0
        return 0;
14273
0
    }
14274
0
    tp = state->TypeVarTuple_type;
14275
0
    isinstance = PyObject_IsInstance(obj, tp);
14276
0
    if (isinstance == -1) {
14277
0
        return -1;
14278
0
    }
14279
0
    if (isinstance) {
14280
0
        identifier name;
14281
0
        expr_ty default_value;
14282
14283
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14284
0
            return -1;
14285
0
        }
14286
0
        if (tmp == NULL) {
14287
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
14288
0
            return -1;
14289
0
        }
14290
0
        else {
14291
0
            int res;
14292
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
14293
0
                goto failed;
14294
0
            }
14295
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14296
0
            _Py_LeaveRecursiveCall();
14297
0
            if (res != 0) goto failed;
14298
0
            Py_CLEAR(tmp);
14299
0
        }
14300
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14301
0
            return -1;
14302
0
        }
14303
0
        if (tmp == NULL || tmp == Py_None) {
14304
0
            Py_CLEAR(tmp);
14305
0
            default_value = NULL;
14306
0
        }
14307
0
        else {
14308
0
            int res;
14309
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
14310
0
                goto failed;
14311
0
            }
14312
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14313
0
                               arena);
14314
0
            _Py_LeaveRecursiveCall();
14315
0
            if (res != 0) goto failed;
14316
0
            Py_CLEAR(tmp);
14317
0
        }
14318
0
        *out = _PyAST_TypeVarTuple(name, default_value, lineno, col_offset,
14319
0
                                   end_lineno, end_col_offset, arena);
14320
0
        if (*out == NULL) goto failed;
14321
0
        return 0;
14322
0
    }
14323
14324
0
    PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
14325
0
    failed:
14326
0
    Py_XDECREF(tmp);
14327
0
    return -1;
14328
0
}
14329
14330
14331
/* Helper for checking if a node class is abstract in the tests. */
14332
static PyObject *
14333
0
ast_is_abstract(PyObject *Py_UNUSED(module), PyObject *cls) {
14334
0
    struct ast_state *state = get_ast_state();
14335
0
    if (state == NULL) {
14336
0
        return NULL;
14337
0
    }
14338
0
    int contains = PySet_Contains(state->abstract_types, cls);
14339
0
    if (contains == -1) {
14340
0
        return NULL;
14341
0
    }
14342
0
    else if (contains == 1) {
14343
0
        Py_RETURN_TRUE;
14344
0
    }
14345
0
    Py_RETURN_FALSE;
14346
0
}
14347
14348
static struct PyMethodDef astmodule_methods[] = {
14349
    {"_is_abstract", ast_is_abstract, METH_O, NULL},
14350
    {NULL}  /* Sentinel */
14351
};
14352
14353
static int
14354
astmodule_exec(PyObject *m)
14355
9
{
14356
9
    struct ast_state *state = get_ast_state();
14357
9
    if (state == NULL) {
14358
0
        return -1;
14359
0
    }
14360
9
    if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
14361
0
        return -1;
14362
0
    }
14363
9
    if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
14364
0
        return -1;
14365
0
    }
14366
9
    if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
14367
0
        return -1;
14368
0
    }
14369
9
    if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
14370
0
        return -1;
14371
0
    }
14372
9
    if (PyModule_AddIntMacro(m, PyCF_OPTIMIZED_AST) < 0) {
14373
0
        return -1;
14374
0
    }
14375
9
    if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
14376
0
        return -1;
14377
0
    }
14378
9
    if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
14379
0
        return -1;
14380
0
    }
14381
9
    if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
14382
0
        return -1;
14383
0
    }
14384
9
    if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
14385
0
        return -1;
14386
0
    }
14387
9
    if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
14388
0
        {
14389
0
        return -1;
14390
0
    }
14391
9
    if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
14392
0
        return -1;
14393
0
    }
14394
9
    if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
14395
0
        return -1;
14396
0
    }
14397
9
    if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
14398
9
        state->AsyncFunctionDef_type) < 0) {
14399
0
        return -1;
14400
0
    }
14401
9
    if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
14402
0
        return -1;
14403
0
    }
14404
9
    if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
14405
0
        return -1;
14406
0
    }
14407
9
    if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
14408
0
        return -1;
14409
0
    }
14410
9
    if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
14411
0
        return -1;
14412
0
    }
14413
9
    if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
14414
0
        return -1;
14415
0
    }
14416
9
    if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
14417
0
        return -1;
14418
0
    }
14419
9
    if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
14420
0
        return -1;
14421
0
    }
14422
9
    if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
14423
0
        return -1;
14424
0
    }
14425
9
    if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
14426
0
        return -1;
14427
0
    }
14428
9
    if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
14429
0
        return -1;
14430
0
    }
14431
9
    if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
14432
0
        return -1;
14433
0
    }
14434
9
    if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
14435
0
        return -1;
14436
0
    }
14437
9
    if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
14438
0
        return -1;
14439
0
    }
14440
9
    if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
14441
0
        return -1;
14442
0
    }
14443
9
    if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
14444
0
        return -1;
14445
0
    }
14446
9
    if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
14447
0
        return -1;
14448
0
    }
14449
9
    if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
14450
0
        return -1;
14451
0
    }
14452
9
    if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
14453
0
        return -1;
14454
0
    }
14455
9
    if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
14456
0
        return -1;
14457
0
    }
14458
9
    if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
14459
0
        return -1;
14460
0
    }
14461
9
    if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
14462
0
        return -1;
14463
0
    }
14464
9
    if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
14465
0
        return -1;
14466
0
    }
14467
9
    if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
14468
0
        return -1;
14469
0
    }
14470
9
    if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
14471
0
        return -1;
14472
0
    }
14473
9
    if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
14474
0
        return -1;
14475
0
    }
14476
9
    if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
14477
0
        return -1;
14478
0
    }
14479
9
    if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
14480
0
        return -1;
14481
0
    }
14482
9
    if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
14483
0
        return -1;
14484
0
    }
14485
9
    if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
14486
0
        return -1;
14487
0
    }
14488
9
    if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
14489
0
        return -1;
14490
0
    }
14491
9
    if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
14492
0
        return -1;
14493
0
    }
14494
9
    if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
14495
0
        return -1;
14496
0
    }
14497
9
    if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
14498
0
        return -1;
14499
0
    }
14500
9
    if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
14501
0
        return -1;
14502
0
    }
14503
9
    if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
14504
0
        return -1;
14505
0
    }
14506
9
    if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
14507
0
        return -1;
14508
0
    }
14509
9
    if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
14510
0
        return -1;
14511
0
    }
14512
9
    if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
14513
0
        return -1;
14514
0
    }
14515
9
    if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
14516
0
        {
14517
0
        return -1;
14518
0
    }
14519
9
    if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
14520
0
        return -1;
14521
0
    }
14522
9
    if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
14523
0
        return -1;
14524
0
    }
14525
9
    if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
14526
0
        return -1;
14527
0
    }
14528
9
    if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
14529
0
        return -1;
14530
0
    }
14531
9
    if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
14532
0
        return -1;
14533
0
    }
14534
9
    if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
14535
9
        < 0) {
14536
0
        return -1;
14537
0
    }
14538
9
    if (PyModule_AddObjectRef(m, "Interpolation", state->Interpolation_type) <
14539
9
        0) {
14540
0
        return -1;
14541
0
    }
14542
9
    if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
14543
0
        return -1;
14544
0
    }
14545
9
    if (PyModule_AddObjectRef(m, "TemplateStr", state->TemplateStr_type) < 0) {
14546
0
        return -1;
14547
0
    }
14548
9
    if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
14549
0
        return -1;
14550
0
    }
14551
9
    if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
14552
0
        return -1;
14553
0
    }
14554
9
    if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
14555
0
        return -1;
14556
0
    }
14557
9
    if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
14558
0
        return -1;
14559
0
    }
14560
9
    if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
14561
0
        return -1;
14562
0
    }
14563
9
    if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
14564
0
        return -1;
14565
0
    }
14566
9
    if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
14567
0
        return -1;
14568
0
    }
14569
9
    if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
14570
0
        return -1;
14571
0
    }
14572
9
    if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
14573
0
        {
14574
0
        return -1;
14575
0
    }
14576
9
    if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
14577
0
        return -1;
14578
0
    }
14579
9
    if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
14580
0
        return -1;
14581
0
    }
14582
9
    if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
14583
0
        return -1;
14584
0
    }
14585
9
    if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
14586
0
        return -1;
14587
0
    }
14588
9
    if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
14589
0
        return -1;
14590
0
    }
14591
9
    if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
14592
0
        return -1;
14593
0
    }
14594
9
    if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
14595
0
        return -1;
14596
0
    }
14597
9
    if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
14598
0
        return -1;
14599
0
    }
14600
9
    if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
14601
0
        return -1;
14602
0
    }
14603
9
    if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
14604
0
        return -1;
14605
0
    }
14606
9
    if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
14607
0
        return -1;
14608
0
    }
14609
9
    if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
14610
0
        return -1;
14611
0
    }
14612
9
    if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
14613
0
        return -1;
14614
0
    }
14615
9
    if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
14616
0
        return -1;
14617
0
    }
14618
9
    if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
14619
0
        return -1;
14620
0
    }
14621
9
    if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
14622
0
        return -1;
14623
0
    }
14624
9
    if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
14625
0
        return -1;
14626
0
    }
14627
9
    if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
14628
0
        return -1;
14629
0
    }
14630
9
    if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
14631
0
        return -1;
14632
0
    }
14633
9
    if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
14634
0
        return -1;
14635
0
    }
14636
9
    if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
14637
0
        return -1;
14638
0
    }
14639
9
    if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
14640
0
        return -1;
14641
0
    }
14642
9
    if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
14643
0
        return -1;
14644
0
    }
14645
9
    if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
14646
0
        return -1;
14647
0
    }
14648
9
    if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
14649
0
        return -1;
14650
0
    }
14651
9
    if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
14652
0
        return -1;
14653
0
    }
14654
9
    if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
14655
0
        return -1;
14656
0
    }
14657
9
    if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
14658
0
        return -1;
14659
0
    }
14660
9
    if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
14661
0
        return -1;
14662
0
    }
14663
9
    if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
14664
0
        return -1;
14665
0
    }
14666
9
    if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
14667
0
        return -1;
14668
0
    }
14669
9
    if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
14670
0
        return -1;
14671
0
    }
14672
9
    if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
14673
0
        return -1;
14674
0
    }
14675
9
    if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
14676
0
        return -1;
14677
0
    }
14678
9
    if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
14679
0
        return -1;
14680
0
    }
14681
9
    if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
14682
0
        return -1;
14683
0
    }
14684
9
    if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
14685
9
        0) {
14686
0
        return -1;
14687
0
    }
14688
9
    if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
14689
9
        0) {
14690
0
        return -1;
14691
0
    }
14692
9
    if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
14693
9
        0) {
14694
0
        return -1;
14695
0
    }
14696
9
    if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
14697
0
        return -1;
14698
0
    }
14699
9
    if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
14700
0
        return -1;
14701
0
    }
14702
9
    if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
14703
0
        return -1;
14704
0
    }
14705
9
    if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
14706
0
        return -1;
14707
0
    }
14708
9
    if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
14709
0
        return -1;
14710
0
    }
14711
9
    if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
14712
0
        return -1;
14713
0
    }
14714
9
    if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
14715
0
        return -1;
14716
0
    }
14717
9
    if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
14718
0
        return -1;
14719
0
    }
14720
9
    if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
14721
9
        < 0) {
14722
0
        return -1;
14723
0
    }
14724
9
    if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
14725
9
        0) {
14726
0
        return -1;
14727
0
    }
14728
9
    if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
14729
0
        {
14730
0
        return -1;
14731
0
    }
14732
9
    if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
14733
0
        return -1;
14734
0
    }
14735
9
    if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
14736
0
        return -1;
14737
0
    }
14738
9
    if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
14739
0
        return -1;
14740
0
    }
14741
9
    if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
14742
0
        return -1;
14743
0
    }
14744
9
    if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
14745
0
        return -1;
14746
0
    }
14747
9
    if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
14748
0
        return -1;
14749
0
    }
14750
9
    if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
14751
0
        return -1;
14752
0
    }
14753
9
    if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
14754
0
        return -1;
14755
0
    }
14756
9
    if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
14757
0
        return -1;
14758
0
    }
14759
9
    if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
14760
0
        {
14761
0
        return -1;
14762
0
    }
14763
9
    return 0;
14764
9
}
14765
14766
static PyModuleDef_Slot astmodule_slots[] = {
14767
    _Py_ABI_SLOT,
14768
    {Py_mod_exec, astmodule_exec},
14769
    {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
14770
    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
14771
    {0, NULL}
14772
};
14773
14774
static struct PyModuleDef _astmodule = {
14775
    PyModuleDef_HEAD_INIT,
14776
    .m_name = "_ast",
14777
    // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
14778
    .m_size = 0,
14779
    .m_methods = astmodule_methods,
14780
    .m_slots = astmodule_slots
14781
};
14782
14783
PyMODINIT_FUNC
14784
PyInit__ast(void)
14785
9
{
14786
9
    return PyModuleDef_Init(&_astmodule);
14787
9
}
14788
14789
14790
PyObject* PyAST_mod2obj(mod_ty t)
14791
7.39k
{
14792
7.39k
    struct ast_state *state = get_ast_state();
14793
7.39k
    if (state == NULL) {
14794
0
        return NULL;
14795
0
    }
14796
7.39k
    PyObject *result = ast2obj_mod(state, t);
14797
14798
7.39k
    return result;
14799
7.39k
}
14800
14801
/* mode is 0 for "exec", 1 for "eval", 2 for "single" and 3 for "func_type"
14802
   input */
14803
int PyAst_CheckMode(PyObject *ast, int mode)
14804
0
{
14805
0
    const char * const req_name[] = {"Module", "Expression", "Interactive",
14806
0
                                     "FunctionType"};
14807
14808
0
    struct ast_state *state = get_ast_state();
14809
0
    if (state == NULL) {
14810
0
        return -1;
14811
0
    }
14812
14813
0
    PyObject *req_type[4];
14814
0
    req_type[0] = state->Module_type;
14815
0
    req_type[1] = state->Expression_type;
14816
0
    req_type[2] = state->Interactive_type;
14817
0
    req_type[3] = state->FunctionType_type;
14818
14819
0
    assert(0 <= mode && mode <= 3);
14820
0
    int isinstance = PyObject_IsInstance(ast, req_type[mode]);
14821
0
    if (isinstance == -1) {
14822
0
        return -1;
14823
0
    }
14824
0
    if (!isinstance) {
14825
0
        PyErr_Format(PyExc_TypeError, "expected %s node, got %T",
14826
0
                     req_name[mode], ast);
14827
0
        return -1;
14828
0
    }
14829
0
    return 0;
14830
0
}
14831
14832
mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
14833
0
{
14834
0
    if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
14835
0
        return NULL;
14836
0
    }
14837
14838
0
    struct ast_state *state = get_ast_state();
14839
0
    if (state == NULL) {
14840
0
        return NULL;
14841
0
    }
14842
14843
0
    if (PyAst_CheckMode(ast, mode) < 0) {
14844
0
        return NULL;
14845
0
    }
14846
14847
0
    mod_ty res = NULL;
14848
0
    if (obj2ast_mod(state, ast, &res, NULL, arena) != 0)
14849
0
        return NULL;
14850
0
    else
14851
0
        return res;
14852
0
}
14853
14854
int PyAST_Check(PyObject* obj)
14855
64.4k
{
14856
64.4k
    struct ast_state *state = get_ast_state();
14857
64.4k
    if (state == NULL) {
14858
0
        return -1;
14859
0
    }
14860
64.4k
    return PyObject_IsInstance(obj, state->AST_type);
14861
64.4k
}
14862
14863