Coverage Report

Created: 2026-11-20 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/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
2.02k
{
23
2.02k
    PyInterpreterState *interp = _PyInterpreterState_GET();
24
2.02k
    struct ast_state *state = &interp->ast;
25
2.02k
    assert(!state->finalized);
26
2.02k
    if (_PyOnceFlag_CallOnce(&state->once, (_Py_once_fn_t *)&init_types, state) < 0) {
27
0
        return NULL;
28
0
    }
29
2.02k
    return state;
30
2.02k
}
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
2
{
297
2
    if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return -1;
298
2
    if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return -1;
299
2
    if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return -1;
300
2
    if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return -1;
301
2
    if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return -1;
302
2
    if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return -1;
303
2
    if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return -1;
304
2
    if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return -1;
305
2
    if ((state->args = PyUnicode_InternFromString("args")) == NULL) return -1;
306
2
    if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return -1;
307
2
    if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return -1;
308
2
    if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return -1;
309
2
    if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return -1;
310
2
    if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return -1;
311
2
    if ((state->body = PyUnicode_InternFromString("body")) == NULL) return -1;
312
2
    if ((state->bound = PyUnicode_InternFromString("bound")) == NULL) return -1;
313
2
    if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return -1;
314
2
    if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return -1;
315
2
    if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return -1;
316
2
    if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return -1;
317
2
    if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return -1;
318
2
    if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return -1;
319
2
    if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return -1;
320
2
    if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return -1;
321
2
    if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return -1;
322
2
    if ((state->default_value = PyUnicode_InternFromString("default_value")) == NULL) return -1;
323
2
    if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return -1;
324
2
    if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return -1;
325
2
    if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return -1;
326
2
    if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return -1;
327
2
    if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return -1;
328
2
    if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return -1;
329
2
    if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return -1;
330
2
    if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return -1;
331
2
    if ((state->func = PyUnicode_InternFromString("func")) == NULL) return -1;
332
2
    if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return -1;
333
2
    if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return -1;
334
2
    if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return -1;
335
2
    if ((state->id = PyUnicode_InternFromString("id")) == NULL) return -1;
336
2
    if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return -1;
337
2
    if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return -1;
338
2
    if ((state->is_lazy = PyUnicode_InternFromString("is_lazy")) == NULL) return -1;
339
2
    if ((state->items = PyUnicode_InternFromString("items")) == NULL) return -1;
340
2
    if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return -1;
341
2
    if ((state->key = PyUnicode_InternFromString("key")) == NULL) return -1;
342
2
    if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return -1;
343
2
    if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return -1;
344
2
    if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return -1;
345
2
    if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return -1;
346
2
    if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return -1;
347
2
    if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return -1;
348
2
    if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return -1;
349
2
    if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return -1;
350
2
    if ((state->left = PyUnicode_InternFromString("left")) == NULL) return -1;
351
2
    if ((state->level = PyUnicode_InternFromString("level")) == NULL) return -1;
352
2
    if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return -1;
353
2
    if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return -1;
354
2
    if ((state->module = PyUnicode_InternFromString("module")) == NULL) return -1;
355
2
    if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return -1;
356
2
    if ((state->name = PyUnicode_InternFromString("name")) == NULL) return -1;
357
2
    if ((state->names = PyUnicode_InternFromString("names")) == NULL) return -1;
358
2
    if ((state->op = PyUnicode_InternFromString("op")) == NULL) return -1;
359
2
    if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return -1;
360
2
    if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return -1;
361
2
    if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return -1;
362
2
    if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return -1;
363
2
    if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return -1;
364
2
    if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return -1;
365
2
    if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return -1;
366
2
    if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return -1;
367
2
    if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return -1;
368
2
    if ((state->right = PyUnicode_InternFromString("right")) == NULL) return -1;
369
2
    if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return -1;
370
2
    if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return -1;
371
2
    if ((state->step = PyUnicode_InternFromString("step")) == NULL) return -1;
372
2
    if ((state->str = PyUnicode_InternFromString("str")) == NULL) return -1;
373
2
    if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return -1;
374
2
    if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return -1;
375
2
    if ((state->target = PyUnicode_InternFromString("target")) == NULL) return -1;
376
2
    if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return -1;
377
2
    if ((state->test = PyUnicode_InternFromString("test")) == NULL) return -1;
378
2
    if ((state->type = PyUnicode_InternFromString("type")) == NULL) return -1;
379
2
    if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return -1;
380
2
    if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return -1;
381
2
    if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return -1;
382
2
    if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return -1;
383
2
    if ((state->value = PyUnicode_InternFromString("value")) == NULL) return -1;
384
2
    if ((state->values = PyUnicode_InternFromString("values")) == NULL) return -1;
385
2
    if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return -1;
386
2
    return 0;
387
2
};
388
389
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
390
0
GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
391
203k
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
123k
GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
396
15.9k
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
986
GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
401
42
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
2
{
830
2
    enum {
831
2
        FIELD_OPTIONAL = 1,
832
2
        FIELD_SEQUENCE = 2,
833
2
        FIELD_BUILTIN = 4,
834
2
    };
835
2
    PyTypeObject *const builtin_types[] = {
836
2
        &PyUnicode_Type,
837
2
        &PyLong_Type,
838
2
        &PyBaseObject_Type,
839
2
    };
840
    // Offsets refer to this interpreter's AST state, not global types.
841
2
    static_assert(sizeof(struct ast_state) <= UINT16_MAX,
842
2
                  "ast_state offsets must fit in uint16_t");
843
2
    static const struct {
844
2
        uint16_t name_offset;
845
2
        uint16_t type_offset;  // An index into builtin_types for builtins.
846
2
        uint8_t flags;
847
2
    } fields[] = {
848
2
        {offsetof(struct ast_state, body),
849
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
850
2
        {offsetof(struct ast_state, type_ignores),
851
2
         offsetof(struct ast_state, type_ignore_type), FIELD_SEQUENCE},
852
2
        {offsetof(struct ast_state, body),
853
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
854
2
        {offsetof(struct ast_state, body),
855
2
         offsetof(struct ast_state, expr_type), 0},
856
2
        {offsetof(struct ast_state, argtypes),
857
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
858
2
        {offsetof(struct ast_state, returns),
859
2
         offsetof(struct ast_state, expr_type), 0},
860
2
        {offsetof(struct ast_state, name),
861
2
         0, FIELD_BUILTIN},
862
2
        {offsetof(struct ast_state, args),
863
2
         offsetof(struct ast_state, arguments_type), 0},
864
2
        {offsetof(struct ast_state, body),
865
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
866
2
        {offsetof(struct ast_state, decorator_list),
867
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
868
2
        {offsetof(struct ast_state, returns),
869
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
870
2
        {offsetof(struct ast_state, type_comment),
871
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
872
2
        {offsetof(struct ast_state, type_params),
873
2
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
874
2
        {offsetof(struct ast_state, name),
875
2
         0, FIELD_BUILTIN},
876
2
        {offsetof(struct ast_state, args),
877
2
         offsetof(struct ast_state, arguments_type), 0},
878
2
        {offsetof(struct ast_state, body),
879
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
880
2
        {offsetof(struct ast_state, decorator_list),
881
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
882
2
        {offsetof(struct ast_state, returns),
883
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
884
2
        {offsetof(struct ast_state, type_comment),
885
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
886
2
        {offsetof(struct ast_state, type_params),
887
2
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
888
2
        {offsetof(struct ast_state, name),
889
2
         0, FIELD_BUILTIN},
890
2
        {offsetof(struct ast_state, bases),
891
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
892
2
        {offsetof(struct ast_state, keywords),
893
2
         offsetof(struct ast_state, keyword_type), FIELD_SEQUENCE},
894
2
        {offsetof(struct ast_state, body),
895
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
896
2
        {offsetof(struct ast_state, decorator_list),
897
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
898
2
        {offsetof(struct ast_state, type_params),
899
2
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
900
2
        {offsetof(struct ast_state, value),
901
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
902
2
        {offsetof(struct ast_state, targets),
903
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
904
2
        {offsetof(struct ast_state, targets),
905
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
906
2
        {offsetof(struct ast_state, value),
907
2
         offsetof(struct ast_state, expr_type), 0},
908
2
        {offsetof(struct ast_state, type_comment),
909
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
910
2
        {offsetof(struct ast_state, name),
911
2
         offsetof(struct ast_state, expr_type), 0},
912
2
        {offsetof(struct ast_state, type_params),
913
2
         offsetof(struct ast_state, type_param_type), FIELD_SEQUENCE},
914
2
        {offsetof(struct ast_state, value),
915
2
         offsetof(struct ast_state, expr_type), 0},
916
2
        {offsetof(struct ast_state, target),
917
2
         offsetof(struct ast_state, expr_type), 0},
918
2
        {offsetof(struct ast_state, op),
919
2
         offsetof(struct ast_state, operator_type), 0},
920
2
        {offsetof(struct ast_state, value),
921
2
         offsetof(struct ast_state, expr_type), 0},
922
2
        {offsetof(struct ast_state, target),
923
2
         offsetof(struct ast_state, expr_type), 0},
924
2
        {offsetof(struct ast_state, annotation),
925
2
         offsetof(struct ast_state, expr_type), 0},
926
2
        {offsetof(struct ast_state, value),
927
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
928
2
        {offsetof(struct ast_state, simple),
929
2
         1, FIELD_BUILTIN},
930
2
        {offsetof(struct ast_state, target),
931
2
         offsetof(struct ast_state, expr_type), 0},
932
2
        {offsetof(struct ast_state, iter),
933
2
         offsetof(struct ast_state, expr_type), 0},
934
2
        {offsetof(struct ast_state, body),
935
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
936
2
        {offsetof(struct ast_state, orelse),
937
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
938
2
        {offsetof(struct ast_state, type_comment),
939
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
940
2
        {offsetof(struct ast_state, target),
941
2
         offsetof(struct ast_state, expr_type), 0},
942
2
        {offsetof(struct ast_state, iter),
943
2
         offsetof(struct ast_state, expr_type), 0},
944
2
        {offsetof(struct ast_state, body),
945
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
946
2
        {offsetof(struct ast_state, orelse),
947
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
948
2
        {offsetof(struct ast_state, type_comment),
949
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
950
2
        {offsetof(struct ast_state, test),
951
2
         offsetof(struct ast_state, expr_type), 0},
952
2
        {offsetof(struct ast_state, body),
953
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
954
2
        {offsetof(struct ast_state, orelse),
955
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
956
2
        {offsetof(struct ast_state, test),
957
2
         offsetof(struct ast_state, expr_type), 0},
958
2
        {offsetof(struct ast_state, body),
959
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
960
2
        {offsetof(struct ast_state, orelse),
961
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
962
2
        {offsetof(struct ast_state, items),
963
2
         offsetof(struct ast_state, withitem_type), FIELD_SEQUENCE},
964
2
        {offsetof(struct ast_state, body),
965
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
966
2
        {offsetof(struct ast_state, type_comment),
967
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
968
2
        {offsetof(struct ast_state, items),
969
2
         offsetof(struct ast_state, withitem_type), FIELD_SEQUENCE},
970
2
        {offsetof(struct ast_state, body),
971
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
972
2
        {offsetof(struct ast_state, type_comment),
973
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
974
2
        {offsetof(struct ast_state, subject),
975
2
         offsetof(struct ast_state, expr_type), 0},
976
2
        {offsetof(struct ast_state, cases),
977
2
         offsetof(struct ast_state, match_case_type), FIELD_SEQUENCE},
978
2
        {offsetof(struct ast_state, exc),
979
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
980
2
        {offsetof(struct ast_state, cause),
981
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
982
2
        {offsetof(struct ast_state, body),
983
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
984
2
        {offsetof(struct ast_state, handlers),
985
2
         offsetof(struct ast_state, excepthandler_type), FIELD_SEQUENCE},
986
2
        {offsetof(struct ast_state, orelse),
987
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
988
2
        {offsetof(struct ast_state, finalbody),
989
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
990
2
        {offsetof(struct ast_state, body),
991
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
992
2
        {offsetof(struct ast_state, handlers),
993
2
         offsetof(struct ast_state, excepthandler_type), FIELD_SEQUENCE},
994
2
        {offsetof(struct ast_state, orelse),
995
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
996
2
        {offsetof(struct ast_state, finalbody),
997
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
998
2
        {offsetof(struct ast_state, test),
999
2
         offsetof(struct ast_state, expr_type), 0},
1000
2
        {offsetof(struct ast_state, msg),
1001
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1002
2
        {offsetof(struct ast_state, names),
1003
2
         offsetof(struct ast_state, alias_type), FIELD_SEQUENCE},
1004
2
        {offsetof(struct ast_state, is_lazy),
1005
2
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1006
2
        {offsetof(struct ast_state, module),
1007
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1008
2
        {offsetof(struct ast_state, names),
1009
2
         offsetof(struct ast_state, alias_type), FIELD_SEQUENCE},
1010
2
        {offsetof(struct ast_state, level),
1011
2
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1012
2
        {offsetof(struct ast_state, is_lazy),
1013
2
         1, FIELD_OPTIONAL | FIELD_BUILTIN},
1014
2
        {offsetof(struct ast_state, names),
1015
2
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1016
2
        {offsetof(struct ast_state, names),
1017
2
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1018
2
        {offsetof(struct ast_state, value),
1019
2
         offsetof(struct ast_state, expr_type), 0},
1020
2
        {offsetof(struct ast_state, op),
1021
2
         offsetof(struct ast_state, boolop_type), 0},
1022
2
        {offsetof(struct ast_state, values),
1023
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1024
2
        {offsetof(struct ast_state, target),
1025
2
         offsetof(struct ast_state, expr_type), 0},
1026
2
        {offsetof(struct ast_state, value),
1027
2
         offsetof(struct ast_state, expr_type), 0},
1028
2
        {offsetof(struct ast_state, left),
1029
2
         offsetof(struct ast_state, expr_type), 0},
1030
2
        {offsetof(struct ast_state, op),
1031
2
         offsetof(struct ast_state, operator_type), 0},
1032
2
        {offsetof(struct ast_state, right),
1033
2
         offsetof(struct ast_state, expr_type), 0},
1034
2
        {offsetof(struct ast_state, op),
1035
2
         offsetof(struct ast_state, unaryop_type), 0},
1036
2
        {offsetof(struct ast_state, operand),
1037
2
         offsetof(struct ast_state, expr_type), 0},
1038
2
        {offsetof(struct ast_state, args),
1039
2
         offsetof(struct ast_state, arguments_type), 0},
1040
2
        {offsetof(struct ast_state, body),
1041
2
         offsetof(struct ast_state, expr_type), 0},
1042
2
        {offsetof(struct ast_state, test),
1043
2
         offsetof(struct ast_state, expr_type), 0},
1044
2
        {offsetof(struct ast_state, body),
1045
2
         offsetof(struct ast_state, expr_type), 0},
1046
2
        {offsetof(struct ast_state, orelse),
1047
2
         offsetof(struct ast_state, expr_type), 0},
1048
2
        {offsetof(struct ast_state, keys),
1049
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1050
2
        {offsetof(struct ast_state, values),
1051
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1052
2
        {offsetof(struct ast_state, elts),
1053
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1054
2
        {offsetof(struct ast_state, elt),
1055
2
         offsetof(struct ast_state, expr_type), 0},
1056
2
        {offsetof(struct ast_state, generators),
1057
2
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1058
2
        {offsetof(struct ast_state, elt),
1059
2
         offsetof(struct ast_state, expr_type), 0},
1060
2
        {offsetof(struct ast_state, generators),
1061
2
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1062
2
        {offsetof(struct ast_state, key),
1063
2
         offsetof(struct ast_state, expr_type), 0},
1064
2
        {offsetof(struct ast_state, value),
1065
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1066
2
        {offsetof(struct ast_state, generators),
1067
2
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1068
2
        {offsetof(struct ast_state, elt),
1069
2
         offsetof(struct ast_state, expr_type), 0},
1070
2
        {offsetof(struct ast_state, generators),
1071
2
         offsetof(struct ast_state, comprehension_type), FIELD_SEQUENCE},
1072
2
        {offsetof(struct ast_state, value),
1073
2
         offsetof(struct ast_state, expr_type), 0},
1074
2
        {offsetof(struct ast_state, value),
1075
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1076
2
        {offsetof(struct ast_state, value),
1077
2
         offsetof(struct ast_state, expr_type), 0},
1078
2
        {offsetof(struct ast_state, left),
1079
2
         offsetof(struct ast_state, expr_type), 0},
1080
2
        {offsetof(struct ast_state, ops),
1081
2
         offsetof(struct ast_state, cmpop_type), FIELD_SEQUENCE},
1082
2
        {offsetof(struct ast_state, comparators),
1083
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1084
2
        {offsetof(struct ast_state, func),
1085
2
         offsetof(struct ast_state, expr_type), 0},
1086
2
        {offsetof(struct ast_state, args),
1087
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1088
2
        {offsetof(struct ast_state, keywords),
1089
2
         offsetof(struct ast_state, keyword_type), FIELD_SEQUENCE},
1090
2
        {offsetof(struct ast_state, value),
1091
2
         offsetof(struct ast_state, expr_type), 0},
1092
2
        {offsetof(struct ast_state, conversion),
1093
2
         1, FIELD_BUILTIN},
1094
2
        {offsetof(struct ast_state, format_spec),
1095
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1096
2
        {offsetof(struct ast_state, value),
1097
2
         offsetof(struct ast_state, expr_type), 0},
1098
2
        {offsetof(struct ast_state, str),
1099
2
         2, FIELD_BUILTIN},
1100
2
        {offsetof(struct ast_state, conversion),
1101
2
         1, FIELD_BUILTIN},
1102
2
        {offsetof(struct ast_state, format_spec),
1103
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1104
2
        {offsetof(struct ast_state, values),
1105
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1106
2
        {offsetof(struct ast_state, values),
1107
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1108
2
        {offsetof(struct ast_state, value),
1109
2
         2, FIELD_BUILTIN},
1110
2
        {offsetof(struct ast_state, kind),
1111
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1112
2
        {offsetof(struct ast_state, value),
1113
2
         offsetof(struct ast_state, expr_type), 0},
1114
2
        {offsetof(struct ast_state, attr),
1115
2
         0, FIELD_BUILTIN},
1116
2
        {offsetof(struct ast_state, ctx),
1117
2
         offsetof(struct ast_state, expr_context_type), 0},
1118
2
        {offsetof(struct ast_state, value),
1119
2
         offsetof(struct ast_state, expr_type), 0},
1120
2
        {offsetof(struct ast_state, slice),
1121
2
         offsetof(struct ast_state, expr_type), 0},
1122
2
        {offsetof(struct ast_state, ctx),
1123
2
         offsetof(struct ast_state, expr_context_type), 0},
1124
2
        {offsetof(struct ast_state, value),
1125
2
         offsetof(struct ast_state, expr_type), 0},
1126
2
        {offsetof(struct ast_state, ctx),
1127
2
         offsetof(struct ast_state, expr_context_type), 0},
1128
2
        {offsetof(struct ast_state, id),
1129
2
         0, FIELD_BUILTIN},
1130
2
        {offsetof(struct ast_state, ctx),
1131
2
         offsetof(struct ast_state, expr_context_type), 0},
1132
2
        {offsetof(struct ast_state, elts),
1133
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1134
2
        {offsetof(struct ast_state, ctx),
1135
2
         offsetof(struct ast_state, expr_context_type), 0},
1136
2
        {offsetof(struct ast_state, elts),
1137
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1138
2
        {offsetof(struct ast_state, ctx),
1139
2
         offsetof(struct ast_state, expr_context_type), 0},
1140
2
        {offsetof(struct ast_state, lower),
1141
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1142
2
        {offsetof(struct ast_state, upper),
1143
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1144
2
        {offsetof(struct ast_state, step),
1145
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1146
2
        {offsetof(struct ast_state, target),
1147
2
         offsetof(struct ast_state, expr_type), 0},
1148
2
        {offsetof(struct ast_state, iter),
1149
2
         offsetof(struct ast_state, expr_type), 0},
1150
2
        {offsetof(struct ast_state, ifs),
1151
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1152
2
        {offsetof(struct ast_state, is_async),
1153
2
         1, FIELD_BUILTIN},
1154
2
        {offsetof(struct ast_state, type),
1155
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1156
2
        {offsetof(struct ast_state, name),
1157
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1158
2
        {offsetof(struct ast_state, body),
1159
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
1160
2
        {offsetof(struct ast_state, posonlyargs),
1161
2
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1162
2
        {offsetof(struct ast_state, args),
1163
2
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1164
2
        {offsetof(struct ast_state, vararg),
1165
2
         offsetof(struct ast_state, arg_type), FIELD_OPTIONAL},
1166
2
        {offsetof(struct ast_state, kwonlyargs),
1167
2
         offsetof(struct ast_state, arg_type), FIELD_SEQUENCE},
1168
2
        {offsetof(struct ast_state, kw_defaults),
1169
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1170
2
        {offsetof(struct ast_state, kwarg),
1171
2
         offsetof(struct ast_state, arg_type), FIELD_OPTIONAL},
1172
2
        {offsetof(struct ast_state, defaults),
1173
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1174
2
        {offsetof(struct ast_state, arg),
1175
2
         0, FIELD_BUILTIN},
1176
2
        {offsetof(struct ast_state, annotation),
1177
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1178
2
        {offsetof(struct ast_state, type_comment),
1179
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1180
2
        {offsetof(struct ast_state, arg),
1181
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1182
2
        {offsetof(struct ast_state, value),
1183
2
         offsetof(struct ast_state, expr_type), 0},
1184
2
        {offsetof(struct ast_state, name),
1185
2
         0, FIELD_BUILTIN},
1186
2
        {offsetof(struct ast_state, asname),
1187
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1188
2
        {offsetof(struct ast_state, context_expr),
1189
2
         offsetof(struct ast_state, expr_type), 0},
1190
2
        {offsetof(struct ast_state, optional_vars),
1191
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1192
2
        {offsetof(struct ast_state, pattern),
1193
2
         offsetof(struct ast_state, pattern_type), 0},
1194
2
        {offsetof(struct ast_state, guard),
1195
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1196
2
        {offsetof(struct ast_state, body),
1197
2
         offsetof(struct ast_state, stmt_type), FIELD_SEQUENCE},
1198
2
        {offsetof(struct ast_state, value),
1199
2
         offsetof(struct ast_state, expr_type), 0},
1200
2
        {offsetof(struct ast_state, value),
1201
2
         2, FIELD_BUILTIN},
1202
2
        {offsetof(struct ast_state, patterns),
1203
2
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1204
2
        {offsetof(struct ast_state, keys),
1205
2
         offsetof(struct ast_state, expr_type), FIELD_SEQUENCE},
1206
2
        {offsetof(struct ast_state, patterns),
1207
2
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1208
2
        {offsetof(struct ast_state, rest),
1209
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1210
2
        {offsetof(struct ast_state, cls),
1211
2
         offsetof(struct ast_state, expr_type), 0},
1212
2
        {offsetof(struct ast_state, patterns),
1213
2
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1214
2
        {offsetof(struct ast_state, kwd_attrs),
1215
2
         0, FIELD_SEQUENCE | FIELD_BUILTIN},
1216
2
        {offsetof(struct ast_state, kwd_patterns),
1217
2
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1218
2
        {offsetof(struct ast_state, name),
1219
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1220
2
        {offsetof(struct ast_state, pattern),
1221
2
         offsetof(struct ast_state, pattern_type), FIELD_OPTIONAL},
1222
2
        {offsetof(struct ast_state, name),
1223
2
         0, FIELD_OPTIONAL | FIELD_BUILTIN},
1224
2
        {offsetof(struct ast_state, patterns),
1225
2
         offsetof(struct ast_state, pattern_type), FIELD_SEQUENCE},
1226
2
        {offsetof(struct ast_state, lineno),
1227
2
         1, FIELD_BUILTIN},
1228
2
        {offsetof(struct ast_state, tag),
1229
2
         0, FIELD_BUILTIN},
1230
2
        {offsetof(struct ast_state, name),
1231
2
         0, FIELD_BUILTIN},
1232
2
        {offsetof(struct ast_state, bound),
1233
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1234
2
        {offsetof(struct ast_state, default_value),
1235
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1236
2
        {offsetof(struct ast_state, name),
1237
2
         0, FIELD_BUILTIN},
1238
2
        {offsetof(struct ast_state, default_value),
1239
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1240
2
        {offsetof(struct ast_state, name),
1241
2
         0, FIELD_BUILTIN},
1242
2
        {offsetof(struct ast_state, default_value),
1243
2
         offsetof(struct ast_state, expr_type), FIELD_OPTIONAL},
1244
2
    };
1245
2
    static const struct {
1246
2
        uint16_t type_offset;
1247
2
        uint16_t first_field;
1248
2
        uint16_t nfields;
1249
2
    } nodes[] = {
1250
2
        {offsetof(struct ast_state, Module_type), 0, 2},
1251
2
        {offsetof(struct ast_state, Interactive_type), 2, 1},
1252
2
        {offsetof(struct ast_state, Expression_type), 3, 1},
1253
2
        {offsetof(struct ast_state, FunctionType_type), 4, 2},
1254
2
        {offsetof(struct ast_state, FunctionDef_type), 6, 7},
1255
2
        {offsetof(struct ast_state, AsyncFunctionDef_type), 13, 7},
1256
2
        {offsetof(struct ast_state, ClassDef_type), 20, 6},
1257
2
        {offsetof(struct ast_state, Return_type), 26, 1},
1258
2
        {offsetof(struct ast_state, Delete_type), 27, 1},
1259
2
        {offsetof(struct ast_state, Assign_type), 28, 3},
1260
2
        {offsetof(struct ast_state, TypeAlias_type), 31, 3},
1261
2
        {offsetof(struct ast_state, AugAssign_type), 34, 3},
1262
2
        {offsetof(struct ast_state, AnnAssign_type), 37, 4},
1263
2
        {offsetof(struct ast_state, For_type), 41, 5},
1264
2
        {offsetof(struct ast_state, AsyncFor_type), 46, 5},
1265
2
        {offsetof(struct ast_state, While_type), 51, 3},
1266
2
        {offsetof(struct ast_state, If_type), 54, 3},
1267
2
        {offsetof(struct ast_state, With_type), 57, 3},
1268
2
        {offsetof(struct ast_state, AsyncWith_type), 60, 3},
1269
2
        {offsetof(struct ast_state, Match_type), 63, 2},
1270
2
        {offsetof(struct ast_state, Raise_type), 65, 2},
1271
2
        {offsetof(struct ast_state, Try_type), 67, 4},
1272
2
        {offsetof(struct ast_state, TryStar_type), 71, 4},
1273
2
        {offsetof(struct ast_state, Assert_type), 75, 2},
1274
2
        {offsetof(struct ast_state, Import_type), 77, 2},
1275
2
        {offsetof(struct ast_state, ImportFrom_type), 79, 4},
1276
2
        {offsetof(struct ast_state, Global_type), 83, 1},
1277
2
        {offsetof(struct ast_state, Nonlocal_type), 84, 1},
1278
2
        {offsetof(struct ast_state, Expr_type), 85, 1},
1279
2
        {offsetof(struct ast_state, Pass_type), 86, 0},
1280
2
        {offsetof(struct ast_state, Break_type), 86, 0},
1281
2
        {offsetof(struct ast_state, Continue_type), 86, 0},
1282
2
        {offsetof(struct ast_state, BoolOp_type), 86, 2},
1283
2
        {offsetof(struct ast_state, NamedExpr_type), 88, 2},
1284
2
        {offsetof(struct ast_state, BinOp_type), 90, 3},
1285
2
        {offsetof(struct ast_state, UnaryOp_type), 93, 2},
1286
2
        {offsetof(struct ast_state, Lambda_type), 95, 2},
1287
2
        {offsetof(struct ast_state, IfExp_type), 97, 3},
1288
2
        {offsetof(struct ast_state, Dict_type), 100, 2},
1289
2
        {offsetof(struct ast_state, Set_type), 102, 1},
1290
2
        {offsetof(struct ast_state, ListComp_type), 103, 2},
1291
2
        {offsetof(struct ast_state, SetComp_type), 105, 2},
1292
2
        {offsetof(struct ast_state, DictComp_type), 107, 3},
1293
2
        {offsetof(struct ast_state, GeneratorExp_type), 110, 2},
1294
2
        {offsetof(struct ast_state, Await_type), 112, 1},
1295
2
        {offsetof(struct ast_state, Yield_type), 113, 1},
1296
2
        {offsetof(struct ast_state, YieldFrom_type), 114, 1},
1297
2
        {offsetof(struct ast_state, Compare_type), 115, 3},
1298
2
        {offsetof(struct ast_state, Call_type), 118, 3},
1299
2
        {offsetof(struct ast_state, FormattedValue_type), 121, 3},
1300
2
        {offsetof(struct ast_state, Interpolation_type), 124, 4},
1301
2
        {offsetof(struct ast_state, JoinedStr_type), 128, 1},
1302
2
        {offsetof(struct ast_state, TemplateStr_type), 129, 1},
1303
2
        {offsetof(struct ast_state, Constant_type), 130, 2},
1304
2
        {offsetof(struct ast_state, Attribute_type), 132, 3},
1305
2
        {offsetof(struct ast_state, Subscript_type), 135, 3},
1306
2
        {offsetof(struct ast_state, Starred_type), 138, 2},
1307
2
        {offsetof(struct ast_state, Name_type), 140, 2},
1308
2
        {offsetof(struct ast_state, List_type), 142, 2},
1309
2
        {offsetof(struct ast_state, Tuple_type), 144, 2},
1310
2
        {offsetof(struct ast_state, Slice_type), 146, 3},
1311
2
        {offsetof(struct ast_state, Load_type), 149, 0},
1312
2
        {offsetof(struct ast_state, Store_type), 149, 0},
1313
2
        {offsetof(struct ast_state, Del_type), 149, 0},
1314
2
        {offsetof(struct ast_state, And_type), 149, 0},
1315
2
        {offsetof(struct ast_state, Or_type), 149, 0},
1316
2
        {offsetof(struct ast_state, Add_type), 149, 0},
1317
2
        {offsetof(struct ast_state, Sub_type), 149, 0},
1318
2
        {offsetof(struct ast_state, Mult_type), 149, 0},
1319
2
        {offsetof(struct ast_state, MatMult_type), 149, 0},
1320
2
        {offsetof(struct ast_state, Div_type), 149, 0},
1321
2
        {offsetof(struct ast_state, Mod_type), 149, 0},
1322
2
        {offsetof(struct ast_state, Pow_type), 149, 0},
1323
2
        {offsetof(struct ast_state, LShift_type), 149, 0},
1324
2
        {offsetof(struct ast_state, RShift_type), 149, 0},
1325
2
        {offsetof(struct ast_state, BitOr_type), 149, 0},
1326
2
        {offsetof(struct ast_state, BitXor_type), 149, 0},
1327
2
        {offsetof(struct ast_state, BitAnd_type), 149, 0},
1328
2
        {offsetof(struct ast_state, FloorDiv_type), 149, 0},
1329
2
        {offsetof(struct ast_state, Invert_type), 149, 0},
1330
2
        {offsetof(struct ast_state, Not_type), 149, 0},
1331
2
        {offsetof(struct ast_state, UAdd_type), 149, 0},
1332
2
        {offsetof(struct ast_state, USub_type), 149, 0},
1333
2
        {offsetof(struct ast_state, Eq_type), 149, 0},
1334
2
        {offsetof(struct ast_state, NotEq_type), 149, 0},
1335
2
        {offsetof(struct ast_state, Lt_type), 149, 0},
1336
2
        {offsetof(struct ast_state, LtE_type), 149, 0},
1337
2
        {offsetof(struct ast_state, Gt_type), 149, 0},
1338
2
        {offsetof(struct ast_state, GtE_type), 149, 0},
1339
2
        {offsetof(struct ast_state, Is_type), 149, 0},
1340
2
        {offsetof(struct ast_state, IsNot_type), 149, 0},
1341
2
        {offsetof(struct ast_state, In_type), 149, 0},
1342
2
        {offsetof(struct ast_state, NotIn_type), 149, 0},
1343
2
        {offsetof(struct ast_state, comprehension_type), 149, 4},
1344
2
        {offsetof(struct ast_state, ExceptHandler_type), 153, 3},
1345
2
        {offsetof(struct ast_state, arguments_type), 156, 7},
1346
2
        {offsetof(struct ast_state, arg_type), 163, 3},
1347
2
        {offsetof(struct ast_state, keyword_type), 166, 2},
1348
2
        {offsetof(struct ast_state, alias_type), 168, 2},
1349
2
        {offsetof(struct ast_state, withitem_type), 170, 2},
1350
2
        {offsetof(struct ast_state, match_case_type), 172, 3},
1351
2
        {offsetof(struct ast_state, MatchValue_type), 175, 1},
1352
2
        {offsetof(struct ast_state, MatchSingleton_type), 176, 1},
1353
2
        {offsetof(struct ast_state, MatchSequence_type), 177, 1},
1354
2
        {offsetof(struct ast_state, MatchMapping_type), 178, 3},
1355
2
        {offsetof(struct ast_state, MatchClass_type), 181, 4},
1356
2
        {offsetof(struct ast_state, MatchStar_type), 185, 1},
1357
2
        {offsetof(struct ast_state, MatchAs_type), 186, 2},
1358
2
        {offsetof(struct ast_state, MatchOr_type), 188, 1},
1359
2
        {offsetof(struct ast_state, TypeIgnore_type), 189, 2},
1360
2
        {offsetof(struct ast_state, TypeVar_type), 191, 3},
1361
2
        {offsetof(struct ast_state, ParamSpec_type), 194, 2},
1362
2
        {offsetof(struct ast_state, TypeVarTuple_type), 196, 2},
1363
2
    };
1364
2
    char *base = (char *)state;
1365
2
    PyObject *annotations = NULL;
1366
228
    for (size_t i = 0; i < Py_ARRAY_LENGTH(nodes); i++) {
1367
226
        annotations = PyDict_New();
1368
226
        if (annotations == NULL) {
1369
0
            goto error;
1370
0
        }
1371
226
        size_t end = nodes[i].first_field + nodes[i].nfields;
1372
622
        for (size_t j = nodes[i].first_field; j < end; j++) {
1373
396
            PyObject *name = *(PyObject **)(base + fields[j].name_offset);
1374
396
            PyObject *type;
1375
396
            if (fields[j].flags & FIELD_BUILTIN) {
1376
82
                type = (PyObject *)builtin_types[fields[j].type_offset];
1377
82
            }
1378
314
            else {
1379
314
                type = *(PyObject **)(base + fields[j].type_offset);
1380
314
            }
1381
396
            if (fields[j].flags & FIELD_OPTIONAL) {
1382
88
                type = _Py_union_type_or(type, Py_None);
1383
88
            }
1384
308
            else if (fields[j].flags & FIELD_SEQUENCE) {
1385
148
                type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1386
148
            }
1387
160
            else {
1388
160
                Py_INCREF(type);
1389
160
            }
1390
396
            if (type == NULL) {
1391
0
                goto error;
1392
0
            }
1393
396
            int res = PyDict_SetItem(annotations, name, type);
1394
396
            Py_DECREF(type);
1395
396
            if (res < 0) {
1396
0
                goto error;
1397
0
            }
1398
396
        }
1399
226
        PyObject *node = *(PyObject **)(base + nodes[i].type_offset);
1400
226
        if (PyObject_SetAttrString(node, "_field_types", annotations) < 0 ||
1401
226
            PyObject_SetAttrString(node, "__annotations__", annotations) < 0)
1402
0
        {
1403
0
            goto error;
1404
0
        }
1405
226
        Py_CLEAR(annotations);
1406
226
    }
1407
2
    return 1;
1408
0
error:
1409
0
    Py_XDECREF(annotations);
1410
0
    return 0;
1411
2
}
1412
1413
1414
1415
typedef struct {
1416
    PyObject_HEAD
1417
} AST_object;
1418
1419
static void
1420
ast_dealloc(PyObject *op)
1421
330k
{
1422
330k
    AST_object *self = (AST_object*)op;
1423
    /* bpo-31095: UnTrack is needed before calling any callbacks */
1424
330k
    PyTypeObject *tp = Py_TYPE(self);
1425
330k
    PyObject_GC_UnTrack(self);
1426
330k
    PyObject_ClearManagedDict(op);
1427
330k
    freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1428
330k
    assert(free_func != NULL);
1429
330k
    free_func(self);
1430
330k
    Py_DECREF(tp);
1431
330k
}
1432
1433
static int
1434
ast_traverse(PyObject *op, visitproc visit, void *arg)
1435
704
{
1436
704
    AST_object *self = (AST_object*)op;
1437
704
    Py_VISIT(Py_TYPE(self));
1438
704
    return PyObject_VisitManagedDict(op, visit, arg);
1439
704
}
1440
1441
static int
1442
ast_clear(PyObject *op)
1443
0
{
1444
0
    PyObject_ClearManagedDict(op);
1445
0
    return 0;
1446
0
}
1447
1448
/*
1449
 * Format the names in the set 'missing' into a natural language list,
1450
 * sorted in the order in which they appear in 'fields'.
1451
 *
1452
 * Similar to format_missing() from 'Python/ceval.c'.
1453
 *
1454
 * Parameters
1455
 *
1456
 *      missing     Set of missing field names to render.
1457
 *      fields      Sequence of AST node field names (self._fields).
1458
 */
1459
static PyObject *
1460
format_missing(PyObject *missing, PyObject *fields)
1461
0
{
1462
0
    Py_ssize_t num_fields, num_total, num_left;
1463
0
    num_fields = PySequence_Size(fields);
1464
0
    if (num_fields == -1) {
1465
0
        return NULL;
1466
0
    }
1467
0
    num_total = num_left = PySet_GET_SIZE(missing);
1468
0
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
1469
0
    if (writer == NULL) {
1470
0
        goto error;
1471
0
    }
1472
    // Iterate all AST node fields in order so that the missing positional
1473
    // arguments are rendered in the order in which __init__ expects them.
1474
0
    for (Py_ssize_t i = 0; i < num_fields; i++) {
1475
0
        PyObject *name = PySequence_GetItem(fields, i);
1476
0
        if (name == NULL) {
1477
0
            goto error;
1478
0
        }
1479
0
        int contains = PySet_Contains(missing, name);
1480
0
        if (contains == -1) {
1481
0
            Py_DECREF(name);
1482
0
            goto error;
1483
0
        }
1484
0
        else if (contains == 1) {
1485
0
            const char* fmt = NULL;
1486
0
            if (num_left == 1) {
1487
0
                fmt = "'%U'";
1488
0
            }
1489
0
            else if (num_total == 2) {
1490
0
                fmt = "'%U' and ";
1491
0
            }
1492
0
            else if (num_left == 2) {
1493
0
                fmt = "'%U', and ";
1494
0
            }
1495
0
            else {
1496
0
                fmt = "'%U', ";
1497
0
            }
1498
0
            num_left--;
1499
0
            if (PyUnicodeWriter_Format(writer, fmt, name) < 0) {
1500
0
                Py_DECREF(name);
1501
0
                goto error;
1502
0
            }
1503
0
        }
1504
0
        Py_DECREF(name);
1505
0
    }
1506
0
    return PyUnicodeWriter_Finish(writer);
1507
0
error:
1508
0
    PyUnicodeWriter_Discard(writer);
1509
0
    return NULL;
1510
0
}
1511
1512
static int
1513
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1514
0
{
1515
0
    struct ast_state *state = get_ast_state();
1516
0
    if (state == NULL) {
1517
0
        return -1;
1518
0
    }
1519
1520
0
    int contains = PySet_Contains(state->abstract_types, (PyObject *)Py_TYPE(self));
1521
0
    if (contains == -1) {
1522
0
        return -1;
1523
0
    }
1524
0
    else if (contains == 1) {
1525
0
        if (PyErr_WarnFormat(
1526
0
                PyExc_DeprecationWarning, 1,
1527
0
                "Instantiating abstract AST node class %T is deprecated. "
1528
0
                "This will become an error in Python 3.20", self) < 0) {
1529
0
            return -1;
1530
0
        }
1531
0
    }
1532
1533
0
    Py_ssize_t i, numfields = 0;
1534
0
    int res = -1;
1535
0
    PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL;
1536
1537
0
    fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields);
1538
0
    if (fields == NULL) {
1539
0
        goto cleanup;
1540
0
    }
1541
1542
0
    numfields = PySequence_Size(fields);
1543
0
    if (numfields == -1) {
1544
0
        goto cleanup;
1545
0
    }
1546
0
    remaining_fields = PySet_New(fields);
1547
0
    if (remaining_fields == NULL) {
1548
0
        goto cleanup;
1549
0
    }
1550
1551
0
    res = 0; /* if no error occurs, this stays 0 to the end */
1552
0
    if (numfields < PyTuple_GET_SIZE(args)) {
1553
0
        PyErr_Format(PyExc_TypeError, "%T constructor takes at most "
1554
0
                     "%zd positional argument%s",
1555
0
                     self, numfields, numfields == 1 ? "" : "s");
1556
0
        res = -1;
1557
0
        goto cleanup;
1558
0
    }
1559
0
    for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1560
        /* cannot be reached when fields is NULL */
1561
0
        PyObject *name = PySequence_GetItem(fields, i);
1562
0
        if (!name) {
1563
0
            res = -1;
1564
0
            goto cleanup;
1565
0
        }
1566
0
        res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1567
0
        if (PySet_Discard(remaining_fields, name) < 0) {
1568
0
            res = -1;
1569
0
            Py_DECREF(name);
1570
0
            goto cleanup;
1571
0
        }
1572
0
        Py_DECREF(name);
1573
0
        if (res < 0) {
1574
0
            goto cleanup;
1575
0
        }
1576
0
    }
1577
0
    if (kw) {
1578
0
        i = 0;  /* needed by PyDict_Next */
1579
0
        while (PyDict_Next(kw, &i, &key, &value)) {
1580
0
            int contains = PySequence_Contains(fields, key);
1581
0
            if (contains == -1) {
1582
0
                res = -1;
1583
0
                goto cleanup;
1584
0
            }
1585
0
            else if (contains == 1) {
1586
0
                int p = PySet_Discard(remaining_fields, key);
1587
0
                if (p == -1) {
1588
0
                    res = -1;
1589
0
                    goto cleanup;
1590
0
                }
1591
0
                if (p == 0) {
1592
0
                    PyErr_Format(PyExc_TypeError,
1593
0
                        "%T got multiple values for argument %R",
1594
0
                        self, key);
1595
0
                    res = -1;
1596
0
                    goto cleanup;
1597
0
                }
1598
0
            }
1599
0
            else {
1600
                // Lazily initialize "attributes"
1601
0
                if (attributes == NULL) {
1602
0
                    attributes = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_attributes);
1603
0
                    if (attributes == NULL) {
1604
0
                        res = -1;
1605
0
                        goto cleanup;
1606
0
                    }
1607
0
                }
1608
0
                int contains = PySequence_Contains(attributes, key);
1609
0
                if (contains == -1) {
1610
0
                    res = -1;
1611
0
                    goto cleanup;
1612
0
                }
1613
0
                else if (contains == 0) {
1614
0
                    PyErr_Format(PyExc_TypeError,
1615
0
                        "%T.__init__ got an unexpected keyword argument %R",
1616
0
                        self, key);
1617
0
                    res = -1;
1618
0
                    goto cleanup;
1619
0
                }
1620
0
            }
1621
0
            res = PyObject_SetAttr(self, key, value);
1622
0
            if (res < 0) {
1623
0
                goto cleanup;
1624
0
            }
1625
0
        }
1626
0
    }
1627
0
    Py_ssize_t size = PySet_Size(remaining_fields);
1628
0
    PyObject *field_types = NULL, *remaining_list = NULL, *missing_names = NULL;
1629
0
    if (size > 0) {
1630
0
        if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
1631
0
                                     &field_types) < 0) {
1632
0
            res = -1;
1633
0
            goto cleanup;
1634
0
        }
1635
0
        if (field_types == NULL) {
1636
            // Probably a user-defined subclass of AST that lacks _field_types.
1637
            // This will continue to work as it did before 3.13; i.e., attributes
1638
            // that are not passed in simply do not exist on the instance.
1639
0
            goto cleanup;
1640
0
        }
1641
0
        remaining_list = PySequence_List(remaining_fields);
1642
0
        if (!remaining_list) {
1643
0
            goto set_remaining_cleanup;
1644
0
        }
1645
0
        missing_names = PySet_New(NULL);
1646
0
        if (!missing_names) {
1647
0
            goto set_remaining_cleanup;
1648
0
        }
1649
0
        for (Py_ssize_t i = 0; i < size; i++) {
1650
0
            PyObject *name = PyList_GET_ITEM(remaining_list, i);
1651
0
            PyObject *type = PyDict_GetItemWithError(field_types, name);
1652
0
            if (!type) {
1653
0
                if (PyErr_Occurred()) {
1654
0
                    goto set_remaining_cleanup;
1655
0
                }
1656
0
                else {
1657
0
                    PyErr_Format(PyExc_TypeError,
1658
0
                        "Field %R is missing from %T._field_types",
1659
0
                        name, self);
1660
0
                    goto set_remaining_cleanup;
1661
0
                }
1662
0
            }
1663
0
            else if (_PyUnion_Check(type)) {
1664
                // optional field
1665
                // do nothing, we'll have set a None default on the class
1666
0
            }
1667
0
            else if (Py_IS_TYPE(type, &Py_GenericAliasType)) {
1668
                // list field
1669
0
                PyObject *empty = PyList_New(0);
1670
0
                if (!empty) {
1671
0
                    goto set_remaining_cleanup;
1672
0
                }
1673
0
                res = PyObject_SetAttr(self, name, empty);
1674
0
                Py_DECREF(empty);
1675
0
                if (res < 0) {
1676
0
                    goto set_remaining_cleanup;
1677
0
                }
1678
0
            }
1679
0
            else if (type == state->expr_context_type) {
1680
                // special case for expr_context: default to Load()
1681
0
                res = PyObject_SetAttr(self, name, state->Load_singleton);
1682
0
                if (res < 0) {
1683
0
                    goto set_remaining_cleanup;
1684
0
                }
1685
0
            }
1686
0
            else {
1687
                // simple field (e.g., identifier)
1688
0
                res = PySet_Add(missing_names, name);
1689
0
                if (res < 0) {
1690
0
                    goto set_remaining_cleanup;
1691
0
                }
1692
0
            }
1693
0
        }
1694
0
        Py_ssize_t num_missing = PySet_GET_SIZE(missing_names);
1695
0
        if (num_missing > 0) {
1696
0
            PyObject *name_str = format_missing(missing_names, fields);
1697
0
            if (!name_str) {
1698
0
                goto set_remaining_cleanup;
1699
0
            }
1700
0
            PyErr_Format(PyExc_TypeError,
1701
0
                "%T.__init__ missing %d required positional argument%s: %U",
1702
0
                self, num_missing, num_missing == 1 ? "" : "s", name_str);
1703
0
            Py_DECREF(name_str);
1704
0
            goto set_remaining_cleanup;
1705
0
        }
1706
0
        Py_DECREF(missing_names);
1707
0
        Py_DECREF(remaining_list);
1708
0
        Py_DECREF(field_types);
1709
0
    }
1710
0
  cleanup:
1711
0
    Py_XDECREF(attributes);
1712
0
    Py_XDECREF(fields);
1713
0
    Py_XDECREF(remaining_fields);
1714
0
    return res;
1715
0
  set_remaining_cleanup:
1716
0
    Py_XDECREF(missing_names);
1717
0
    Py_XDECREF(remaining_list);
1718
0
    Py_XDECREF(field_types);
1719
0
    res = -1;
1720
0
    goto cleanup;
1721
0
}
1722
1723
/* Pickling support */
1724
static PyObject *
1725
ast_type_reduce(PyObject *self, PyObject *unused)
1726
0
{
1727
0
    struct ast_state *state = get_ast_state();
1728
0
    if (state == NULL) {
1729
0
        return NULL;
1730
0
    }
1731
1732
0
    PyObject *dict = NULL, *fields = NULL, *positional_args = NULL;
1733
0
    if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
1734
0
        return NULL;
1735
0
    }
1736
0
    PyObject *result = NULL;
1737
0
    if (dict) {
1738
        // Unpickling (or copying) works as follows:
1739
        // - Construct the object with only positional arguments
1740
        // - Set the fields from the dict
1741
        // We have two constraints:
1742
        // - We must set all the required fields in the initial constructor call,
1743
        //   or the unpickling or deepcopying of the object will trigger DeprecationWarnings.
1744
        // - We must not include child nodes in the positional args, because
1745
        //   that may trigger runaway recursion during copying (gh-120108).
1746
        // To satisfy both constraints, we set all the fields to None in the
1747
        // initial list of positional args, and then set the fields from the dict.
1748
0
        if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
1749
0
            goto cleanup;
1750
0
        }
1751
0
        if (fields) {
1752
0
            Py_ssize_t numfields = PySequence_Size(fields);
1753
0
            if (numfields == -1) {
1754
0
                Py_DECREF(dict);
1755
0
                goto cleanup;
1756
0
            }
1757
0
            positional_args = PyList_New(0);
1758
0
            if (!positional_args) {
1759
0
                goto cleanup;
1760
0
            }
1761
0
            for (Py_ssize_t i = 0; i < numfields; i++) {
1762
0
                PyObject *name = PySequence_GetItem(fields, i);
1763
0
                if (!name) {
1764
0
                    goto cleanup;
1765
0
                }
1766
0
                PyObject *value;
1767
0
                int rc = PyDict_GetItemRef(dict, name, &value);
1768
0
                Py_DECREF(name);
1769
0
                if (rc < 0) {
1770
0
                    goto cleanup;
1771
0
                }
1772
0
                if (!value) {
1773
0
                    break;
1774
0
                }
1775
0
                rc = PyList_Append(positional_args, Py_None);
1776
0
                Py_DECREF(value);
1777
0
                if (rc < 0) {
1778
0
                    goto cleanup;
1779
0
                }
1780
0
            }
1781
0
            PyObject *args_tuple = PyList_AsTuple(positional_args);
1782
0
            if (!args_tuple) {
1783
0
                goto cleanup;
1784
0
            }
1785
0
            result = Py_BuildValue("ONN", Py_TYPE(self), args_tuple, dict);
1786
0
        }
1787
0
        else {
1788
0
            result = Py_BuildValue("O()N", Py_TYPE(self), dict);
1789
0
        }
1790
0
    }
1791
0
    else {
1792
0
        result = Py_BuildValue("O()", Py_TYPE(self));
1793
0
    }
1794
0
cleanup:
1795
0
    Py_XDECREF(fields);
1796
0
    Py_XDECREF(positional_args);
1797
0
    return result;
1798
0
}
1799
1800
/*
1801
 * Python equivalent:
1802
 *
1803
 *   for key in keys:
1804
 *       if hasattr(self, key):
1805
 *           payload[key] = getattr(self, key)
1806
 *
1807
 * The 'keys' argument is a sequence corresponding to
1808
 * the '_fields' or the '_attributes' of an AST node.
1809
 *
1810
 * This returns -1 if an error occurs and 0 otherwise.
1811
 *
1812
 * Parameters
1813
 *
1814
 *      payload   A dictionary to fill.
1815
 *      keys      A sequence of keys or NULL for an empty sequence.
1816
 *      dict      The AST node instance dictionary (must not be NULL).
1817
 */
1818
static inline int
1819
ast_type_replace_update_payload(PyObject *payload,
1820
                                PyObject *keys,
1821
                                PyObject *dict)
1822
0
{
1823
0
    assert(dict != NULL);
1824
0
    if (keys == NULL) {
1825
0
        return 0;
1826
0
    }
1827
0
    Py_ssize_t n = PySequence_Size(keys);
1828
0
    if (n == -1) {
1829
0
        return -1;
1830
0
    }
1831
0
    for (Py_ssize_t i = 0; i < n; i++) {
1832
0
        PyObject *key = PySequence_GetItem(keys, i);
1833
0
        if (key == NULL) {
1834
0
            return -1;
1835
0
        }
1836
0
        PyObject *value;
1837
0
        if (PyDict_GetItemRef(dict, key, &value) < 0) {
1838
0
            Py_DECREF(key);
1839
0
            return -1;
1840
0
        }
1841
0
        if (value == NULL) {
1842
0
            Py_DECREF(key);
1843
            // If a field or attribute is not present at runtime, it should
1844
            // be explicitly given in 'kwargs'. If not, the constructor will
1845
            // issue a warning (which becomes an error in 3.15).
1846
0
            continue;
1847
0
        }
1848
0
        int rc = PyDict_SetItem(payload, key, value);
1849
0
        Py_DECREF(key);
1850
0
        Py_DECREF(value);
1851
0
        if (rc < 0) {
1852
0
            return -1;
1853
0
        }
1854
0
    }
1855
0
    return 0;
1856
0
}
1857
1858
/* copy.replace() support (shallow copy) */
1859
static PyObject *
1860
ast_type_replace(PyObject *self, PyObject *args, PyObject *kwargs)
1861
0
{
1862
0
    if (!_PyArg_NoPositional("__replace__", args)) {
1863
0
        return NULL;
1864
0
    }
1865
1866
0
    struct ast_state *state = get_ast_state();
1867
0
    if (state == NULL) {
1868
0
        return NULL;
1869
0
    }
1870
1871
0
    PyObject *result = NULL;
1872
    // known AST class fields and attributes
1873
0
    PyObject *fields = NULL, *attributes = NULL;
1874
    // current instance dictionary
1875
0
    PyObject *dict = NULL;
1876
    // constructor positional and keyword arguments
1877
0
    PyObject *empty_tuple = NULL, *payload = NULL;
1878
1879
0
    PyObject *type = (PyObject *)Py_TYPE(self);
1880
0
    if (PyObject_GetOptionalAttr(type, state->_fields, &fields) < 0) {
1881
0
        goto cleanup;
1882
0
    }
1883
0
    if (PyObject_GetOptionalAttr(type, state->_attributes, &attributes) < 0) {
1884
0
        goto cleanup;
1885
0
    }
1886
0
    if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
1887
0
        goto cleanup;
1888
0
    }
1889
0
    empty_tuple = PyTuple_New(0);
1890
0
    if (empty_tuple == NULL) {
1891
0
        goto cleanup;
1892
0
    }
1893
0
    payload = PyDict_New();
1894
0
    if (payload == NULL) {
1895
0
        goto cleanup;
1896
0
    }
1897
0
    if (dict) { // in case __dict__ is missing (for some obscure reason)
1898
        // copy the instance's fields (possibly NULL)
1899
0
        if (ast_type_replace_update_payload(payload, fields, dict) < 0) {
1900
0
            goto cleanup;
1901
0
        }
1902
        // copy the instance's attributes (possibly NULL)
1903
0
        if (ast_type_replace_update_payload(payload, attributes, dict) < 0) {
1904
0
            goto cleanup;
1905
0
        }
1906
0
    }
1907
0
    if (kwargs && PyDict_Update(payload, kwargs) < 0) {
1908
0
        goto cleanup;
1909
0
    }
1910
0
    result = PyObject_Call(type, empty_tuple, payload);
1911
0
cleanup:
1912
0
    Py_XDECREF(payload);
1913
0
    Py_XDECREF(empty_tuple);
1914
0
    Py_XDECREF(dict);
1915
0
    Py_XDECREF(attributes);
1916
0
    Py_XDECREF(fields);
1917
0
    return result;
1918
0
}
1919
1920
static PyMethodDef ast_type_methods[] = {
1921
    {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1922
    {"__replace__", _PyCFunction_CAST(ast_type_replace), METH_VARARGS | METH_KEYWORDS,
1923
     PyDoc_STR("__replace__($self, /, **fields)\n--\n\n"
1924
               "Return a copy of the AST node with new values "
1925
               "for the specified fields.")},
1926
    {NULL}
1927
};
1928
1929
static PyGetSetDef ast_type_getsets[] = {
1930
    {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1931
    {NULL}
1932
};
1933
1934
static PyObject *
1935
ast_repr_max_depth(AST_object *self, int depth);
1936
1937
/* Format list and tuple properties of AST nodes.
1938
   Note that, only the first and last elements are shown.
1939
   Anything in between is represented with an ellipsis ('...').
1940
   For example, the list [1, 2, 3] is formatted as
1941
   'List(elts=[Constant(1), ..., Constant(3)])'. */
1942
static PyObject *
1943
ast_repr_list(PyObject *list, int depth)
1944
4
{
1945
4
    assert(PyList_Check(list) || PyTuple_Check(list));
1946
1947
4
    struct ast_state *state = get_ast_state();
1948
4
    if (state == NULL) {
1949
0
        return NULL;
1950
0
    }
1951
1952
4
    Py_ssize_t length = PySequence_Size(list);
1953
4
    if (length < 0) {
1954
0
        return NULL;
1955
0
    }
1956
4
    else if (length == 0) {
1957
0
        return PyObject_Repr(list);
1958
0
    }
1959
1960
4
    PyObject *items[2] = {NULL, NULL};
1961
4
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
1962
4
    if (writer == NULL) {
1963
0
        goto error;
1964
0
    }
1965
1966
4
    items[0] = PySequence_GetItem(list, 0);
1967
4
    if (!items[0]) {
1968
0
        goto error;
1969
0
    }
1970
4
    if (length > 1) {
1971
4
        items[1] = PySequence_GetItem(list, length - 1);
1972
4
        if (!items[1]) {
1973
0
            goto error;
1974
0
        }
1975
4
    }
1976
1977
4
    bool is_list = PyList_Check(list);
1978
4
    if (PyUnicodeWriter_WriteChar(writer, is_list ? '[' : '(') < 0) {
1979
0
        goto error;
1980
0
    }
1981
1982
12
    for (Py_ssize_t i = 0; i < Py_MIN(length, 2); i++) {
1983
8
        if (i > 0) {
1984
4
            if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
1985
0
                goto error;
1986
0
            }
1987
4
        }
1988
1989
8
        PyObject *item = items[i];
1990
8
        if (PyType_IsSubtype(Py_TYPE(item), (PyTypeObject *)state->AST_type)) {
1991
8
            PyObject *item_repr;
1992
8
            item_repr = ast_repr_max_depth((AST_object*)item, depth - 1);
1993
8
            if (!item_repr) {
1994
0
                goto error;
1995
0
            }
1996
8
            if (PyUnicodeWriter_WriteStr(writer, item_repr) < 0) {
1997
0
                Py_DECREF(item_repr);
1998
0
                goto error;
1999
0
            }
2000
8
            Py_DECREF(item_repr);
2001
8
        } else {
2002
0
            if (PyUnicodeWriter_WriteRepr(writer, item) < 0) {
2003
0
                goto error;
2004
0
            }
2005
0
        }
2006
2007
8
        if (i == 0 && length > 2) {
2008
0
            if (PyUnicodeWriter_WriteASCII(writer, ", ...", 5) < 0) {
2009
0
                goto error;
2010
0
            }
2011
0
        }
2012
8
    }
2013
2014
4
    if (PyUnicodeWriter_WriteChar(writer, is_list ? ']' : ')') < 0) {
2015
0
        goto error;
2016
0
    }
2017
2018
4
    Py_XDECREF(items[0]);
2019
4
    Py_XDECREF(items[1]);
2020
4
    return PyUnicodeWriter_Finish(writer);
2021
2022
0
error:
2023
0
    Py_XDECREF(items[0]);
2024
0
    Py_XDECREF(items[1]);
2025
0
    PyUnicodeWriter_Discard(writer);
2026
0
    return NULL;
2027
4
}
2028
2029
static PyObject *
2030
ast_repr_max_depth(AST_object *self, int depth)
2031
29
{
2032
29
    struct ast_state *state = get_ast_state();
2033
29
    if (state == NULL) {
2034
0
        return NULL;
2035
0
    }
2036
2037
29
    PyObject *fields = PyObject_GetAttr((PyObject *)Py_TYPE(self), state->_fields);
2038
29
    if (!fields) {
2039
0
        return NULL;
2040
0
    }
2041
2042
29
    Py_ssize_t numfields = PySequence_Size(fields);
2043
29
    if (numfields < 0) {
2044
0
        Py_DECREF(fields);
2045
0
        return NULL;
2046
0
    }
2047
2048
29
    if (numfields == 0) {
2049
5
        Py_DECREF(fields);
2050
5
        return PyUnicode_FromFormat("%s()", Py_TYPE(self)->tp_name);
2051
5
    }
2052
2053
24
    if (depth <= 0) {
2054
0
        Py_DECREF(fields);
2055
0
        return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
2056
0
    }
2057
2058
24
    int status = Py_ReprEnter((PyObject *)self);
2059
24
    if (status != 0) {
2060
0
        Py_DECREF(fields);
2061
0
        if (status < 0) {
2062
0
            return NULL;
2063
0
        }
2064
0
        return PyUnicode_FromFormat("%s(...)", Py_TYPE(self)->tp_name);
2065
0
    }
2066
2067
24
    const char* tp_name = Py_TYPE(self)->tp_name;
2068
24
    PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
2069
24
    if (writer == NULL) {
2070
0
        goto error;
2071
0
    }
2072
2073
24
    if (PyUnicodeWriter_WriteUTF8(writer, tp_name, -1) < 0) {
2074
0
        goto error;
2075
0
    }
2076
24
    if (PyUnicodeWriter_WriteChar(writer, '(') < 0) {
2077
0
        goto error;
2078
0
    }
2079
2080
78
    for (Py_ssize_t i = 0; i < numfields; i++) {
2081
54
        PyObject *name = PySequence_GetItem(fields, i);
2082
54
        if (!name) {
2083
0
            goto error;
2084
0
        }
2085
2086
54
        PyObject *value = PyObject_GetAttr((PyObject *)self, name);
2087
54
        if (!value) {
2088
0
            Py_DECREF(name);
2089
0
            goto error;
2090
0
        }
2091
2092
54
        PyObject *value_repr;
2093
54
        if (PyList_Check(value) || PyTuple_Check(value)) {
2094
4
            value_repr = ast_repr_list(value, depth);
2095
4
        }
2096
50
        else if (PyType_IsSubtype(Py_TYPE(value), (PyTypeObject *)state->AST_type)) {
2097
13
            value_repr = ast_repr_max_depth((AST_object*)value, depth - 1);
2098
13
        }
2099
37
        else {
2100
37
            value_repr = PyObject_Repr(value);
2101
37
        }
2102
2103
54
        Py_DECREF(value);
2104
2105
54
        if (!value_repr) {
2106
0
            Py_DECREF(name);
2107
0
            goto error;
2108
0
        }
2109
2110
54
        if (i > 0) {
2111
30
            if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
2112
0
                Py_DECREF(name);
2113
0
                Py_DECREF(value_repr);
2114
0
                goto error;
2115
0
            }
2116
30
        }
2117
54
        if (PyUnicodeWriter_WriteStr(writer, name) < 0) {
2118
0
            Py_DECREF(name);
2119
0
            Py_DECREF(value_repr);
2120
0
            goto error;
2121
0
        }
2122
2123
54
        Py_DECREF(name);
2124
2125
54
        if (PyUnicodeWriter_WriteChar(writer, '=') < 0) {
2126
0
            Py_DECREF(value_repr);
2127
0
            goto error;
2128
0
        }
2129
54
        if (PyUnicodeWriter_WriteStr(writer, value_repr) < 0) {
2130
0
            Py_DECREF(value_repr);
2131
0
            goto error;
2132
0
        }
2133
2134
54
        Py_DECREF(value_repr);
2135
54
    }
2136
2137
24
    if (PyUnicodeWriter_WriteChar(writer, ')') < 0) {
2138
0
        goto error;
2139
0
    }
2140
24
    Py_ReprLeave((PyObject *)self);
2141
24
    Py_DECREF(fields);
2142
24
    return PyUnicodeWriter_Finish(writer);
2143
2144
0
error:
2145
0
    Py_ReprLeave((PyObject *)self);
2146
0
    Py_DECREF(fields);
2147
0
    PyUnicodeWriter_Discard(writer);
2148
0
    return NULL;
2149
24
}
2150
2151
static PyObject *
2152
ast_repr(PyObject *self)
2153
8
{
2154
8
    return ast_repr_max_depth((AST_object*)self, 3);
2155
8
}
2156
2157
static PyType_Slot AST_type_slots[] = {
2158
    {Py_tp_dealloc, ast_dealloc},
2159
    {Py_tp_repr, ast_repr},
2160
    {Py_tp_getattro, PyObject_GenericGetAttr},
2161
    {Py_tp_setattro, PyObject_GenericSetAttr},
2162
    {Py_tp_traverse, ast_traverse},
2163
    {Py_tp_clear, ast_clear},
2164
    {Py_tp_methods, ast_type_methods},
2165
    {Py_tp_getset, ast_type_getsets},
2166
    {Py_tp_init, ast_type_init},
2167
    {Py_tp_alloc, PyType_GenericAlloc},
2168
    {Py_tp_new, PyType_GenericNew},
2169
    {Py_tp_free, PyObject_GC_Del},
2170
    {0, 0},
2171
};
2172
2173
static PyType_Spec AST_type_spec = {
2174
    "ast.AST",
2175
    sizeof(AST_object),
2176
    0,
2177
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
2178
    Py_TPFLAGS_MANAGED_DICT,
2179
    AST_type_slots
2180
};
2181
2182
static PyObject *
2183
make_type(struct ast_state *state, const char *type, PyObject* base,
2184
          const char* const* fields, int num_fields, const char *doc)
2185
250
{
2186
250
    PyObject *fnames, *result;
2187
250
    int i;
2188
250
    fnames = PyTuple_New(num_fields);
2189
250
    if (!fnames) return NULL;
2190
646
    for (i = 0; i < num_fields; i++) {
2191
396
        PyObject *field = PyUnicode_InternFromString(fields[i]);
2192
396
        if (!field) {
2193
0
            Py_DECREF(fnames);
2194
0
            return NULL;
2195
0
        }
2196
396
        PyTuple_SET_ITEM(fnames, i, field);
2197
396
    }
2198
250
    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
2199
250
                    type, base,
2200
250
                    state->_fields, fnames,
2201
250
                    state->__match_args__, fnames,
2202
250
                    state->__module__,
2203
250
                    state->ast,
2204
250
                    state->__doc__, doc);
2205
250
    Py_DECREF(fnames);
2206
250
    return result;
2207
250
}
2208
2209
static int
2210
add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
2211
38
{
2212
38
    int i, result;
2213
38
    PyObject *s, *l = PyTuple_New(num_fields);
2214
38
    if (!l)
2215
0
        return -1;
2216
102
    for (i = 0; i < num_fields; i++) {
2217
64
        s = PyUnicode_InternFromString(attrs[i]);
2218
64
        if (!s) {
2219
0
            Py_DECREF(l);
2220
0
            return -1;
2221
0
        }
2222
64
        PyTuple_SET_ITEM(l, i, s);
2223
64
    }
2224
38
    result = PyObject_SetAttr(type, state->_attributes, l);
2225
38
    Py_DECREF(l);
2226
38
    return result;
2227
38
}
2228
2229
/* Conversion AST -> Python */
2230
2231
static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq,
2232
                              PyObject* (*func)(struct ast_state *state, void*))
2233
40.6k
{
2234
40.6k
    Py_ssize_t i, n = asdl_seq_LEN(seq);
2235
40.6k
    PyObject *result = PyList_New(n);
2236
40.6k
    PyObject *value;
2237
40.6k
    if (!result)
2238
0
        return NULL;
2239
117k
    for (i = 0; i < n; i++) {
2240
76.7k
        value = func(state, asdl_seq_GET_UNTYPED(seq, i));
2241
76.7k
        if (!value) {
2242
0
            Py_DECREF(result);
2243
0
            return NULL;
2244
0
        }
2245
76.7k
        PyList_SET_ITEM(result, i, value);
2246
76.7k
    }
2247
40.6k
    return result;
2248
40.6k
}
2249
2250
static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
2251
200k
{
2252
200k
    PyObject *op = (PyObject*)o;
2253
200k
    if (!op) {
2254
73.4k
        op = Py_None;
2255
73.4k
    }
2256
200k
    return Py_NewRef(op);
2257
200k
}
2258
64.7k
#define ast2obj_constant ast2obj_object
2259
65.3k
#define ast2obj_identifier ast2obj_object
2260
70.6k
#define ast2obj_string ast2obj_object
2261
2262
static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
2263
1.29M
{
2264
1.29M
    return PyLong_FromLong(b);
2265
1.29M
}
2266
2267
/* Conversion Python -> AST */
2268
2269
static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj,
2270
                          PyObject** out,
2271
                          const char* Py_UNUSED(field), PyArena* arena)
2272
0
{
2273
0
    if (obj == Py_None)
2274
0
        obj = NULL;
2275
0
    if (obj) {
2276
0
        if (_PyArena_AddPyObject(arena, obj) < 0) {
2277
0
            *out = NULL;
2278
0
            return -1;
2279
0
        }
2280
0
        *out = Py_NewRef(obj);
2281
0
    }
2282
0
    else {
2283
0
        *out = NULL;
2284
0
    }
2285
0
    return 0;
2286
0
}
2287
2288
static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj,
2289
                            PyObject** out,
2290
                            const char* Py_UNUSED(field), PyArena* arena)
2291
0
{
2292
0
    if (_PyArena_AddPyObject(arena, obj) < 0) {
2293
0
        *out = NULL;
2294
0
        return -1;
2295
0
    }
2296
0
    *out = Py_NewRef(obj);
2297
0
    return 0;
2298
0
}
2299
2300
static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
2301
0
{
2302
0
    if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
2303
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string object, got %T", field, obj);
2304
0
        return -1;
2305
0
    }
2306
0
    return obj2ast_object(state, obj, out, field, arena);
2307
0
}
2308
2309
static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
2310
0
{
2311
0
    if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
2312
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string or bytes object, got %T", field, obj);
2313
0
        return -1;
2314
0
    }
2315
0
    return obj2ast_object(state, obj, out, field, arena);
2316
0
}
2317
2318
static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, const char* field, PyArena* arena)
2319
0
{
2320
0
    int i;
2321
0
    if (!PyLong_Check(obj)) {
2322
0
        PyErr_Format(PyExc_ValueError, "field \"%s\" got an invalid integer value: %R", field, obj);
2323
0
        return -1;
2324
0
    }
2325
2326
0
    i = PyLong_AsInt(obj);
2327
0
    if (i == -1 && PyErr_Occurred())
2328
0
        return -1;
2329
0
    *out = i;
2330
0
    return 0;
2331
0
}
2332
2333
static int add_ast_fields(struct ast_state *state)
2334
2
{
2335
2
    PyObject *empty_tuple;
2336
2
    empty_tuple = PyTuple_New(0);
2337
2
    if (!empty_tuple ||
2338
2
        PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
2339
2
        PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
2340
2
        PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
2341
0
        Py_XDECREF(empty_tuple);
2342
0
        return -1;
2343
0
    }
2344
2
    Py_DECREF(empty_tuple);
2345
2
    return 0;
2346
2
}
2347
2348
2349
2350
static int
2351
init_types(void *arg)
2352
2
{
2353
2
    struct ast_state *state = arg;
2354
2
    if (init_identifiers(state) < 0) {
2355
0
        return -1;
2356
0
    }
2357
2
    state->AST_type = PyType_FromSpec(&AST_type_spec);
2358
2
    if (!state->AST_type) {
2359
0
        return -1;
2360
0
    }
2361
2
    state->abstract_types = PySet_New(NULL);
2362
2
    if (!state->abstract_types) {
2363
0
        return -1;
2364
0
    }
2365
2
    if (PySet_Add(state->abstract_types, state->AST_type) < 0) {
2366
0
        return -1;
2367
0
    }
2368
2
    if (add_ast_fields(state) < 0) {
2369
0
        return -1;
2370
0
    }
2371
2
    state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
2372
2
        "mod = Module(stmt* body, type_ignore* type_ignores)\n"
2373
2
        "    | Interactive(stmt* body)\n"
2374
2
        "    | Expression(expr body)\n"
2375
2
        "    | FunctionType(expr* argtypes, expr returns)");
2376
2
    if (!state->mod_type) return -1;
2377
2
    if (add_attributes(state, state->mod_type, NULL, 0) < 0) return -1;
2378
2
    if (PySet_Add(state->abstract_types, state->mod_type) < 0) return -1;
2379
2
    state->Module_type = make_type(state, "Module", state->mod_type,
2380
2
                                   Module_fields, 2,
2381
2
        "Module(stmt* body, type_ignore* type_ignores)");
2382
2
    if (!state->Module_type) return -1;
2383
2
    state->Interactive_type = make_type(state, "Interactive", state->mod_type,
2384
2
                                        Interactive_fields, 1,
2385
2
        "Interactive(stmt* body)");
2386
2
    if (!state->Interactive_type) return -1;
2387
2
    state->Expression_type = make_type(state, "Expression", state->mod_type,
2388
2
                                       Expression_fields, 1,
2389
2
        "Expression(expr body)");
2390
2
    if (!state->Expression_type) return -1;
2391
2
    state->FunctionType_type = make_type(state, "FunctionType",
2392
2
                                         state->mod_type, FunctionType_fields,
2393
2
                                         2,
2394
2
        "FunctionType(expr* argtypes, expr returns)");
2395
2
    if (!state->FunctionType_type) return -1;
2396
2
    state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
2397
2
        "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
2398
2
        "     | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
2399
2
        "     | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
2400
2
        "     | Return(expr? value)\n"
2401
2
        "     | Delete(expr* targets)\n"
2402
2
        "     | Assign(expr* targets, expr value, string? type_comment)\n"
2403
2
        "     | TypeAlias(expr name, type_param* type_params, expr value)\n"
2404
2
        "     | AugAssign(expr target, operator op, expr value)\n"
2405
2
        "     | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
2406
2
        "     | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
2407
2
        "     | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
2408
2
        "     | While(expr test, stmt* body, stmt* orelse)\n"
2409
2
        "     | If(expr test, stmt* body, stmt* orelse)\n"
2410
2
        "     | With(withitem* items, stmt* body, string? type_comment)\n"
2411
2
        "     | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
2412
2
        "     | Match(expr subject, match_case* cases)\n"
2413
2
        "     | Raise(expr? exc, expr? cause)\n"
2414
2
        "     | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
2415
2
        "     | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
2416
2
        "     | Assert(expr test, expr? msg)\n"
2417
2
        "     | Import(alias* names, int? is_lazy)\n"
2418
2
        "     | ImportFrom(identifier? module, alias* names, int? level, int? is_lazy)\n"
2419
2
        "     | Global(identifier* names)\n"
2420
2
        "     | Nonlocal(identifier* names)\n"
2421
2
        "     | Expr(expr value)\n"
2422
2
        "     | Pass\n"
2423
2
        "     | Break\n"
2424
2
        "     | Continue");
2425
2
    if (!state->stmt_type) return -1;
2426
2
    if (add_attributes(state, state->stmt_type, stmt_attributes, 4) < 0) return
2427
0
        -1;
2428
2
    if (PySet_Add(state->abstract_types, state->stmt_type) < 0) return -1;
2429
2
    if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
2430
0
        return -1;
2431
2
    if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
2432
2
        -1)
2433
0
        return -1;
2434
2
    state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
2435
2
                                        FunctionDef_fields, 7,
2436
2
        "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
2437
2
    if (!state->FunctionDef_type) return -1;
2438
2
    if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
2439
2
        -1)
2440
0
        return -1;
2441
2
    if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
2442
2
        == -1)
2443
0
        return -1;
2444
2
    state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
2445
2
                                             state->stmt_type,
2446
2
                                             AsyncFunctionDef_fields, 7,
2447
2
        "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
2448
2
    if (!state->AsyncFunctionDef_type) return -1;
2449
2
    if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
2450
2
        == -1)
2451
0
        return -1;
2452
2
    if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
2453
2
        Py_None) == -1)
2454
0
        return -1;
2455
2
    state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
2456
2
                                     ClassDef_fields, 6,
2457
2
        "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
2458
2
    if (!state->ClassDef_type) return -1;
2459
2
    state->Return_type = make_type(state, "Return", state->stmt_type,
2460
2
                                   Return_fields, 1,
2461
2
        "Return(expr? value)");
2462
2
    if (!state->Return_type) return -1;
2463
2
    if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
2464
0
        return -1;
2465
2
    state->Delete_type = make_type(state, "Delete", state->stmt_type,
2466
2
                                   Delete_fields, 1,
2467
2
        "Delete(expr* targets)");
2468
2
    if (!state->Delete_type) return -1;
2469
2
    state->Assign_type = make_type(state, "Assign", state->stmt_type,
2470
2
                                   Assign_fields, 3,
2471
2
        "Assign(expr* targets, expr value, string? type_comment)");
2472
2
    if (!state->Assign_type) return -1;
2473
2
    if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
2474
2
        -1)
2475
0
        return -1;
2476
2
    state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
2477
2
                                      TypeAlias_fields, 3,
2478
2
        "TypeAlias(expr name, type_param* type_params, expr value)");
2479
2
    if (!state->TypeAlias_type) return -1;
2480
2
    state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
2481
2
                                      AugAssign_fields, 3,
2482
2
        "AugAssign(expr target, operator op, expr value)");
2483
2
    if (!state->AugAssign_type) return -1;
2484
2
    state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
2485
2
                                      AnnAssign_fields, 4,
2486
2
        "AnnAssign(expr target, expr annotation, expr? value, int simple)");
2487
2
    if (!state->AnnAssign_type) return -1;
2488
2
    if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
2489
0
        return -1;
2490
2
    state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
2491
2
        "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
2492
2
    if (!state->For_type) return -1;
2493
2
    if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
2494
0
        return -1;
2495
2
    state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
2496
2
                                     AsyncFor_fields, 5,
2497
2
        "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
2498
2
    if (!state->AsyncFor_type) return -1;
2499
2
    if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
2500
2
        -1)
2501
0
        return -1;
2502
2
    state->While_type = make_type(state, "While", state->stmt_type,
2503
2
                                  While_fields, 3,
2504
2
        "While(expr test, stmt* body, stmt* orelse)");
2505
2
    if (!state->While_type) return -1;
2506
2
    state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
2507
2
        "If(expr test, stmt* body, stmt* orelse)");
2508
2
    if (!state->If_type) return -1;
2509
2
    state->With_type = make_type(state, "With", state->stmt_type, With_fields,
2510
2
                                 3,
2511
2
        "With(withitem* items, stmt* body, string? type_comment)");
2512
2
    if (!state->With_type) return -1;
2513
2
    if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
2514
0
        return -1;
2515
2
    state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
2516
2
                                      AsyncWith_fields, 3,
2517
2
        "AsyncWith(withitem* items, stmt* body, string? type_comment)");
2518
2
    if (!state->AsyncWith_type) return -1;
2519
2
    if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
2520
2
        == -1)
2521
0
        return -1;
2522
2
    state->Match_type = make_type(state, "Match", state->stmt_type,
2523
2
                                  Match_fields, 2,
2524
2
        "Match(expr subject, match_case* cases)");
2525
2
    if (!state->Match_type) return -1;
2526
2
    state->Raise_type = make_type(state, "Raise", state->stmt_type,
2527
2
                                  Raise_fields, 2,
2528
2
        "Raise(expr? exc, expr? cause)");
2529
2
    if (!state->Raise_type) return -1;
2530
2
    if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
2531
0
        return -1;
2532
2
    if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
2533
0
        return -1;
2534
2
    state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
2535
2
        "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
2536
2
    if (!state->Try_type) return -1;
2537
2
    state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
2538
2
                                    TryStar_fields, 4,
2539
2
        "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
2540
2
    if (!state->TryStar_type) return -1;
2541
2
    state->Assert_type = make_type(state, "Assert", state->stmt_type,
2542
2
                                   Assert_fields, 2,
2543
2
        "Assert(expr test, expr? msg)");
2544
2
    if (!state->Assert_type) return -1;
2545
2
    if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
2546
0
        return -1;
2547
2
    state->Import_type = make_type(state, "Import", state->stmt_type,
2548
2
                                   Import_fields, 2,
2549
2
        "Import(alias* names, int? is_lazy)");
2550
2
    if (!state->Import_type) return -1;
2551
2
    if (PyObject_SetAttr(state->Import_type, state->is_lazy, Py_None) == -1)
2552
0
        return -1;
2553
2
    state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
2554
2
                                       ImportFrom_fields, 4,
2555
2
        "ImportFrom(identifier? module, alias* names, int? level, int? is_lazy)");
2556
2
    if (!state->ImportFrom_type) return -1;
2557
2
    if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
2558
0
        return -1;
2559
2
    if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
2560
0
        return -1;
2561
2
    if (PyObject_SetAttr(state->ImportFrom_type, state->is_lazy, Py_None) == -1)
2562
0
        return -1;
2563
2
    state->Global_type = make_type(state, "Global", state->stmt_type,
2564
2
                                   Global_fields, 1,
2565
2
        "Global(identifier* names)");
2566
2
    if (!state->Global_type) return -1;
2567
2
    state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
2568
2
                                     Nonlocal_fields, 1,
2569
2
        "Nonlocal(identifier* names)");
2570
2
    if (!state->Nonlocal_type) return -1;
2571
2
    state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
2572
2
                                 1,
2573
2
        "Expr(expr value)");
2574
2
    if (!state->Expr_type) return -1;
2575
2
    state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
2576
2
        "Pass");
2577
2
    if (!state->Pass_type) return -1;
2578
2
    state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
2579
2
        "Break");
2580
2
    if (!state->Break_type) return -1;
2581
2
    state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
2582
2
                                     0,
2583
2
        "Continue");
2584
2
    if (!state->Continue_type) return -1;
2585
2
    state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
2586
2
        "expr = BoolOp(boolop op, expr* values)\n"
2587
2
        "     | NamedExpr(expr target, expr value)\n"
2588
2
        "     | BinOp(expr left, operator op, expr right)\n"
2589
2
        "     | UnaryOp(unaryop op, expr operand)\n"
2590
2
        "     | Lambda(arguments args, expr body)\n"
2591
2
        "     | IfExp(expr test, expr body, expr orelse)\n"
2592
2
        "     | Dict(expr?* keys, expr* values)\n"
2593
2
        "     | Set(expr* elts)\n"
2594
2
        "     | ListComp(expr elt, comprehension* generators)\n"
2595
2
        "     | SetComp(expr elt, comprehension* generators)\n"
2596
2
        "     | DictComp(expr key, expr? value, comprehension* generators)\n"
2597
2
        "     | GeneratorExp(expr elt, comprehension* generators)\n"
2598
2
        "     | Await(expr value)\n"
2599
2
        "     | Yield(expr? value)\n"
2600
2
        "     | YieldFrom(expr value)\n"
2601
2
        "     | Compare(expr left, cmpop* ops, expr* comparators)\n"
2602
2
        "     | Call(expr func, expr* args, keyword* keywords)\n"
2603
2
        "     | FormattedValue(expr value, int conversion, expr? format_spec)\n"
2604
2
        "     | Interpolation(expr value, constant str, int conversion, expr? format_spec)\n"
2605
2
        "     | JoinedStr(expr* values)\n"
2606
2
        "     | TemplateStr(expr* values)\n"
2607
2
        "     | Constant(constant value, string? kind)\n"
2608
2
        "     | Attribute(expr value, identifier attr, expr_context ctx)\n"
2609
2
        "     | Subscript(expr value, expr slice, expr_context ctx)\n"
2610
2
        "     | Starred(expr value, expr_context ctx)\n"
2611
2
        "     | Name(identifier id, expr_context ctx)\n"
2612
2
        "     | List(expr* elts, expr_context ctx)\n"
2613
2
        "     | Tuple(expr* elts, expr_context ctx)\n"
2614
2
        "     | Slice(expr? lower, expr? upper, expr? step)");
2615
2
    if (!state->expr_type) return -1;
2616
2
    if (add_attributes(state, state->expr_type, expr_attributes, 4) < 0) return
2617
0
        -1;
2618
2
    if (PySet_Add(state->abstract_types, state->expr_type) < 0) return -1;
2619
2
    if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
2620
0
        return -1;
2621
2
    if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
2622
2
        -1)
2623
0
        return -1;
2624
2
    state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
2625
2
                                   BoolOp_fields, 2,
2626
2
        "BoolOp(boolop op, expr* values)");
2627
2
    if (!state->BoolOp_type) return -1;
2628
2
    state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
2629
2
                                      NamedExpr_fields, 2,
2630
2
        "NamedExpr(expr target, expr value)");
2631
2
    if (!state->NamedExpr_type) return -1;
2632
2
    state->BinOp_type = make_type(state, "BinOp", state->expr_type,
2633
2
                                  BinOp_fields, 3,
2634
2
        "BinOp(expr left, operator op, expr right)");
2635
2
    if (!state->BinOp_type) return -1;
2636
2
    state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
2637
2
                                    UnaryOp_fields, 2,
2638
2
        "UnaryOp(unaryop op, expr operand)");
2639
2
    if (!state->UnaryOp_type) return -1;
2640
2
    state->Lambda_type = make_type(state, "Lambda", state->expr_type,
2641
2
                                   Lambda_fields, 2,
2642
2
        "Lambda(arguments args, expr body)");
2643
2
    if (!state->Lambda_type) return -1;
2644
2
    state->IfExp_type = make_type(state, "IfExp", state->expr_type,
2645
2
                                  IfExp_fields, 3,
2646
2
        "IfExp(expr test, expr body, expr orelse)");
2647
2
    if (!state->IfExp_type) return -1;
2648
2
    state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
2649
2
                                 2,
2650
2
        "Dict(expr?* keys, expr* values)");
2651
2
    if (!state->Dict_type) return -1;
2652
2
    state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
2653
2
        "Set(expr* elts)");
2654
2
    if (!state->Set_type) return -1;
2655
2
    state->ListComp_type = make_type(state, "ListComp", state->expr_type,
2656
2
                                     ListComp_fields, 2,
2657
2
        "ListComp(expr elt, comprehension* generators)");
2658
2
    if (!state->ListComp_type) return -1;
2659
2
    state->SetComp_type = make_type(state, "SetComp", state->expr_type,
2660
2
                                    SetComp_fields, 2,
2661
2
        "SetComp(expr elt, comprehension* generators)");
2662
2
    if (!state->SetComp_type) return -1;
2663
2
    state->DictComp_type = make_type(state, "DictComp", state->expr_type,
2664
2
                                     DictComp_fields, 3,
2665
2
        "DictComp(expr key, expr? value, comprehension* generators)");
2666
2
    if (!state->DictComp_type) return -1;
2667
2
    if (PyObject_SetAttr(state->DictComp_type, state->value, Py_None) == -1)
2668
0
        return -1;
2669
2
    state->GeneratorExp_type = make_type(state, "GeneratorExp",
2670
2
                                         state->expr_type, GeneratorExp_fields,
2671
2
                                         2,
2672
2
        "GeneratorExp(expr elt, comprehension* generators)");
2673
2
    if (!state->GeneratorExp_type) return -1;
2674
2
    state->Await_type = make_type(state, "Await", state->expr_type,
2675
2
                                  Await_fields, 1,
2676
2
        "Await(expr value)");
2677
2
    if (!state->Await_type) return -1;
2678
2
    state->Yield_type = make_type(state, "Yield", state->expr_type,
2679
2
                                  Yield_fields, 1,
2680
2
        "Yield(expr? value)");
2681
2
    if (!state->Yield_type) return -1;
2682
2
    if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
2683
0
        return -1;
2684
2
    state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
2685
2
                                      YieldFrom_fields, 1,
2686
2
        "YieldFrom(expr value)");
2687
2
    if (!state->YieldFrom_type) return -1;
2688
2
    state->Compare_type = make_type(state, "Compare", state->expr_type,
2689
2
                                    Compare_fields, 3,
2690
2
        "Compare(expr left, cmpop* ops, expr* comparators)");
2691
2
    if (!state->Compare_type) return -1;
2692
2
    state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
2693
2
                                 3,
2694
2
        "Call(expr func, expr* args, keyword* keywords)");
2695
2
    if (!state->Call_type) return -1;
2696
2
    state->FormattedValue_type = make_type(state, "FormattedValue",
2697
2
                                           state->expr_type,
2698
2
                                           FormattedValue_fields, 3,
2699
2
        "FormattedValue(expr value, int conversion, expr? format_spec)");
2700
2
    if (!state->FormattedValue_type) return -1;
2701
2
    if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
2702
2
        Py_None) == -1)
2703
0
        return -1;
2704
2
    state->Interpolation_type = make_type(state, "Interpolation",
2705
2
                                          state->expr_type,
2706
2
                                          Interpolation_fields, 4,
2707
2
        "Interpolation(expr value, constant str, int conversion, expr? format_spec)");
2708
2
    if (!state->Interpolation_type) return -1;
2709
2
    if (PyObject_SetAttr(state->Interpolation_type, state->format_spec,
2710
2
        Py_None) == -1)
2711
0
        return -1;
2712
2
    state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
2713
2
                                      JoinedStr_fields, 1,
2714
2
        "JoinedStr(expr* values)");
2715
2
    if (!state->JoinedStr_type) return -1;
2716
2
    state->TemplateStr_type = make_type(state, "TemplateStr", state->expr_type,
2717
2
                                        TemplateStr_fields, 1,
2718
2
        "TemplateStr(expr* values)");
2719
2
    if (!state->TemplateStr_type) return -1;
2720
2
    state->Constant_type = make_type(state, "Constant", state->expr_type,
2721
2
                                     Constant_fields, 2,
2722
2
        "Constant(constant value, string? kind)");
2723
2
    if (!state->Constant_type) return -1;
2724
2
    if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
2725
0
        return -1;
2726
2
    state->Attribute_type = make_type(state, "Attribute", state->expr_type,
2727
2
                                      Attribute_fields, 3,
2728
2
        "Attribute(expr value, identifier attr, expr_context ctx)");
2729
2
    if (!state->Attribute_type) return -1;
2730
2
    state->Subscript_type = make_type(state, "Subscript", state->expr_type,
2731
2
                                      Subscript_fields, 3,
2732
2
        "Subscript(expr value, expr slice, expr_context ctx)");
2733
2
    if (!state->Subscript_type) return -1;
2734
2
    state->Starred_type = make_type(state, "Starred", state->expr_type,
2735
2
                                    Starred_fields, 2,
2736
2
        "Starred(expr value, expr_context ctx)");
2737
2
    if (!state->Starred_type) return -1;
2738
2
    state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
2739
2
                                 2,
2740
2
        "Name(identifier id, expr_context ctx)");
2741
2
    if (!state->Name_type) return -1;
2742
2
    state->List_type = make_type(state, "List", state->expr_type, List_fields,
2743
2
                                 2,
2744
2
        "List(expr* elts, expr_context ctx)");
2745
2
    if (!state->List_type) return -1;
2746
2
    state->Tuple_type = make_type(state, "Tuple", state->expr_type,
2747
2
                                  Tuple_fields, 2,
2748
2
        "Tuple(expr* elts, expr_context ctx)");
2749
2
    if (!state->Tuple_type) return -1;
2750
2
    state->Slice_type = make_type(state, "Slice", state->expr_type,
2751
2
                                  Slice_fields, 3,
2752
2
        "Slice(expr? lower, expr? upper, expr? step)");
2753
2
    if (!state->Slice_type) return -1;
2754
2
    if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
2755
0
        return -1;
2756
2
    if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
2757
0
        return -1;
2758
2
    if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
2759
0
        return -1;
2760
2
    state->expr_context_type = make_type(state, "expr_context",
2761
2
                                         state->AST_type, NULL, 0,
2762
2
        "expr_context = Load | Store | Del");
2763
2
    if (!state->expr_context_type) return -1;
2764
2
    if (add_attributes(state, state->expr_context_type, NULL, 0) < 0) return -1;
2765
2
    if (PySet_Add(state->abstract_types, state->expr_context_type) < 0) return
2766
0
        -1;
2767
2
    state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
2768
2
                                 0,
2769
2
        "Load");
2770
2
    if (!state->Load_type) return -1;
2771
2
    state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
2772
2
                                              NULL, NULL);
2773
2
    if (!state->Load_singleton) return -1;
2774
2
    state->Store_type = make_type(state, "Store", state->expr_context_type,
2775
2
                                  NULL, 0,
2776
2
        "Store");
2777
2
    if (!state->Store_type) return -1;
2778
2
    state->Store_singleton = PyType_GenericNew((PyTypeObject
2779
2
                                               *)state->Store_type, NULL, NULL);
2780
2
    if (!state->Store_singleton) return -1;
2781
2
    state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
2782
2
        "Del");
2783
2
    if (!state->Del_type) return -1;
2784
2
    state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
2785
2
                                             NULL, NULL);
2786
2
    if (!state->Del_singleton) return -1;
2787
2
    state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
2788
2
        "boolop = And | Or");
2789
2
    if (!state->boolop_type) return -1;
2790
2
    if (add_attributes(state, state->boolop_type, NULL, 0) < 0) return -1;
2791
2
    if (PySet_Add(state->abstract_types, state->boolop_type) < 0) return -1;
2792
2
    state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
2793
2
        "And");
2794
2
    if (!state->And_type) return -1;
2795
2
    state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
2796
2
                                             NULL, NULL);
2797
2
    if (!state->And_singleton) return -1;
2798
2
    state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
2799
2
        "Or");
2800
2
    if (!state->Or_type) return -1;
2801
2
    state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
2802
2
                                            NULL, NULL);
2803
2
    if (!state->Or_singleton) return -1;
2804
2
    state->operator_type = make_type(state, "operator", state->AST_type, NULL,
2805
2
                                     0,
2806
2
        "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
2807
2
    if (!state->operator_type) return -1;
2808
2
    if (add_attributes(state, state->operator_type, NULL, 0) < 0) return -1;
2809
2
    if (PySet_Add(state->abstract_types, state->operator_type) < 0) return -1;
2810
2
    state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
2811
2
        "Add");
2812
2
    if (!state->Add_type) return -1;
2813
2
    state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
2814
2
                                             NULL, NULL);
2815
2
    if (!state->Add_singleton) return -1;
2816
2
    state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
2817
2
        "Sub");
2818
2
    if (!state->Sub_type) return -1;
2819
2
    state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
2820
2
                                             NULL, NULL);
2821
2
    if (!state->Sub_singleton) return -1;
2822
2
    state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
2823
2
        "Mult");
2824
2
    if (!state->Mult_type) return -1;
2825
2
    state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
2826
2
                                              NULL, NULL);
2827
2
    if (!state->Mult_singleton) return -1;
2828
2
    state->MatMult_type = make_type(state, "MatMult", state->operator_type,
2829
2
                                    NULL, 0,
2830
2
        "MatMult");
2831
2
    if (!state->MatMult_type) return -1;
2832
2
    state->MatMult_singleton = PyType_GenericNew((PyTypeObject
2833
2
                                                 *)state->MatMult_type, NULL,
2834
2
                                                 NULL);
2835
2
    if (!state->MatMult_singleton) return -1;
2836
2
    state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
2837
2
        "Div");
2838
2
    if (!state->Div_type) return -1;
2839
2
    state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
2840
2
                                             NULL, NULL);
2841
2
    if (!state->Div_singleton) return -1;
2842
2
    state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
2843
2
        "Mod");
2844
2
    if (!state->Mod_type) return -1;
2845
2
    state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
2846
2
                                             NULL, NULL);
2847
2
    if (!state->Mod_singleton) return -1;
2848
2
    state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
2849
2
        "Pow");
2850
2
    if (!state->Pow_type) return -1;
2851
2
    state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
2852
2
                                             NULL, NULL);
2853
2
    if (!state->Pow_singleton) return -1;
2854
2
    state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
2855
2
                                   0,
2856
2
        "LShift");
2857
2
    if (!state->LShift_type) return -1;
2858
2
    state->LShift_singleton = PyType_GenericNew((PyTypeObject
2859
2
                                                *)state->LShift_type, NULL,
2860
2
                                                NULL);
2861
2
    if (!state->LShift_singleton) return -1;
2862
2
    state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
2863
2
                                   0,
2864
2
        "RShift");
2865
2
    if (!state->RShift_type) return -1;
2866
2
    state->RShift_singleton = PyType_GenericNew((PyTypeObject
2867
2
                                                *)state->RShift_type, NULL,
2868
2
                                                NULL);
2869
2
    if (!state->RShift_singleton) return -1;
2870
2
    state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
2871
2
        "BitOr");
2872
2
    if (!state->BitOr_type) return -1;
2873
2
    state->BitOr_singleton = PyType_GenericNew((PyTypeObject
2874
2
                                               *)state->BitOr_type, NULL, NULL);
2875
2
    if (!state->BitOr_singleton) return -1;
2876
2
    state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
2877
2
                                   0,
2878
2
        "BitXor");
2879
2
    if (!state->BitXor_type) return -1;
2880
2
    state->BitXor_singleton = PyType_GenericNew((PyTypeObject
2881
2
                                                *)state->BitXor_type, NULL,
2882
2
                                                NULL);
2883
2
    if (!state->BitXor_singleton) return -1;
2884
2
    state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
2885
2
                                   0,
2886
2
        "BitAnd");
2887
2
    if (!state->BitAnd_type) return -1;
2888
2
    state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
2889
2
                                                *)state->BitAnd_type, NULL,
2890
2
                                                NULL);
2891
2
    if (!state->BitAnd_singleton) return -1;
2892
2
    state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
2893
2
                                     NULL, 0,
2894
2
        "FloorDiv");
2895
2
    if (!state->FloorDiv_type) return -1;
2896
2
    state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
2897
2
                                                  *)state->FloorDiv_type, NULL,
2898
2
                                                  NULL);
2899
2
    if (!state->FloorDiv_singleton) return -1;
2900
2
    state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
2901
2
        "unaryop = Invert | Not | UAdd | USub");
2902
2
    if (!state->unaryop_type) return -1;
2903
2
    if (add_attributes(state, state->unaryop_type, NULL, 0) < 0) return -1;
2904
2
    if (PySet_Add(state->abstract_types, state->unaryop_type) < 0) return -1;
2905
2
    state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
2906
2
                                   0,
2907
2
        "Invert");
2908
2
    if (!state->Invert_type) return -1;
2909
2
    state->Invert_singleton = PyType_GenericNew((PyTypeObject
2910
2
                                                *)state->Invert_type, NULL,
2911
2
                                                NULL);
2912
2
    if (!state->Invert_singleton) return -1;
2913
2
    state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
2914
2
        "Not");
2915
2
    if (!state->Not_type) return -1;
2916
2
    state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
2917
2
                                             NULL, NULL);
2918
2
    if (!state->Not_singleton) return -1;
2919
2
    state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
2920
2
        "UAdd");
2921
2
    if (!state->UAdd_type) return -1;
2922
2
    state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
2923
2
                                              NULL, NULL);
2924
2
    if (!state->UAdd_singleton) return -1;
2925
2
    state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
2926
2
        "USub");
2927
2
    if (!state->USub_type) return -1;
2928
2
    state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
2929
2
                                              NULL, NULL);
2930
2
    if (!state->USub_singleton) return -1;
2931
2
    state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
2932
2
        "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
2933
2
    if (!state->cmpop_type) return -1;
2934
2
    if (add_attributes(state, state->cmpop_type, NULL, 0) < 0) return -1;
2935
2
    if (PySet_Add(state->abstract_types, state->cmpop_type) < 0) return -1;
2936
2
    state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
2937
2
        "Eq");
2938
2
    if (!state->Eq_type) return -1;
2939
2
    state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
2940
2
                                            NULL, NULL);
2941
2
    if (!state->Eq_singleton) return -1;
2942
2
    state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
2943
2
        "NotEq");
2944
2
    if (!state->NotEq_type) return -1;
2945
2
    state->NotEq_singleton = PyType_GenericNew((PyTypeObject
2946
2
                                               *)state->NotEq_type, NULL, NULL);
2947
2
    if (!state->NotEq_singleton) return -1;
2948
2
    state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
2949
2
        "Lt");
2950
2
    if (!state->Lt_type) return -1;
2951
2
    state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
2952
2
                                            NULL, NULL);
2953
2
    if (!state->Lt_singleton) return -1;
2954
2
    state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
2955
2
        "LtE");
2956
2
    if (!state->LtE_type) return -1;
2957
2
    state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
2958
2
                                             NULL, NULL);
2959
2
    if (!state->LtE_singleton) return -1;
2960
2
    state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
2961
2
        "Gt");
2962
2
    if (!state->Gt_type) return -1;
2963
2
    state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
2964
2
                                            NULL, NULL);
2965
2
    if (!state->Gt_singleton) return -1;
2966
2
    state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
2967
2
        "GtE");
2968
2
    if (!state->GtE_type) return -1;
2969
2
    state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
2970
2
                                             NULL, NULL);
2971
2
    if (!state->GtE_singleton) return -1;
2972
2
    state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
2973
2
        "Is");
2974
2
    if (!state->Is_type) return -1;
2975
2
    state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
2976
2
                                            NULL, NULL);
2977
2
    if (!state->Is_singleton) return -1;
2978
2
    state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
2979
2
        "IsNot");
2980
2
    if (!state->IsNot_type) return -1;
2981
2
    state->IsNot_singleton = PyType_GenericNew((PyTypeObject
2982
2
                                               *)state->IsNot_type, NULL, NULL);
2983
2
    if (!state->IsNot_singleton) return -1;
2984
2
    state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
2985
2
        "In");
2986
2
    if (!state->In_type) return -1;
2987
2
    state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
2988
2
                                            NULL, NULL);
2989
2
    if (!state->In_singleton) return -1;
2990
2
    state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
2991
2
        "NotIn");
2992
2
    if (!state->NotIn_type) return -1;
2993
2
    state->NotIn_singleton = PyType_GenericNew((PyTypeObject
2994
2
                                               *)state->NotIn_type, NULL, NULL);
2995
2
    if (!state->NotIn_singleton) return -1;
2996
2
    state->comprehension_type = make_type(state, "comprehension",
2997
2
                                          state->AST_type,
2998
2
                                          comprehension_fields, 4,
2999
2
        "comprehension(expr target, expr iter, expr* ifs, int is_async)");
3000
2
    if (!state->comprehension_type) return -1;
3001
2
    if (add_attributes(state, state->comprehension_type, NULL, 0) < 0) return
3002
0
        -1;
3003
2
    state->excepthandler_type = make_type(state, "excepthandler",
3004
2
                                          state->AST_type, NULL, 0,
3005
2
        "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
3006
2
    if (!state->excepthandler_type) return -1;
3007
2
    if (add_attributes(state, state->excepthandler_type,
3008
2
        excepthandler_attributes, 4) < 0) return -1;
3009
2
    if (PySet_Add(state->abstract_types, state->excepthandler_type) < 0) return
3010
0
        -1;
3011
2
    if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
3012
2
        == -1)
3013
0
        return -1;
3014
2
    if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
3015
2
        Py_None) == -1)
3016
0
        return -1;
3017
2
    state->ExceptHandler_type = make_type(state, "ExceptHandler",
3018
2
                                          state->excepthandler_type,
3019
2
                                          ExceptHandler_fields, 3,
3020
2
        "ExceptHandler(expr? type, identifier? name, stmt* body)");
3021
2
    if (!state->ExceptHandler_type) return -1;
3022
2
    if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
3023
0
        return -1;
3024
2
    if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
3025
0
        return -1;
3026
2
    state->arguments_type = make_type(state, "arguments", state->AST_type,
3027
2
                                      arguments_fields, 7,
3028
2
        "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr?* kw_defaults, arg? kwarg, expr* defaults)");
3029
2
    if (!state->arguments_type) return -1;
3030
2
    if (add_attributes(state, state->arguments_type, NULL, 0) < 0) return -1;
3031
2
    if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
3032
0
        return -1;
3033
2
    if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
3034
0
        return -1;
3035
2
    state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
3036
2
        "arg(identifier arg, expr? annotation, string? type_comment)");
3037
2
    if (!state->arg_type) return -1;
3038
2
    if (add_attributes(state, state->arg_type, arg_attributes, 4) < 0) return
3039
0
        -1;
3040
2
    if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
3041
0
        return -1;
3042
2
    if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
3043
0
        return -1;
3044
2
    if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
3045
0
        return -1;
3046
2
    if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
3047
0
        return -1;
3048
2
    state->keyword_type = make_type(state, "keyword", state->AST_type,
3049
2
                                    keyword_fields, 2,
3050
2
        "keyword(identifier? arg, expr value)");
3051
2
    if (!state->keyword_type) return -1;
3052
2
    if (add_attributes(state, state->keyword_type, keyword_attributes, 4) < 0)
3053
0
        return -1;
3054
2
    if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
3055
0
        return -1;
3056
2
    if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
3057
0
        return -1;
3058
2
    if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
3059
2
        == -1)
3060
0
        return -1;
3061
2
    state->alias_type = make_type(state, "alias", state->AST_type,
3062
2
                                  alias_fields, 2,
3063
2
        "alias(identifier name, identifier? asname)");
3064
2
    if (!state->alias_type) return -1;
3065
2
    if (add_attributes(state, state->alias_type, alias_attributes, 4) < 0)
3066
0
        return -1;
3067
2
    if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
3068
0
        return -1;
3069
2
    if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
3070
0
        return -1;
3071
2
    if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
3072
2
        -1)
3073
0
        return -1;
3074
2
    state->withitem_type = make_type(state, "withitem", state->AST_type,
3075
2
                                     withitem_fields, 2,
3076
2
        "withitem(expr context_expr, expr? optional_vars)");
3077
2
    if (!state->withitem_type) return -1;
3078
2
    if (add_attributes(state, state->withitem_type, NULL, 0) < 0) return -1;
3079
2
    if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
3080
2
        == -1)
3081
0
        return -1;
3082
2
    state->match_case_type = make_type(state, "match_case", state->AST_type,
3083
2
                                       match_case_fields, 3,
3084
2
        "match_case(pattern pattern, expr? guard, stmt* body)");
3085
2
    if (!state->match_case_type) return -1;
3086
2
    if (add_attributes(state, state->match_case_type, NULL, 0) < 0) return -1;
3087
2
    if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
3088
0
        return -1;
3089
2
    state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
3090
2
        "pattern = MatchValue(expr value)\n"
3091
2
        "        | MatchSingleton(constant value)\n"
3092
2
        "        | MatchSequence(pattern* patterns)\n"
3093
2
        "        | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
3094
2
        "        | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
3095
2
        "        | MatchStar(identifier? name)\n"
3096
2
        "        | MatchAs(pattern? pattern, identifier? name)\n"
3097
2
        "        | MatchOr(pattern* patterns)");
3098
2
    if (!state->pattern_type) return -1;
3099
2
    if (add_attributes(state, state->pattern_type, pattern_attributes, 4) < 0)
3100
0
        return -1;
3101
2
    if (PySet_Add(state->abstract_types, state->pattern_type) < 0) return -1;
3102
2
    state->MatchValue_type = make_type(state, "MatchValue",
3103
2
                                       state->pattern_type, MatchValue_fields,
3104
2
                                       1,
3105
2
        "MatchValue(expr value)");
3106
2
    if (!state->MatchValue_type) return -1;
3107
2
    state->MatchSingleton_type = make_type(state, "MatchSingleton",
3108
2
                                           state->pattern_type,
3109
2
                                           MatchSingleton_fields, 1,
3110
2
        "MatchSingleton(constant value)");
3111
2
    if (!state->MatchSingleton_type) return -1;
3112
2
    state->MatchSequence_type = make_type(state, "MatchSequence",
3113
2
                                          state->pattern_type,
3114
2
                                          MatchSequence_fields, 1,
3115
2
        "MatchSequence(pattern* patterns)");
3116
2
    if (!state->MatchSequence_type) return -1;
3117
2
    state->MatchMapping_type = make_type(state, "MatchMapping",
3118
2
                                         state->pattern_type,
3119
2
                                         MatchMapping_fields, 3,
3120
2
        "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
3121
2
    if (!state->MatchMapping_type) return -1;
3122
2
    if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
3123
0
        return -1;
3124
2
    state->MatchClass_type = make_type(state, "MatchClass",
3125
2
                                       state->pattern_type, MatchClass_fields,
3126
2
                                       4,
3127
2
        "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
3128
2
    if (!state->MatchClass_type) return -1;
3129
2
    state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
3130
2
                                      MatchStar_fields, 1,
3131
2
        "MatchStar(identifier? name)");
3132
2
    if (!state->MatchStar_type) return -1;
3133
2
    if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
3134
0
        return -1;
3135
2
    state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
3136
2
                                    MatchAs_fields, 2,
3137
2
        "MatchAs(pattern? pattern, identifier? name)");
3138
2
    if (!state->MatchAs_type) return -1;
3139
2
    if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
3140
0
        return -1;
3141
2
    if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
3142
0
        return -1;
3143
2
    state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
3144
2
                                    MatchOr_fields, 1,
3145
2
        "MatchOr(pattern* patterns)");
3146
2
    if (!state->MatchOr_type) return -1;
3147
2
    state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
3148
2
                                        NULL, 0,
3149
2
        "type_ignore = TypeIgnore(int lineno, string tag)");
3150
2
    if (!state->type_ignore_type) return -1;
3151
2
    if (add_attributes(state, state->type_ignore_type, NULL, 0) < 0) return -1;
3152
2
    if (PySet_Add(state->abstract_types, state->type_ignore_type) < 0) return
3153
0
        -1;
3154
2
    state->TypeIgnore_type = make_type(state, "TypeIgnore",
3155
2
                                       state->type_ignore_type,
3156
2
                                       TypeIgnore_fields, 2,
3157
2
        "TypeIgnore(int lineno, string tag)");
3158
2
    if (!state->TypeIgnore_type) return -1;
3159
2
    state->type_param_type = make_type(state, "type_param", state->AST_type,
3160
2
                                       NULL, 0,
3161
2
        "type_param = TypeVar(identifier name, expr? bound, expr? default_value)\n"
3162
2
        "           | ParamSpec(identifier name, expr? default_value)\n"
3163
2
        "           | TypeVarTuple(identifier name, expr? default_value)");
3164
2
    if (!state->type_param_type) return -1;
3165
2
    if (add_attributes(state, state->type_param_type, type_param_attributes, 4)
3166
2
        < 0) return -1;
3167
2
    if (PySet_Add(state->abstract_types, state->type_param_type) < 0) return -1;
3168
2
    state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
3169
2
                                    TypeVar_fields, 3,
3170
2
        "TypeVar(identifier name, expr? bound, expr? default_value)");
3171
2
    if (!state->TypeVar_type) return -1;
3172
2
    if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
3173
0
        return -1;
3174
2
    if (PyObject_SetAttr(state->TypeVar_type, state->default_value, Py_None) ==
3175
2
        -1)
3176
0
        return -1;
3177
2
    state->ParamSpec_type = make_type(state, "ParamSpec",
3178
2
                                      state->type_param_type, ParamSpec_fields,
3179
2
                                      2,
3180
2
        "ParamSpec(identifier name, expr? default_value)");
3181
2
    if (!state->ParamSpec_type) return -1;
3182
2
    if (PyObject_SetAttr(state->ParamSpec_type, state->default_value, Py_None)
3183
2
        == -1)
3184
0
        return -1;
3185
2
    state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
3186
2
                                         state->type_param_type,
3187
2
                                         TypeVarTuple_fields, 2,
3188
2
        "TypeVarTuple(identifier name, expr? default_value)");
3189
2
    if (!state->TypeVarTuple_type) return -1;
3190
2
    if (PyObject_SetAttr(state->TypeVarTuple_type, state->default_value,
3191
2
        Py_None) == -1)
3192
0
        return -1;
3193
3194
2
    if (!add_ast_annotations(state)) {
3195
0
        return -1;
3196
0
    }
3197
2
    return 0;
3198
2
}
3199
3200
static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
3201
                       const char* field, PyArena* arena);
3202
static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
3203
                        const char* field, PyArena* arena);
3204
static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
3205
                        const char* field, PyArena* arena);
3206
static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
3207
                                expr_context_ty* out, const char* field,
3208
                                PyArena* arena);
3209
static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
3210
                          out, const char* field, PyArena* arena);
3211
static int obj2ast_operator(struct ast_state *state, PyObject* obj,
3212
                            operator_ty* out, const char* field, PyArena*
3213
                            arena);
3214
static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
3215
                           out, const char* field, PyArena* arena);
3216
static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
3217
                         const char* field, PyArena* arena);
3218
static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
3219
                                 comprehension_ty* out, const char* field,
3220
                                 PyArena* arena);
3221
static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
3222
                                 excepthandler_ty* out, const char* field,
3223
                                 PyArena* arena);
3224
static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
3225
                             arguments_ty* out, const char* field, PyArena*
3226
                             arena);
3227
static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
3228
                       const char* field, PyArena* arena);
3229
static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
3230
                           out, const char* field, PyArena* arena);
3231
static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
3232
                         const char* field, PyArena* arena);
3233
static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
3234
                            withitem_ty* out, const char* field, PyArena*
3235
                            arena);
3236
static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
3237
                              match_case_ty* out, const char* field, PyArena*
3238
                              arena);
3239
static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
3240
                           out, const char* field, PyArena* arena);
3241
static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
3242
                               type_ignore_ty* out, const char* field, PyArena*
3243
                               arena);
3244
static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
3245
                              type_param_ty* out, const char* field, PyArena*
3246
                              arena);
3247
3248
mod_ty
3249
_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
3250
              PyArena *arena)
3251
9.90k
{
3252
9.90k
    mod_ty p;
3253
9.90k
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3254
9.90k
    if (!p)
3255
0
        return NULL;
3256
9.90k
    p->kind = Module_kind;
3257
9.90k
    p->v.Module.body = body;
3258
9.90k
    p->v.Module.type_ignores = type_ignores;
3259
9.90k
    return p;
3260
9.90k
}
3261
3262
mod_ty
3263
_PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
3264
2.76k
{
3265
2.76k
    mod_ty p;
3266
2.76k
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3267
2.76k
    if (!p)
3268
0
        return NULL;
3269
2.76k
    p->kind = Interactive_kind;
3270
2.76k
    p->v.Interactive.body = body;
3271
2.76k
    return p;
3272
2.76k
}
3273
3274
mod_ty
3275
_PyAST_Expression(expr_ty body, PyArena *arena)
3276
2.04k
{
3277
2.04k
    mod_ty p;
3278
2.04k
    if (!body) {
3279
0
        PyErr_SetString(PyExc_ValueError,
3280
0
                        "field 'body' is required for Expression");
3281
0
        return NULL;
3282
0
    }
3283
2.04k
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3284
2.04k
    if (!p)
3285
0
        return NULL;
3286
2.04k
    p->kind = Expression_kind;
3287
2.04k
    p->v.Expression.body = body;
3288
2.04k
    return p;
3289
2.04k
}
3290
3291
mod_ty
3292
_PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
3293
0
{
3294
0
    mod_ty p;
3295
0
    if (!returns) {
3296
0
        PyErr_SetString(PyExc_ValueError,
3297
0
                        "field 'returns' is required for FunctionType");
3298
0
        return NULL;
3299
0
    }
3300
0
    p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
3301
0
    if (!p)
3302
0
        return NULL;
3303
0
    p->kind = FunctionType_kind;
3304
0
    p->v.FunctionType.argtypes = argtypes;
3305
0
    p->v.FunctionType.returns = returns;
3306
0
    return p;
3307
0
}
3308
3309
stmt_ty
3310
_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
3311
                   asdl_expr_seq * decorator_list, expr_ty returns, string
3312
                   type_comment, asdl_type_param_seq * type_params, int lineno,
3313
                   int col_offset, int end_lineno, int end_col_offset, PyArena
3314
                   *arena)
3315
7.50k
{
3316
7.50k
    stmt_ty p;
3317
7.50k
    if (!name) {
3318
0
        PyErr_SetString(PyExc_ValueError,
3319
0
                        "field 'name' is required for FunctionDef");
3320
0
        return NULL;
3321
0
    }
3322
7.50k
    if (!args) {
3323
0
        PyErr_SetString(PyExc_ValueError,
3324
0
                        "field 'args' is required for FunctionDef");
3325
0
        return NULL;
3326
0
    }
3327
7.50k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3328
7.50k
    if (!p)
3329
0
        return NULL;
3330
7.50k
    p->kind = FunctionDef_kind;
3331
7.50k
    p->v.FunctionDef.name = name;
3332
7.50k
    p->v.FunctionDef.args = args;
3333
7.50k
    p->v.FunctionDef.body = body;
3334
7.50k
    p->v.FunctionDef.decorator_list = decorator_list;
3335
7.50k
    p->v.FunctionDef.returns = returns;
3336
7.50k
    p->v.FunctionDef.type_comment = type_comment;
3337
7.50k
    p->v.FunctionDef.type_params = type_params;
3338
7.50k
    p->lineno = lineno;
3339
7.50k
    p->col_offset = col_offset;
3340
7.50k
    p->end_lineno = end_lineno;
3341
7.50k
    p->end_col_offset = end_col_offset;
3342
7.50k
    return p;
3343
7.50k
}
3344
3345
stmt_ty
3346
_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
3347
                        body, asdl_expr_seq * decorator_list, expr_ty returns,
3348
                        string type_comment, asdl_type_param_seq * type_params,
3349
                        int lineno, int col_offset, int end_lineno, int
3350
                        end_col_offset, PyArena *arena)
3351
4.88k
{
3352
4.88k
    stmt_ty p;
3353
4.88k
    if (!name) {
3354
0
        PyErr_SetString(PyExc_ValueError,
3355
0
                        "field 'name' is required for AsyncFunctionDef");
3356
0
        return NULL;
3357
0
    }
3358
4.88k
    if (!args) {
3359
0
        PyErr_SetString(PyExc_ValueError,
3360
0
                        "field 'args' is required for AsyncFunctionDef");
3361
0
        return NULL;
3362
0
    }
3363
4.88k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3364
4.88k
    if (!p)
3365
0
        return NULL;
3366
4.88k
    p->kind = AsyncFunctionDef_kind;
3367
4.88k
    p->v.AsyncFunctionDef.name = name;
3368
4.88k
    p->v.AsyncFunctionDef.args = args;
3369
4.88k
    p->v.AsyncFunctionDef.body = body;
3370
4.88k
    p->v.AsyncFunctionDef.decorator_list = decorator_list;
3371
4.88k
    p->v.AsyncFunctionDef.returns = returns;
3372
4.88k
    p->v.AsyncFunctionDef.type_comment = type_comment;
3373
4.88k
    p->v.AsyncFunctionDef.type_params = type_params;
3374
4.88k
    p->lineno = lineno;
3375
4.88k
    p->col_offset = col_offset;
3376
4.88k
    p->end_lineno = end_lineno;
3377
4.88k
    p->end_col_offset = end_col_offset;
3378
4.88k
    return p;
3379
4.88k
}
3380
3381
stmt_ty
3382
_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
3383
                keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
3384
                asdl_type_param_seq * type_params, int lineno, int col_offset,
3385
                int end_lineno, int end_col_offset, PyArena *arena)
3386
16.4k
{
3387
16.4k
    stmt_ty p;
3388
16.4k
    if (!name) {
3389
0
        PyErr_SetString(PyExc_ValueError,
3390
0
                        "field 'name' is required for ClassDef");
3391
0
        return NULL;
3392
0
    }
3393
16.4k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3394
16.4k
    if (!p)
3395
0
        return NULL;
3396
16.4k
    p->kind = ClassDef_kind;
3397
16.4k
    p->v.ClassDef.name = name;
3398
16.4k
    p->v.ClassDef.bases = bases;
3399
16.4k
    p->v.ClassDef.keywords = keywords;
3400
16.4k
    p->v.ClassDef.body = body;
3401
16.4k
    p->v.ClassDef.decorator_list = decorator_list;
3402
16.4k
    p->v.ClassDef.type_params = type_params;
3403
16.4k
    p->lineno = lineno;
3404
16.4k
    p->col_offset = col_offset;
3405
16.4k
    p->end_lineno = end_lineno;
3406
16.4k
    p->end_col_offset = end_col_offset;
3407
16.4k
    return p;
3408
16.4k
}
3409
3410
stmt_ty
3411
_PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
3412
              end_col_offset, PyArena *arena)
3413
1.59k
{
3414
1.59k
    stmt_ty p;
3415
1.59k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3416
1.59k
    if (!p)
3417
0
        return NULL;
3418
1.59k
    p->kind = Return_kind;
3419
1.59k
    p->v.Return.value = value;
3420
1.59k
    p->lineno = lineno;
3421
1.59k
    p->col_offset = col_offset;
3422
1.59k
    p->end_lineno = end_lineno;
3423
1.59k
    p->end_col_offset = end_col_offset;
3424
1.59k
    return p;
3425
1.59k
}
3426
3427
stmt_ty
3428
_PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
3429
              end_lineno, int end_col_offset, PyArena *arena)
3430
1.54k
{
3431
1.54k
    stmt_ty p;
3432
1.54k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3433
1.54k
    if (!p)
3434
0
        return NULL;
3435
1.54k
    p->kind = Delete_kind;
3436
1.54k
    p->v.Delete.targets = targets;
3437
1.54k
    p->lineno = lineno;
3438
1.54k
    p->col_offset = col_offset;
3439
1.54k
    p->end_lineno = end_lineno;
3440
1.54k
    p->end_col_offset = end_col_offset;
3441
1.54k
    return p;
3442
1.54k
}
3443
3444
stmt_ty
3445
_PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
3446
              lineno, int col_offset, int end_lineno, int end_col_offset,
3447
              PyArena *arena)
3448
8.31k
{
3449
8.31k
    stmt_ty p;
3450
8.31k
    if (!value) {
3451
0
        PyErr_SetString(PyExc_ValueError,
3452
0
                        "field 'value' is required for Assign");
3453
0
        return NULL;
3454
0
    }
3455
8.31k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3456
8.31k
    if (!p)
3457
0
        return NULL;
3458
8.31k
    p->kind = Assign_kind;
3459
8.31k
    p->v.Assign.targets = targets;
3460
8.31k
    p->v.Assign.value = value;
3461
8.31k
    p->v.Assign.type_comment = type_comment;
3462
8.31k
    p->lineno = lineno;
3463
8.31k
    p->col_offset = col_offset;
3464
8.31k
    p->end_lineno = end_lineno;
3465
8.31k
    p->end_col_offset = end_col_offset;
3466
8.31k
    return p;
3467
8.31k
}
3468
3469
stmt_ty
3470
_PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
3471
                 value, int lineno, int col_offset, int end_lineno, int
3472
                 end_col_offset, PyArena *arena)
3473
2.75k
{
3474
2.75k
    stmt_ty p;
3475
2.75k
    if (!name) {
3476
0
        PyErr_SetString(PyExc_ValueError,
3477
0
                        "field 'name' is required for TypeAlias");
3478
0
        return NULL;
3479
0
    }
3480
2.75k
    if (!value) {
3481
0
        PyErr_SetString(PyExc_ValueError,
3482
0
                        "field 'value' is required for TypeAlias");
3483
0
        return NULL;
3484
0
    }
3485
2.75k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3486
2.75k
    if (!p)
3487
0
        return NULL;
3488
2.75k
    p->kind = TypeAlias_kind;
3489
2.75k
    p->v.TypeAlias.name = name;
3490
2.75k
    p->v.TypeAlias.type_params = type_params;
3491
2.75k
    p->v.TypeAlias.value = value;
3492
2.75k
    p->lineno = lineno;
3493
2.75k
    p->col_offset = col_offset;
3494
2.75k
    p->end_lineno = end_lineno;
3495
2.75k
    p->end_col_offset = end_col_offset;
3496
2.75k
    return p;
3497
2.75k
}
3498
3499
stmt_ty
3500
_PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
3501
                 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3502
7.75k
{
3503
7.75k
    stmt_ty p;
3504
7.75k
    if (!target) {
3505
0
        PyErr_SetString(PyExc_ValueError,
3506
0
                        "field 'target' is required for AugAssign");
3507
0
        return NULL;
3508
0
    }
3509
7.75k
    if (!op) {
3510
0
        PyErr_SetString(PyExc_ValueError,
3511
0
                        "field 'op' is required for AugAssign");
3512
0
        return NULL;
3513
0
    }
3514
7.75k
    if (!value) {
3515
0
        PyErr_SetString(PyExc_ValueError,
3516
0
                        "field 'value' is required for AugAssign");
3517
0
        return NULL;
3518
0
    }
3519
7.75k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3520
7.75k
    if (!p)
3521
0
        return NULL;
3522
7.75k
    p->kind = AugAssign_kind;
3523
7.75k
    p->v.AugAssign.target = target;
3524
7.75k
    p->v.AugAssign.op = op;
3525
7.75k
    p->v.AugAssign.value = value;
3526
7.75k
    p->lineno = lineno;
3527
7.75k
    p->col_offset = col_offset;
3528
7.75k
    p->end_lineno = end_lineno;
3529
7.75k
    p->end_col_offset = end_col_offset;
3530
7.75k
    return p;
3531
7.75k
}
3532
3533
stmt_ty
3534
_PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
3535
                 int lineno, int col_offset, int end_lineno, int
3536
                 end_col_offset, PyArena *arena)
3537
30.2k
{
3538
30.2k
    stmt_ty p;
3539
30.2k
    if (!target) {
3540
0
        PyErr_SetString(PyExc_ValueError,
3541
0
                        "field 'target' is required for AnnAssign");
3542
0
        return NULL;
3543
0
    }
3544
30.2k
    if (!annotation) {
3545
0
        PyErr_SetString(PyExc_ValueError,
3546
0
                        "field 'annotation' is required for AnnAssign");
3547
0
        return NULL;
3548
0
    }
3549
30.2k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3550
30.2k
    if (!p)
3551
0
        return NULL;
3552
30.2k
    p->kind = AnnAssign_kind;
3553
30.2k
    p->v.AnnAssign.target = target;
3554
30.2k
    p->v.AnnAssign.annotation = annotation;
3555
30.2k
    p->v.AnnAssign.value = value;
3556
30.2k
    p->v.AnnAssign.simple = simple;
3557
30.2k
    p->lineno = lineno;
3558
30.2k
    p->col_offset = col_offset;
3559
30.2k
    p->end_lineno = end_lineno;
3560
30.2k
    p->end_col_offset = end_col_offset;
3561
30.2k
    return p;
3562
30.2k
}
3563
3564
stmt_ty
3565
_PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
3566
           orelse, string type_comment, int lineno, int col_offset, int
3567
           end_lineno, int end_col_offset, PyArena *arena)
3568
920
{
3569
920
    stmt_ty p;
3570
920
    if (!target) {
3571
0
        PyErr_SetString(PyExc_ValueError,
3572
0
                        "field 'target' is required for For");
3573
0
        return NULL;
3574
0
    }
3575
920
    if (!iter) {
3576
0
        PyErr_SetString(PyExc_ValueError,
3577
0
                        "field 'iter' is required for For");
3578
0
        return NULL;
3579
0
    }
3580
920
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3581
920
    if (!p)
3582
0
        return NULL;
3583
920
    p->kind = For_kind;
3584
920
    p->v.For.target = target;
3585
920
    p->v.For.iter = iter;
3586
920
    p->v.For.body = body;
3587
920
    p->v.For.orelse = orelse;
3588
920
    p->v.For.type_comment = type_comment;
3589
920
    p->lineno = lineno;
3590
920
    p->col_offset = col_offset;
3591
920
    p->end_lineno = end_lineno;
3592
920
    p->end_col_offset = end_col_offset;
3593
920
    return p;
3594
920
}
3595
3596
stmt_ty
3597
_PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
3598
                asdl_stmt_seq * orelse, string type_comment, int lineno, int
3599
                col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3600
870
{
3601
870
    stmt_ty p;
3602
870
    if (!target) {
3603
0
        PyErr_SetString(PyExc_ValueError,
3604
0
                        "field 'target' is required for AsyncFor");
3605
0
        return NULL;
3606
0
    }
3607
870
    if (!iter) {
3608
0
        PyErr_SetString(PyExc_ValueError,
3609
0
                        "field 'iter' is required for AsyncFor");
3610
0
        return NULL;
3611
0
    }
3612
870
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3613
870
    if (!p)
3614
0
        return NULL;
3615
870
    p->kind = AsyncFor_kind;
3616
870
    p->v.AsyncFor.target = target;
3617
870
    p->v.AsyncFor.iter = iter;
3618
870
    p->v.AsyncFor.body = body;
3619
870
    p->v.AsyncFor.orelse = orelse;
3620
870
    p->v.AsyncFor.type_comment = type_comment;
3621
870
    p->lineno = lineno;
3622
870
    p->col_offset = col_offset;
3623
870
    p->end_lineno = end_lineno;
3624
870
    p->end_col_offset = end_col_offset;
3625
870
    return p;
3626
870
}
3627
3628
stmt_ty
3629
_PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
3630
             lineno, int col_offset, int end_lineno, int end_col_offset,
3631
             PyArena *arena)
3632
3.21k
{
3633
3.21k
    stmt_ty p;
3634
3.21k
    if (!test) {
3635
0
        PyErr_SetString(PyExc_ValueError,
3636
0
                        "field 'test' is required for While");
3637
0
        return NULL;
3638
0
    }
3639
3.21k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3640
3.21k
    if (!p)
3641
0
        return NULL;
3642
3.21k
    p->kind = While_kind;
3643
3.21k
    p->v.While.test = test;
3644
3.21k
    p->v.While.body = body;
3645
3.21k
    p->v.While.orelse = orelse;
3646
3.21k
    p->lineno = lineno;
3647
3.21k
    p->col_offset = col_offset;
3648
3.21k
    p->end_lineno = end_lineno;
3649
3.21k
    p->end_col_offset = end_col_offset;
3650
3.21k
    return p;
3651
3.21k
}
3652
3653
stmt_ty
3654
_PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
3655
          lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
3656
          *arena)
3657
2.43k
{
3658
2.43k
    stmt_ty p;
3659
2.43k
    if (!test) {
3660
0
        PyErr_SetString(PyExc_ValueError,
3661
0
                        "field 'test' is required for If");
3662
0
        return NULL;
3663
0
    }
3664
2.43k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3665
2.43k
    if (!p)
3666
0
        return NULL;
3667
2.43k
    p->kind = If_kind;
3668
2.43k
    p->v.If.test = test;
3669
2.43k
    p->v.If.body = body;
3670
2.43k
    p->v.If.orelse = orelse;
3671
2.43k
    p->lineno = lineno;
3672
2.43k
    p->col_offset = col_offset;
3673
2.43k
    p->end_lineno = end_lineno;
3674
2.43k
    p->end_col_offset = end_col_offset;
3675
2.43k
    return p;
3676
2.43k
}
3677
3678
stmt_ty
3679
_PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
3680
            type_comment, int lineno, int col_offset, int end_lineno, int
3681
            end_col_offset, PyArena *arena)
3682
2.55k
{
3683
2.55k
    stmt_ty p;
3684
2.55k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3685
2.55k
    if (!p)
3686
0
        return NULL;
3687
2.55k
    p->kind = With_kind;
3688
2.55k
    p->v.With.items = items;
3689
2.55k
    p->v.With.body = body;
3690
2.55k
    p->v.With.type_comment = type_comment;
3691
2.55k
    p->lineno = lineno;
3692
2.55k
    p->col_offset = col_offset;
3693
2.55k
    p->end_lineno = end_lineno;
3694
2.55k
    p->end_col_offset = end_col_offset;
3695
2.55k
    return p;
3696
2.55k
}
3697
3698
stmt_ty
3699
_PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
3700
                 type_comment, int lineno, int col_offset, int end_lineno, int
3701
                 end_col_offset, PyArena *arena)
3702
2.82k
{
3703
2.82k
    stmt_ty p;
3704
2.82k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3705
2.82k
    if (!p)
3706
0
        return NULL;
3707
2.82k
    p->kind = AsyncWith_kind;
3708
2.82k
    p->v.AsyncWith.items = items;
3709
2.82k
    p->v.AsyncWith.body = body;
3710
2.82k
    p->v.AsyncWith.type_comment = type_comment;
3711
2.82k
    p->lineno = lineno;
3712
2.82k
    p->col_offset = col_offset;
3713
2.82k
    p->end_lineno = end_lineno;
3714
2.82k
    p->end_col_offset = end_col_offset;
3715
2.82k
    return p;
3716
2.82k
}
3717
3718
stmt_ty
3719
_PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
3720
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3721
1.40k
{
3722
1.40k
    stmt_ty p;
3723
1.40k
    if (!subject) {
3724
0
        PyErr_SetString(PyExc_ValueError,
3725
0
                        "field 'subject' is required for Match");
3726
0
        return NULL;
3727
0
    }
3728
1.40k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3729
1.40k
    if (!p)
3730
0
        return NULL;
3731
1.40k
    p->kind = Match_kind;
3732
1.40k
    p->v.Match.subject = subject;
3733
1.40k
    p->v.Match.cases = cases;
3734
1.40k
    p->lineno = lineno;
3735
1.40k
    p->col_offset = col_offset;
3736
1.40k
    p->end_lineno = end_lineno;
3737
1.40k
    p->end_col_offset = end_col_offset;
3738
1.40k
    return p;
3739
1.40k
}
3740
3741
stmt_ty
3742
_PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
3743
             end_lineno, int end_col_offset, PyArena *arena)
3744
1.40k
{
3745
1.40k
    stmt_ty p;
3746
1.40k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3747
1.40k
    if (!p)
3748
0
        return NULL;
3749
1.40k
    p->kind = Raise_kind;
3750
1.40k
    p->v.Raise.exc = exc;
3751
1.40k
    p->v.Raise.cause = cause;
3752
1.40k
    p->lineno = lineno;
3753
1.40k
    p->col_offset = col_offset;
3754
1.40k
    p->end_lineno = end_lineno;
3755
1.40k
    p->end_col_offset = end_col_offset;
3756
1.40k
    return p;
3757
1.40k
}
3758
3759
stmt_ty
3760
_PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
3761
           asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
3762
           col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3763
5.70k
{
3764
5.70k
    stmt_ty p;
3765
5.70k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3766
5.70k
    if (!p)
3767
0
        return NULL;
3768
5.70k
    p->kind = Try_kind;
3769
5.70k
    p->v.Try.body = body;
3770
5.70k
    p->v.Try.handlers = handlers;
3771
5.70k
    p->v.Try.orelse = orelse;
3772
5.70k
    p->v.Try.finalbody = finalbody;
3773
5.70k
    p->lineno = lineno;
3774
5.70k
    p->col_offset = col_offset;
3775
5.70k
    p->end_lineno = end_lineno;
3776
5.70k
    p->end_col_offset = end_col_offset;
3777
5.70k
    return p;
3778
5.70k
}
3779
3780
stmt_ty
3781
_PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
3782
               asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
3783
               int col_offset, int end_lineno, int end_col_offset, PyArena
3784
               *arena)
3785
1.15k
{
3786
1.15k
    stmt_ty p;
3787
1.15k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3788
1.15k
    if (!p)
3789
0
        return NULL;
3790
1.15k
    p->kind = TryStar_kind;
3791
1.15k
    p->v.TryStar.body = body;
3792
1.15k
    p->v.TryStar.handlers = handlers;
3793
1.15k
    p->v.TryStar.orelse = orelse;
3794
1.15k
    p->v.TryStar.finalbody = finalbody;
3795
1.15k
    p->lineno = lineno;
3796
1.15k
    p->col_offset = col_offset;
3797
1.15k
    p->end_lineno = end_lineno;
3798
1.15k
    p->end_col_offset = end_col_offset;
3799
1.15k
    return p;
3800
1.15k
}
3801
3802
stmt_ty
3803
_PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
3804
              end_lineno, int end_col_offset, PyArena *arena)
3805
3.84k
{
3806
3.84k
    stmt_ty p;
3807
3.84k
    if (!test) {
3808
0
        PyErr_SetString(PyExc_ValueError,
3809
0
                        "field 'test' is required for Assert");
3810
0
        return NULL;
3811
0
    }
3812
3.84k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3813
3.84k
    if (!p)
3814
0
        return NULL;
3815
3.84k
    p->kind = Assert_kind;
3816
3.84k
    p->v.Assert.test = test;
3817
3.84k
    p->v.Assert.msg = msg;
3818
3.84k
    p->lineno = lineno;
3819
3.84k
    p->col_offset = col_offset;
3820
3.84k
    p->end_lineno = end_lineno;
3821
3.84k
    p->end_col_offset = end_col_offset;
3822
3.84k
    return p;
3823
3.84k
}
3824
3825
stmt_ty
3826
_PyAST_Import(asdl_alias_seq * names, int is_lazy, int lineno, int col_offset,
3827
              int end_lineno, int end_col_offset, PyArena *arena)
3828
3.34k
{
3829
3.34k
    stmt_ty p;
3830
3.34k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3831
3.34k
    if (!p)
3832
0
        return NULL;
3833
3.34k
    p->kind = Import_kind;
3834
3.34k
    p->v.Import.names = names;
3835
3.34k
    p->v.Import.is_lazy = is_lazy;
3836
3.34k
    p->lineno = lineno;
3837
3.34k
    p->col_offset = col_offset;
3838
3.34k
    p->end_lineno = end_lineno;
3839
3.34k
    p->end_col_offset = end_col_offset;
3840
3.34k
    return p;
3841
3.34k
}
3842
3843
stmt_ty
3844
_PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
3845
                  is_lazy, int lineno, int col_offset, int end_lineno, int
3846
                  end_col_offset, PyArena *arena)
3847
5.96k
{
3848
5.96k
    stmt_ty p;
3849
5.96k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3850
5.96k
    if (!p)
3851
0
        return NULL;
3852
5.96k
    p->kind = ImportFrom_kind;
3853
5.96k
    p->v.ImportFrom.module = module;
3854
5.96k
    p->v.ImportFrom.names = names;
3855
5.96k
    p->v.ImportFrom.level = level;
3856
5.96k
    p->v.ImportFrom.is_lazy = is_lazy;
3857
5.96k
    p->lineno = lineno;
3858
5.96k
    p->col_offset = col_offset;
3859
5.96k
    p->end_lineno = end_lineno;
3860
5.96k
    p->end_col_offset = end_col_offset;
3861
5.96k
    return p;
3862
5.96k
}
3863
3864
stmt_ty
3865
_PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
3866
              end_lineno, int end_col_offset, PyArena *arena)
3867
957
{
3868
957
    stmt_ty p;
3869
957
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3870
957
    if (!p)
3871
0
        return NULL;
3872
957
    p->kind = Global_kind;
3873
957
    p->v.Global.names = names;
3874
957
    p->lineno = lineno;
3875
957
    p->col_offset = col_offset;
3876
957
    p->end_lineno = end_lineno;
3877
957
    p->end_col_offset = end_col_offset;
3878
957
    return p;
3879
957
}
3880
3881
stmt_ty
3882
_PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
3883
                end_lineno, int end_col_offset, PyArena *arena)
3884
290
{
3885
290
    stmt_ty p;
3886
290
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3887
290
    if (!p)
3888
0
        return NULL;
3889
290
    p->kind = Nonlocal_kind;
3890
290
    p->v.Nonlocal.names = names;
3891
290
    p->lineno = lineno;
3892
290
    p->col_offset = col_offset;
3893
290
    p->end_lineno = end_lineno;
3894
290
    p->end_col_offset = end_col_offset;
3895
290
    return p;
3896
290
}
3897
3898
stmt_ty
3899
_PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
3900
            end_col_offset, PyArena *arena)
3901
156k
{
3902
156k
    stmt_ty p;
3903
156k
    if (!value) {
3904
0
        PyErr_SetString(PyExc_ValueError,
3905
0
                        "field 'value' is required for Expr");
3906
0
        return NULL;
3907
0
    }
3908
156k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3909
156k
    if (!p)
3910
0
        return NULL;
3911
156k
    p->kind = Expr_kind;
3912
156k
    p->v.Expr.value = value;
3913
156k
    p->lineno = lineno;
3914
156k
    p->col_offset = col_offset;
3915
156k
    p->end_lineno = end_lineno;
3916
156k
    p->end_col_offset = end_col_offset;
3917
156k
    return p;
3918
156k
}
3919
3920
stmt_ty
3921
_PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
3922
            PyArena *arena)
3923
3.57k
{
3924
3.57k
    stmt_ty p;
3925
3.57k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3926
3.57k
    if (!p)
3927
0
        return NULL;
3928
3.57k
    p->kind = Pass_kind;
3929
3.57k
    p->lineno = lineno;
3930
3.57k
    p->col_offset = col_offset;
3931
3.57k
    p->end_lineno = end_lineno;
3932
3.57k
    p->end_col_offset = end_col_offset;
3933
3.57k
    return p;
3934
3.57k
}
3935
3936
stmt_ty
3937
_PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
3938
             PyArena *arena)
3939
1.69k
{
3940
1.69k
    stmt_ty p;
3941
1.69k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3942
1.69k
    if (!p)
3943
0
        return NULL;
3944
1.69k
    p->kind = Break_kind;
3945
1.69k
    p->lineno = lineno;
3946
1.69k
    p->col_offset = col_offset;
3947
1.69k
    p->end_lineno = end_lineno;
3948
1.69k
    p->end_col_offset = end_col_offset;
3949
1.69k
    return p;
3950
1.69k
}
3951
3952
stmt_ty
3953
_PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
3954
                PyArena *arena)
3955
1.13k
{
3956
1.13k
    stmt_ty p;
3957
1.13k
    p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
3958
1.13k
    if (!p)
3959
0
        return NULL;
3960
1.13k
    p->kind = Continue_kind;
3961
1.13k
    p->lineno = lineno;
3962
1.13k
    p->col_offset = col_offset;
3963
1.13k
    p->end_lineno = end_lineno;
3964
1.13k
    p->end_col_offset = end_col_offset;
3965
1.13k
    return p;
3966
1.13k
}
3967
3968
expr_ty
3969
_PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
3970
              int end_lineno, int end_col_offset, PyArena *arena)
3971
3.68k
{
3972
3.68k
    expr_ty p;
3973
3.68k
    if (!op) {
3974
0
        PyErr_SetString(PyExc_ValueError,
3975
0
                        "field 'op' is required for BoolOp");
3976
0
        return NULL;
3977
0
    }
3978
3.68k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3979
3.68k
    if (!p)
3980
0
        return NULL;
3981
3.68k
    p->kind = BoolOp_kind;
3982
3.68k
    p->v.BoolOp.op = op;
3983
3.68k
    p->v.BoolOp.values = values;
3984
3.68k
    p->lineno = lineno;
3985
3.68k
    p->col_offset = col_offset;
3986
3.68k
    p->end_lineno = end_lineno;
3987
3.68k
    p->end_col_offset = end_col_offset;
3988
3.68k
    return p;
3989
3.68k
}
3990
3991
expr_ty
3992
_PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
3993
                 end_lineno, int end_col_offset, PyArena *arena)
3994
6.71k
{
3995
6.71k
    expr_ty p;
3996
6.71k
    if (!target) {
3997
0
        PyErr_SetString(PyExc_ValueError,
3998
0
                        "field 'target' is required for NamedExpr");
3999
0
        return NULL;
4000
0
    }
4001
6.71k
    if (!value) {
4002
0
        PyErr_SetString(PyExc_ValueError,
4003
0
                        "field 'value' is required for NamedExpr");
4004
0
        return NULL;
4005
0
    }
4006
6.71k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4007
6.71k
    if (!p)
4008
0
        return NULL;
4009
6.71k
    p->kind = NamedExpr_kind;
4010
6.71k
    p->v.NamedExpr.target = target;
4011
6.71k
    p->v.NamedExpr.value = value;
4012
6.71k
    p->lineno = lineno;
4013
6.71k
    p->col_offset = col_offset;
4014
6.71k
    p->end_lineno = end_lineno;
4015
6.71k
    p->end_col_offset = end_col_offset;
4016
6.71k
    return p;
4017
6.71k
}
4018
4019
expr_ty
4020
_PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
4021
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4022
711k
{
4023
711k
    expr_ty p;
4024
711k
    if (!left) {
4025
0
        PyErr_SetString(PyExc_ValueError,
4026
0
                        "field 'left' is required for BinOp");
4027
0
        return NULL;
4028
0
    }
4029
711k
    if (!op) {
4030
0
        PyErr_SetString(PyExc_ValueError,
4031
0
                        "field 'op' is required for BinOp");
4032
0
        return NULL;
4033
0
    }
4034
711k
    if (!right) {
4035
0
        PyErr_SetString(PyExc_ValueError,
4036
0
                        "field 'right' is required for BinOp");
4037
0
        return NULL;
4038
0
    }
4039
711k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4040
711k
    if (!p)
4041
0
        return NULL;
4042
711k
    p->kind = BinOp_kind;
4043
711k
    p->v.BinOp.left = left;
4044
711k
    p->v.BinOp.op = op;
4045
711k
    p->v.BinOp.right = right;
4046
711k
    p->lineno = lineno;
4047
711k
    p->col_offset = col_offset;
4048
711k
    p->end_lineno = end_lineno;
4049
711k
    p->end_col_offset = end_col_offset;
4050
711k
    return p;
4051
711k
}
4052
4053
expr_ty
4054
_PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
4055
               end_lineno, int end_col_offset, PyArena *arena)
4056
370k
{
4057
370k
    expr_ty p;
4058
370k
    if (!op) {
4059
0
        PyErr_SetString(PyExc_ValueError,
4060
0
                        "field 'op' is required for UnaryOp");
4061
0
        return NULL;
4062
0
    }
4063
370k
    if (!operand) {
4064
0
        PyErr_SetString(PyExc_ValueError,
4065
0
                        "field 'operand' is required for UnaryOp");
4066
0
        return NULL;
4067
0
    }
4068
370k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4069
370k
    if (!p)
4070
0
        return NULL;
4071
370k
    p->kind = UnaryOp_kind;
4072
370k
    p->v.UnaryOp.op = op;
4073
370k
    p->v.UnaryOp.operand = operand;
4074
370k
    p->lineno = lineno;
4075
370k
    p->col_offset = col_offset;
4076
370k
    p->end_lineno = end_lineno;
4077
370k
    p->end_col_offset = end_col_offset;
4078
370k
    return p;
4079
370k
}
4080
4081
expr_ty
4082
_PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
4083
              end_lineno, int end_col_offset, PyArena *arena)
4084
15.4k
{
4085
15.4k
    expr_ty p;
4086
15.4k
    if (!args) {
4087
0
        PyErr_SetString(PyExc_ValueError,
4088
0
                        "field 'args' is required for Lambda");
4089
0
        return NULL;
4090
0
    }
4091
15.4k
    if (!body) {
4092
0
        PyErr_SetString(PyExc_ValueError,
4093
0
                        "field 'body' is required for Lambda");
4094
0
        return NULL;
4095
0
    }
4096
15.4k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4097
15.4k
    if (!p)
4098
0
        return NULL;
4099
15.4k
    p->kind = Lambda_kind;
4100
15.4k
    p->v.Lambda.args = args;
4101
15.4k
    p->v.Lambda.body = body;
4102
15.4k
    p->lineno = lineno;
4103
15.4k
    p->col_offset = col_offset;
4104
15.4k
    p->end_lineno = end_lineno;
4105
15.4k
    p->end_col_offset = end_col_offset;
4106
15.4k
    return p;
4107
15.4k
}
4108
4109
expr_ty
4110
_PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
4111
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4112
3.53k
{
4113
3.53k
    expr_ty p;
4114
3.53k
    if (!test) {
4115
0
        PyErr_SetString(PyExc_ValueError,
4116
0
                        "field 'test' is required for IfExp");
4117
0
        return NULL;
4118
0
    }
4119
3.53k
    if (!body) {
4120
0
        PyErr_SetString(PyExc_ValueError,
4121
0
                        "field 'body' is required for IfExp");
4122
0
        return NULL;
4123
0
    }
4124
3.53k
    if (!orelse) {
4125
0
        PyErr_SetString(PyExc_ValueError,
4126
0
                        "field 'orelse' is required for IfExp");
4127
0
        return NULL;
4128
0
    }
4129
3.53k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4130
3.53k
    if (!p)
4131
0
        return NULL;
4132
3.53k
    p->kind = IfExp_kind;
4133
3.53k
    p->v.IfExp.test = test;
4134
3.53k
    p->v.IfExp.body = body;
4135
3.53k
    p->v.IfExp.orelse = orelse;
4136
3.53k
    p->lineno = lineno;
4137
3.53k
    p->col_offset = col_offset;
4138
3.53k
    p->end_lineno = end_lineno;
4139
3.53k
    p->end_col_offset = end_col_offset;
4140
3.53k
    return p;
4141
3.53k
}
4142
4143
expr_ty
4144
_PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
4145
            col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4146
6.75k
{
4147
6.75k
    expr_ty p;
4148
6.75k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4149
6.75k
    if (!p)
4150
0
        return NULL;
4151
6.75k
    p->kind = Dict_kind;
4152
6.75k
    p->v.Dict.keys = keys;
4153
6.75k
    p->v.Dict.values = values;
4154
6.75k
    p->lineno = lineno;
4155
6.75k
    p->col_offset = col_offset;
4156
6.75k
    p->end_lineno = end_lineno;
4157
6.75k
    p->end_col_offset = end_col_offset;
4158
6.75k
    return p;
4159
6.75k
}
4160
4161
expr_ty
4162
_PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
4163
           int end_col_offset, PyArena *arena)
4164
19.6k
{
4165
19.6k
    expr_ty p;
4166
19.6k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4167
19.6k
    if (!p)
4168
0
        return NULL;
4169
19.6k
    p->kind = Set_kind;
4170
19.6k
    p->v.Set.elts = elts;
4171
19.6k
    p->lineno = lineno;
4172
19.6k
    p->col_offset = col_offset;
4173
19.6k
    p->end_lineno = end_lineno;
4174
19.6k
    p->end_col_offset = end_col_offset;
4175
19.6k
    return p;
4176
19.6k
}
4177
4178
expr_ty
4179
_PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
4180
                int col_offset, int end_lineno, int end_col_offset, PyArena
4181
                *arena)
4182
1.32k
{
4183
1.32k
    expr_ty p;
4184
1.32k
    if (!elt) {
4185
0
        PyErr_SetString(PyExc_ValueError,
4186
0
                        "field 'elt' is required for ListComp");
4187
0
        return NULL;
4188
0
    }
4189
1.32k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4190
1.32k
    if (!p)
4191
0
        return NULL;
4192
1.32k
    p->kind = ListComp_kind;
4193
1.32k
    p->v.ListComp.elt = elt;
4194
1.32k
    p->v.ListComp.generators = generators;
4195
1.32k
    p->lineno = lineno;
4196
1.32k
    p->col_offset = col_offset;
4197
1.32k
    p->end_lineno = end_lineno;
4198
1.32k
    p->end_col_offset = end_col_offset;
4199
1.32k
    return p;
4200
1.32k
}
4201
4202
expr_ty
4203
_PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
4204
               int col_offset, int end_lineno, int end_col_offset, PyArena
4205
               *arena)
4206
6.01k
{
4207
6.01k
    expr_ty p;
4208
6.01k
    if (!elt) {
4209
0
        PyErr_SetString(PyExc_ValueError,
4210
0
                        "field 'elt' is required for SetComp");
4211
0
        return NULL;
4212
0
    }
4213
6.01k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4214
6.01k
    if (!p)
4215
0
        return NULL;
4216
6.01k
    p->kind = SetComp_kind;
4217
6.01k
    p->v.SetComp.elt = elt;
4218
6.01k
    p->v.SetComp.generators = generators;
4219
6.01k
    p->lineno = lineno;
4220
6.01k
    p->col_offset = col_offset;
4221
6.01k
    p->end_lineno = end_lineno;
4222
6.01k
    p->end_col_offset = end_col_offset;
4223
6.01k
    return p;
4224
6.01k
}
4225
4226
expr_ty
4227
_PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
4228
                generators, int lineno, int col_offset, int end_lineno, int
4229
                end_col_offset, PyArena *arena)
4230
1.72k
{
4231
1.72k
    expr_ty p;
4232
1.72k
    if (!key) {
4233
0
        PyErr_SetString(PyExc_ValueError,
4234
0
                        "field 'key' is required for DictComp");
4235
0
        return NULL;
4236
0
    }
4237
1.72k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4238
1.72k
    if (!p)
4239
0
        return NULL;
4240
1.72k
    p->kind = DictComp_kind;
4241
1.72k
    p->v.DictComp.key = key;
4242
1.72k
    p->v.DictComp.value = value;
4243
1.72k
    p->v.DictComp.generators = generators;
4244
1.72k
    p->lineno = lineno;
4245
1.72k
    p->col_offset = col_offset;
4246
1.72k
    p->end_lineno = end_lineno;
4247
1.72k
    p->end_col_offset = end_col_offset;
4248
1.72k
    return p;
4249
1.72k
}
4250
4251
expr_ty
4252
_PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
4253
                    lineno, int col_offset, int end_lineno, int end_col_offset,
4254
                    PyArena *arena)
4255
2.43k
{
4256
2.43k
    expr_ty p;
4257
2.43k
    if (!elt) {
4258
0
        PyErr_SetString(PyExc_ValueError,
4259
0
                        "field 'elt' is required for GeneratorExp");
4260
0
        return NULL;
4261
0
    }
4262
2.43k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4263
2.43k
    if (!p)
4264
0
        return NULL;
4265
2.43k
    p->kind = GeneratorExp_kind;
4266
2.43k
    p->v.GeneratorExp.elt = elt;
4267
2.43k
    p->v.GeneratorExp.generators = generators;
4268
2.43k
    p->lineno = lineno;
4269
2.43k
    p->col_offset = col_offset;
4270
2.43k
    p->end_lineno = end_lineno;
4271
2.43k
    p->end_col_offset = end_col_offset;
4272
2.43k
    return p;
4273
2.43k
}
4274
4275
expr_ty
4276
_PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
4277
             end_col_offset, PyArena *arena)
4278
1.33k
{
4279
1.33k
    expr_ty p;
4280
1.33k
    if (!value) {
4281
0
        PyErr_SetString(PyExc_ValueError,
4282
0
                        "field 'value' is required for Await");
4283
0
        return NULL;
4284
0
    }
4285
1.33k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4286
1.33k
    if (!p)
4287
0
        return NULL;
4288
1.33k
    p->kind = Await_kind;
4289
1.33k
    p->v.Await.value = value;
4290
1.33k
    p->lineno = lineno;
4291
1.33k
    p->col_offset = col_offset;
4292
1.33k
    p->end_lineno = end_lineno;
4293
1.33k
    p->end_col_offset = end_col_offset;
4294
1.33k
    return p;
4295
1.33k
}
4296
4297
expr_ty
4298
_PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
4299
             end_col_offset, PyArena *arena)
4300
4.94k
{
4301
4.94k
    expr_ty p;
4302
4.94k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4303
4.94k
    if (!p)
4304
0
        return NULL;
4305
4.94k
    p->kind = Yield_kind;
4306
4.94k
    p->v.Yield.value = value;
4307
4.94k
    p->lineno = lineno;
4308
4.94k
    p->col_offset = col_offset;
4309
4.94k
    p->end_lineno = end_lineno;
4310
4.94k
    p->end_col_offset = end_col_offset;
4311
4.94k
    return p;
4312
4.94k
}
4313
4314
expr_ty
4315
_PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
4316
                 end_col_offset, PyArena *arena)
4317
580
{
4318
580
    expr_ty p;
4319
580
    if (!value) {
4320
0
        PyErr_SetString(PyExc_ValueError,
4321
0
                        "field 'value' is required for YieldFrom");
4322
0
        return NULL;
4323
0
    }
4324
580
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4325
580
    if (!p)
4326
0
        return NULL;
4327
580
    p->kind = YieldFrom_kind;
4328
580
    p->v.YieldFrom.value = value;
4329
580
    p->lineno = lineno;
4330
580
    p->col_offset = col_offset;
4331
580
    p->end_lineno = end_lineno;
4332
580
    p->end_col_offset = end_col_offset;
4333
580
    return p;
4334
580
}
4335
4336
expr_ty
4337
_PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
4338
               int lineno, int col_offset, int end_lineno, int end_col_offset,
4339
               PyArena *arena)
4340
26.9k
{
4341
26.9k
    expr_ty p;
4342
26.9k
    if (!left) {
4343
0
        PyErr_SetString(PyExc_ValueError,
4344
0
                        "field 'left' is required for Compare");
4345
0
        return NULL;
4346
0
    }
4347
26.9k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4348
26.9k
    if (!p)
4349
0
        return NULL;
4350
26.9k
    p->kind = Compare_kind;
4351
26.9k
    p->v.Compare.left = left;
4352
26.9k
    p->v.Compare.ops = ops;
4353
26.9k
    p->v.Compare.comparators = comparators;
4354
26.9k
    p->lineno = lineno;
4355
26.9k
    p->col_offset = col_offset;
4356
26.9k
    p->end_lineno = end_lineno;
4357
26.9k
    p->end_col_offset = end_col_offset;
4358
26.9k
    return p;
4359
26.9k
}
4360
4361
expr_ty
4362
_PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
4363
            int lineno, int col_offset, int end_lineno, int end_col_offset,
4364
            PyArena *arena)
4365
67.2k
{
4366
67.2k
    expr_ty p;
4367
67.2k
    if (!func) {
4368
0
        PyErr_SetString(PyExc_ValueError,
4369
0
                        "field 'func' is required for Call");
4370
0
        return NULL;
4371
0
    }
4372
67.2k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4373
67.2k
    if (!p)
4374
0
        return NULL;
4375
67.2k
    p->kind = Call_kind;
4376
67.2k
    p->v.Call.func = func;
4377
67.2k
    p->v.Call.args = args;
4378
67.2k
    p->v.Call.keywords = keywords;
4379
67.2k
    p->lineno = lineno;
4380
67.2k
    p->col_offset = col_offset;
4381
67.2k
    p->end_lineno = end_lineno;
4382
67.2k
    p->end_col_offset = end_col_offset;
4383
67.2k
    return p;
4384
67.2k
}
4385
4386
expr_ty
4387
_PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
4388
                      lineno, int col_offset, int end_lineno, int
4389
                      end_col_offset, PyArena *arena)
4390
17.4k
{
4391
17.4k
    expr_ty p;
4392
17.4k
    if (!value) {
4393
0
        PyErr_SetString(PyExc_ValueError,
4394
0
                        "field 'value' is required for FormattedValue");
4395
0
        return NULL;
4396
0
    }
4397
17.4k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4398
17.4k
    if (!p)
4399
0
        return NULL;
4400
17.4k
    p->kind = FormattedValue_kind;
4401
17.4k
    p->v.FormattedValue.value = value;
4402
17.4k
    p->v.FormattedValue.conversion = conversion;
4403
17.4k
    p->v.FormattedValue.format_spec = format_spec;
4404
17.4k
    p->lineno = lineno;
4405
17.4k
    p->col_offset = col_offset;
4406
17.4k
    p->end_lineno = end_lineno;
4407
17.4k
    p->end_col_offset = end_col_offset;
4408
17.4k
    return p;
4409
17.4k
}
4410
4411
expr_ty
4412
_PyAST_Interpolation(expr_ty value, constant str, int conversion, expr_ty
4413
                     format_spec, int lineno, int col_offset, int end_lineno,
4414
                     int end_col_offset, PyArena *arena)
4415
5.26k
{
4416
5.26k
    expr_ty p;
4417
5.26k
    if (!value) {
4418
0
        PyErr_SetString(PyExc_ValueError,
4419
0
                        "field 'value' is required for Interpolation");
4420
0
        return NULL;
4421
0
    }
4422
5.26k
    if (!str) {
4423
0
        PyErr_SetString(PyExc_ValueError,
4424
0
                        "field 'str' is required for Interpolation");
4425
0
        return NULL;
4426
0
    }
4427
5.26k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4428
5.26k
    if (!p)
4429
0
        return NULL;
4430
5.26k
    p->kind = Interpolation_kind;
4431
5.26k
    p->v.Interpolation.value = value;
4432
5.26k
    p->v.Interpolation.str = str;
4433
5.26k
    p->v.Interpolation.conversion = conversion;
4434
5.26k
    p->v.Interpolation.format_spec = format_spec;
4435
5.26k
    p->lineno = lineno;
4436
5.26k
    p->col_offset = col_offset;
4437
5.26k
    p->end_lineno = end_lineno;
4438
5.26k
    p->end_col_offset = end_col_offset;
4439
5.26k
    return p;
4440
5.26k
}
4441
4442
expr_ty
4443
_PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
4444
                 end_lineno, int end_col_offset, PyArena *arena)
4445
44.3k
{
4446
44.3k
    expr_ty p;
4447
44.3k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4448
44.3k
    if (!p)
4449
0
        return NULL;
4450
44.3k
    p->kind = JoinedStr_kind;
4451
44.3k
    p->v.JoinedStr.values = values;
4452
44.3k
    p->lineno = lineno;
4453
44.3k
    p->col_offset = col_offset;
4454
44.3k
    p->end_lineno = end_lineno;
4455
44.3k
    p->end_col_offset = end_col_offset;
4456
44.3k
    return p;
4457
44.3k
}
4458
4459
expr_ty
4460
_PyAST_TemplateStr(asdl_expr_seq * values, int lineno, int col_offset, int
4461
                   end_lineno, int end_col_offset, PyArena *arena)
4462
7.82k
{
4463
7.82k
    expr_ty p;
4464
7.82k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4465
7.82k
    if (!p)
4466
0
        return NULL;
4467
7.82k
    p->kind = TemplateStr_kind;
4468
7.82k
    p->v.TemplateStr.values = values;
4469
7.82k
    p->lineno = lineno;
4470
7.82k
    p->col_offset = col_offset;
4471
7.82k
    p->end_lineno = end_lineno;
4472
7.82k
    p->end_col_offset = end_col_offset;
4473
7.82k
    return p;
4474
7.82k
}
4475
4476
expr_ty
4477
_PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
4478
                end_lineno, int end_col_offset, PyArena *arena)
4479
1.08M
{
4480
1.08M
    expr_ty p;
4481
1.08M
    if (!value) {
4482
0
        PyErr_SetString(PyExc_ValueError,
4483
0
                        "field 'value' is required for Constant");
4484
0
        return NULL;
4485
0
    }
4486
1.08M
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4487
1.08M
    if (!p)
4488
0
        return NULL;
4489
1.08M
    p->kind = Constant_kind;
4490
1.08M
    p->v.Constant.value = value;
4491
1.08M
    p->v.Constant.kind = kind;
4492
1.08M
    p->lineno = lineno;
4493
1.08M
    p->col_offset = col_offset;
4494
1.08M
    p->end_lineno = end_lineno;
4495
1.08M
    p->end_col_offset = end_col_offset;
4496
1.08M
    return p;
4497
1.08M
}
4498
4499
expr_ty
4500
_PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
4501
                 lineno, int col_offset, int end_lineno, int end_col_offset,
4502
                 PyArena *arena)
4503
50.4k
{
4504
50.4k
    expr_ty p;
4505
50.4k
    if (!value) {
4506
0
        PyErr_SetString(PyExc_ValueError,
4507
0
                        "field 'value' is required for Attribute");
4508
0
        return NULL;
4509
0
    }
4510
50.4k
    if (!attr) {
4511
0
        PyErr_SetString(PyExc_ValueError,
4512
0
                        "field 'attr' is required for Attribute");
4513
0
        return NULL;
4514
0
    }
4515
50.4k
    if (!ctx) {
4516
0
        PyErr_SetString(PyExc_ValueError,
4517
0
                        "field 'ctx' is required for Attribute");
4518
0
        return NULL;
4519
0
    }
4520
50.4k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4521
50.4k
    if (!p)
4522
0
        return NULL;
4523
50.4k
    p->kind = Attribute_kind;
4524
50.4k
    p->v.Attribute.value = value;
4525
50.4k
    p->v.Attribute.attr = attr;
4526
50.4k
    p->v.Attribute.ctx = ctx;
4527
50.4k
    p->lineno = lineno;
4528
50.4k
    p->col_offset = col_offset;
4529
50.4k
    p->end_lineno = end_lineno;
4530
50.4k
    p->end_col_offset = end_col_offset;
4531
50.4k
    return p;
4532
50.4k
}
4533
4534
expr_ty
4535
_PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
4536
                 int col_offset, int end_lineno, int end_col_offset, PyArena
4537
                 *arena)
4538
68.7k
{
4539
68.7k
    expr_ty p;
4540
68.7k
    if (!value) {
4541
0
        PyErr_SetString(PyExc_ValueError,
4542
0
                        "field 'value' is required for Subscript");
4543
0
        return NULL;
4544
0
    }
4545
68.7k
    if (!slice) {
4546
0
        PyErr_SetString(PyExc_ValueError,
4547
0
                        "field 'slice' is required for Subscript");
4548
0
        return NULL;
4549
0
    }
4550
68.7k
    if (!ctx) {
4551
0
        PyErr_SetString(PyExc_ValueError,
4552
0
                        "field 'ctx' is required for Subscript");
4553
0
        return NULL;
4554
0
    }
4555
68.7k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4556
68.7k
    if (!p)
4557
0
        return NULL;
4558
68.7k
    p->kind = Subscript_kind;
4559
68.7k
    p->v.Subscript.value = value;
4560
68.7k
    p->v.Subscript.slice = slice;
4561
68.7k
    p->v.Subscript.ctx = ctx;
4562
68.7k
    p->lineno = lineno;
4563
68.7k
    p->col_offset = col_offset;
4564
68.7k
    p->end_lineno = end_lineno;
4565
68.7k
    p->end_col_offset = end_col_offset;
4566
68.7k
    return p;
4567
68.7k
}
4568
4569
expr_ty
4570
_PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
4571
               int end_lineno, int end_col_offset, PyArena *arena)
4572
57.2k
{
4573
57.2k
    expr_ty p;
4574
57.2k
    if (!value) {
4575
0
        PyErr_SetString(PyExc_ValueError,
4576
0
                        "field 'value' is required for Starred");
4577
0
        return NULL;
4578
0
    }
4579
57.2k
    if (!ctx) {
4580
0
        PyErr_SetString(PyExc_ValueError,
4581
0
                        "field 'ctx' is required for Starred");
4582
0
        return NULL;
4583
0
    }
4584
57.2k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4585
57.2k
    if (!p)
4586
0
        return NULL;
4587
57.2k
    p->kind = Starred_kind;
4588
57.2k
    p->v.Starred.value = value;
4589
57.2k
    p->v.Starred.ctx = ctx;
4590
57.2k
    p->lineno = lineno;
4591
57.2k
    p->col_offset = col_offset;
4592
57.2k
    p->end_lineno = end_lineno;
4593
57.2k
    p->end_col_offset = end_col_offset;
4594
57.2k
    return p;
4595
57.2k
}
4596
4597
expr_ty
4598
_PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
4599
            end_lineno, int end_col_offset, PyArena *arena)
4600
4.46M
{
4601
4.46M
    expr_ty p;
4602
4.46M
    if (!id) {
4603
0
        PyErr_SetString(PyExc_ValueError,
4604
0
                        "field 'id' is required for Name");
4605
0
        return NULL;
4606
0
    }
4607
4.46M
    if (!ctx) {
4608
0
        PyErr_SetString(PyExc_ValueError,
4609
0
                        "field 'ctx' is required for Name");
4610
0
        return NULL;
4611
0
    }
4612
4.46M
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4613
4.46M
    if (!p)
4614
0
        return NULL;
4615
4.46M
    p->kind = Name_kind;
4616
4.46M
    p->v.Name.id = id;
4617
4.46M
    p->v.Name.ctx = ctx;
4618
4.46M
    p->lineno = lineno;
4619
4.46M
    p->col_offset = col_offset;
4620
4.46M
    p->end_lineno = end_lineno;
4621
4.46M
    p->end_col_offset = end_col_offset;
4622
4.46M
    return p;
4623
4.46M
}
4624
4625
expr_ty
4626
_PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
4627
            col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4628
54.0k
{
4629
54.0k
    expr_ty p;
4630
54.0k
    if (!ctx) {
4631
0
        PyErr_SetString(PyExc_ValueError,
4632
0
                        "field 'ctx' is required for List");
4633
0
        return NULL;
4634
0
    }
4635
54.0k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4636
54.0k
    if (!p)
4637
0
        return NULL;
4638
54.0k
    p->kind = List_kind;
4639
54.0k
    p->v.List.elts = elts;
4640
54.0k
    p->v.List.ctx = ctx;
4641
54.0k
    p->lineno = lineno;
4642
54.0k
    p->col_offset = col_offset;
4643
54.0k
    p->end_lineno = end_lineno;
4644
54.0k
    p->end_col_offset = end_col_offset;
4645
54.0k
    return p;
4646
54.0k
}
4647
4648
expr_ty
4649
_PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
4650
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4651
179k
{
4652
179k
    expr_ty p;
4653
179k
    if (!ctx) {
4654
0
        PyErr_SetString(PyExc_ValueError,
4655
0
                        "field 'ctx' is required for Tuple");
4656
0
        return NULL;
4657
0
    }
4658
179k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4659
179k
    if (!p)
4660
0
        return NULL;
4661
179k
    p->kind = Tuple_kind;
4662
179k
    p->v.Tuple.elts = elts;
4663
179k
    p->v.Tuple.ctx = ctx;
4664
179k
    p->lineno = lineno;
4665
179k
    p->col_offset = col_offset;
4666
179k
    p->end_lineno = end_lineno;
4667
179k
    p->end_col_offset = end_col_offset;
4668
179k
    return p;
4669
179k
}
4670
4671
expr_ty
4672
_PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
4673
             col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4674
22.3k
{
4675
22.3k
    expr_ty p;
4676
22.3k
    p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
4677
22.3k
    if (!p)
4678
0
        return NULL;
4679
22.3k
    p->kind = Slice_kind;
4680
22.3k
    p->v.Slice.lower = lower;
4681
22.3k
    p->v.Slice.upper = upper;
4682
22.3k
    p->v.Slice.step = step;
4683
22.3k
    p->lineno = lineno;
4684
22.3k
    p->col_offset = col_offset;
4685
22.3k
    p->end_lineno = end_lineno;
4686
22.3k
    p->end_col_offset = end_col_offset;
4687
22.3k
    return p;
4688
22.3k
}
4689
4690
comprehension_ty
4691
_PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
4692
                     is_async, PyArena *arena)
4693
16.8k
{
4694
16.8k
    comprehension_ty p;
4695
16.8k
    if (!target) {
4696
0
        PyErr_SetString(PyExc_ValueError,
4697
0
                        "field 'target' is required for comprehension");
4698
0
        return NULL;
4699
0
    }
4700
16.8k
    if (!iter) {
4701
0
        PyErr_SetString(PyExc_ValueError,
4702
0
                        "field 'iter' is required for comprehension");
4703
0
        return NULL;
4704
0
    }
4705
16.8k
    p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
4706
16.8k
    if (!p)
4707
0
        return NULL;
4708
16.8k
    p->target = target;
4709
16.8k
    p->iter = iter;
4710
16.8k
    p->ifs = ifs;
4711
16.8k
    p->is_async = is_async;
4712
16.8k
    return p;
4713
16.8k
}
4714
4715
excepthandler_ty
4716
_PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
4717
                     lineno, int col_offset, int end_lineno, int
4718
                     end_col_offset, PyArena *arena)
4719
9.62k
{
4720
9.62k
    excepthandler_ty p;
4721
9.62k
    p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
4722
9.62k
    if (!p)
4723
0
        return NULL;
4724
9.62k
    p->kind = ExceptHandler_kind;
4725
9.62k
    p->v.ExceptHandler.type = type;
4726
9.62k
    p->v.ExceptHandler.name = name;
4727
9.62k
    p->v.ExceptHandler.body = body;
4728
9.62k
    p->lineno = lineno;
4729
9.62k
    p->col_offset = col_offset;
4730
9.62k
    p->end_lineno = end_lineno;
4731
9.62k
    p->end_col_offset = end_col_offset;
4732
9.62k
    return p;
4733
9.62k
}
4734
4735
arguments_ty
4736
_PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
4737
                 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
4738
                 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
4739
                 *arena)
4740
42.1k
{
4741
42.1k
    arguments_ty p;
4742
42.1k
    p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
4743
42.1k
    if (!p)
4744
0
        return NULL;
4745
42.1k
    p->posonlyargs = posonlyargs;
4746
42.1k
    p->args = args;
4747
42.1k
    p->vararg = vararg;
4748
42.1k
    p->kwonlyargs = kwonlyargs;
4749
42.1k
    p->kw_defaults = kw_defaults;
4750
42.1k
    p->kwarg = kwarg;
4751
42.1k
    p->defaults = defaults;
4752
42.1k
    return p;
4753
42.1k
}
4754
4755
arg_ty
4756
_PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
4757
           int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
4758
91.5M
{
4759
91.5M
    arg_ty p;
4760
91.5M
    if (!arg) {
4761
0
        PyErr_SetString(PyExc_ValueError,
4762
0
                        "field 'arg' is required for arg");
4763
0
        return NULL;
4764
0
    }
4765
91.5M
    p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
4766
91.5M
    if (!p)
4767
0
        return NULL;
4768
91.5M
    p->arg = arg;
4769
91.5M
    p->annotation = annotation;
4770
91.5M
    p->type_comment = type_comment;
4771
91.5M
    p->lineno = lineno;
4772
91.5M
    p->col_offset = col_offset;
4773
91.5M
    p->end_lineno = end_lineno;
4774
91.5M
    p->end_col_offset = end_col_offset;
4775
91.5M
    return p;
4776
91.5M
}
4777
4778
keyword_ty
4779
_PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
4780
               end_lineno, int end_col_offset, PyArena *arena)
4781
34.5k
{
4782
34.5k
    keyword_ty p;
4783
34.5k
    if (!value) {
4784
0
        PyErr_SetString(PyExc_ValueError,
4785
0
                        "field 'value' is required for keyword");
4786
0
        return NULL;
4787
0
    }
4788
34.5k
    p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
4789
34.5k
    if (!p)
4790
0
        return NULL;
4791
34.5k
    p->arg = arg;
4792
34.5k
    p->value = value;
4793
34.5k
    p->lineno = lineno;
4794
34.5k
    p->col_offset = col_offset;
4795
34.5k
    p->end_lineno = end_lineno;
4796
34.5k
    p->end_col_offset = end_col_offset;
4797
34.5k
    return p;
4798
34.5k
}
4799
4800
alias_ty
4801
_PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
4802
             int end_lineno, int end_col_offset, PyArena *arena)
4803
26.3k
{
4804
26.3k
    alias_ty p;
4805
26.3k
    if (!name) {
4806
0
        PyErr_SetString(PyExc_ValueError,
4807
0
                        "field 'name' is required for alias");
4808
0
        return NULL;
4809
0
    }
4810
26.3k
    p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
4811
26.3k
    if (!p)
4812
0
        return NULL;
4813
26.3k
    p->name = name;
4814
26.3k
    p->asname = asname;
4815
26.3k
    p->lineno = lineno;
4816
26.3k
    p->col_offset = col_offset;
4817
26.3k
    p->end_lineno = end_lineno;
4818
26.3k
    p->end_col_offset = end_col_offset;
4819
26.3k
    return p;
4820
26.3k
}
4821
4822
withitem_ty
4823
_PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
4824
17.3k
{
4825
17.3k
    withitem_ty p;
4826
17.3k
    if (!context_expr) {
4827
0
        PyErr_SetString(PyExc_ValueError,
4828
0
                        "field 'context_expr' is required for withitem");
4829
0
        return NULL;
4830
0
    }
4831
17.3k
    p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
4832
17.3k
    if (!p)
4833
0
        return NULL;
4834
17.3k
    p->context_expr = context_expr;
4835
17.3k
    p->optional_vars = optional_vars;
4836
17.3k
    return p;
4837
17.3k
}
4838
4839
match_case_ty
4840
_PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
4841
                  PyArena *arena)
4842
4.98k
{
4843
4.98k
    match_case_ty p;
4844
4.98k
    if (!pattern) {
4845
0
        PyErr_SetString(PyExc_ValueError,
4846
0
                        "field 'pattern' is required for match_case");
4847
0
        return NULL;
4848
0
    }
4849
4.98k
    p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
4850
4.98k
    if (!p)
4851
0
        return NULL;
4852
4.98k
    p->pattern = pattern;
4853
4.98k
    p->guard = guard;
4854
4.98k
    p->body = body;
4855
4.98k
    return p;
4856
4.98k
}
4857
4858
pattern_ty
4859
_PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
4860
                  int end_col_offset, PyArena *arena)
4861
14.8k
{
4862
14.8k
    pattern_ty p;
4863
14.8k
    if (!value) {
4864
0
        PyErr_SetString(PyExc_ValueError,
4865
0
                        "field 'value' is required for MatchValue");
4866
0
        return NULL;
4867
0
    }
4868
14.8k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4869
14.8k
    if (!p)
4870
0
        return NULL;
4871
14.8k
    p->kind = MatchValue_kind;
4872
14.8k
    p->v.MatchValue.value = value;
4873
14.8k
    p->lineno = lineno;
4874
14.8k
    p->col_offset = col_offset;
4875
14.8k
    p->end_lineno = end_lineno;
4876
14.8k
    p->end_col_offset = end_col_offset;
4877
14.8k
    return p;
4878
14.8k
}
4879
4880
pattern_ty
4881
_PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
4882
                      end_lineno, int end_col_offset, PyArena *arena)
4883
1.00k
{
4884
1.00k
    pattern_ty p;
4885
1.00k
    if (!value) {
4886
0
        PyErr_SetString(PyExc_ValueError,
4887
0
                        "field 'value' is required for MatchSingleton");
4888
0
        return NULL;
4889
0
    }
4890
1.00k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4891
1.00k
    if (!p)
4892
0
        return NULL;
4893
1.00k
    p->kind = MatchSingleton_kind;
4894
1.00k
    p->v.MatchSingleton.value = value;
4895
1.00k
    p->lineno = lineno;
4896
1.00k
    p->col_offset = col_offset;
4897
1.00k
    p->end_lineno = end_lineno;
4898
1.00k
    p->end_col_offset = end_col_offset;
4899
1.00k
    return p;
4900
1.00k
}
4901
4902
pattern_ty
4903
_PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
4904
                     int end_lineno, int end_col_offset, PyArena *arena)
4905
4.56k
{
4906
4.56k
    pattern_ty p;
4907
4.56k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4908
4.56k
    if (!p)
4909
0
        return NULL;
4910
4.56k
    p->kind = MatchSequence_kind;
4911
4.56k
    p->v.MatchSequence.patterns = patterns;
4912
4.56k
    p->lineno = lineno;
4913
4.56k
    p->col_offset = col_offset;
4914
4.56k
    p->end_lineno = end_lineno;
4915
4.56k
    p->end_col_offset = end_col_offset;
4916
4.56k
    return p;
4917
4.56k
}
4918
4919
pattern_ty
4920
_PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
4921
                    identifier rest, int lineno, int col_offset, int
4922
                    end_lineno, int end_col_offset, PyArena *arena)
4923
1.02k
{
4924
1.02k
    pattern_ty p;
4925
1.02k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4926
1.02k
    if (!p)
4927
0
        return NULL;
4928
1.02k
    p->kind = MatchMapping_kind;
4929
1.02k
    p->v.MatchMapping.keys = keys;
4930
1.02k
    p->v.MatchMapping.patterns = patterns;
4931
1.02k
    p->v.MatchMapping.rest = rest;
4932
1.02k
    p->lineno = lineno;
4933
1.02k
    p->col_offset = col_offset;
4934
1.02k
    p->end_lineno = end_lineno;
4935
1.02k
    p->end_col_offset = end_col_offset;
4936
1.02k
    return p;
4937
1.02k
}
4938
4939
pattern_ty
4940
_PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
4941
                  * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
4942
                  col_offset, int end_lineno, int end_col_offset, PyArena
4943
                  *arena)
4944
3.03k
{
4945
3.03k
    pattern_ty p;
4946
3.03k
    if (!cls) {
4947
0
        PyErr_SetString(PyExc_ValueError,
4948
0
                        "field 'cls' is required for MatchClass");
4949
0
        return NULL;
4950
0
    }
4951
3.03k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4952
3.03k
    if (!p)
4953
0
        return NULL;
4954
3.03k
    p->kind = MatchClass_kind;
4955
3.03k
    p->v.MatchClass.cls = cls;
4956
3.03k
    p->v.MatchClass.patterns = patterns;
4957
3.03k
    p->v.MatchClass.kwd_attrs = kwd_attrs;
4958
3.03k
    p->v.MatchClass.kwd_patterns = kwd_patterns;
4959
3.03k
    p->lineno = lineno;
4960
3.03k
    p->col_offset = col_offset;
4961
3.03k
    p->end_lineno = end_lineno;
4962
3.03k
    p->end_col_offset = end_col_offset;
4963
3.03k
    return p;
4964
3.03k
}
4965
4966
pattern_ty
4967
_PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
4968
                 int end_col_offset, PyArena *arena)
4969
1.70k
{
4970
1.70k
    pattern_ty p;
4971
1.70k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4972
1.70k
    if (!p)
4973
0
        return NULL;
4974
1.70k
    p->kind = MatchStar_kind;
4975
1.70k
    p->v.MatchStar.name = name;
4976
1.70k
    p->lineno = lineno;
4977
1.70k
    p->col_offset = col_offset;
4978
1.70k
    p->end_lineno = end_lineno;
4979
1.70k
    p->end_col_offset = end_col_offset;
4980
1.70k
    return p;
4981
1.70k
}
4982
4983
pattern_ty
4984
_PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
4985
               int end_lineno, int end_col_offset, PyArena *arena)
4986
27.6k
{
4987
27.6k
    pattern_ty p;
4988
27.6k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
4989
27.6k
    if (!p)
4990
0
        return NULL;
4991
27.6k
    p->kind = MatchAs_kind;
4992
27.6k
    p->v.MatchAs.pattern = pattern;
4993
27.6k
    p->v.MatchAs.name = name;
4994
27.6k
    p->lineno = lineno;
4995
27.6k
    p->col_offset = col_offset;
4996
27.6k
    p->end_lineno = end_lineno;
4997
27.6k
    p->end_col_offset = end_col_offset;
4998
27.6k
    return p;
4999
27.6k
}
5000
5001
pattern_ty
5002
_PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
5003
               end_lineno, int end_col_offset, PyArena *arena)
5004
9.35k
{
5005
9.35k
    pattern_ty p;
5006
9.35k
    p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
5007
9.35k
    if (!p)
5008
0
        return NULL;
5009
9.35k
    p->kind = MatchOr_kind;
5010
9.35k
    p->v.MatchOr.patterns = patterns;
5011
9.35k
    p->lineno = lineno;
5012
9.35k
    p->col_offset = col_offset;
5013
9.35k
    p->end_lineno = end_lineno;
5014
9.35k
    p->end_col_offset = end_col_offset;
5015
9.35k
    return p;
5016
9.35k
}
5017
5018
type_ignore_ty
5019
_PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
5020
834
{
5021
834
    type_ignore_ty p;
5022
834
    if (!tag) {
5023
0
        PyErr_SetString(PyExc_ValueError,
5024
0
                        "field 'tag' is required for TypeIgnore");
5025
0
        return NULL;
5026
0
    }
5027
834
    p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
5028
834
    if (!p)
5029
0
        return NULL;
5030
834
    p->kind = TypeIgnore_kind;
5031
834
    p->v.TypeIgnore.lineno = lineno;
5032
834
    p->v.TypeIgnore.tag = tag;
5033
834
    return p;
5034
834
}
5035
5036
type_param_ty
5037
_PyAST_TypeVar(identifier name, expr_ty bound, expr_ty default_value, int
5038
               lineno, int col_offset, int end_lineno, int end_col_offset,
5039
               PyArena *arena)
5040
15.6k
{
5041
15.6k
    type_param_ty p;
5042
15.6k
    if (!name) {
5043
0
        PyErr_SetString(PyExc_ValueError,
5044
0
                        "field 'name' is required for TypeVar");
5045
0
        return NULL;
5046
0
    }
5047
15.6k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5048
15.6k
    if (!p)
5049
0
        return NULL;
5050
15.6k
    p->kind = TypeVar_kind;
5051
15.6k
    p->v.TypeVar.name = name;
5052
15.6k
    p->v.TypeVar.bound = bound;
5053
15.6k
    p->v.TypeVar.default_value = default_value;
5054
15.6k
    p->lineno = lineno;
5055
15.6k
    p->col_offset = col_offset;
5056
15.6k
    p->end_lineno = end_lineno;
5057
15.6k
    p->end_col_offset = end_col_offset;
5058
15.6k
    return p;
5059
15.6k
}
5060
5061
type_param_ty
5062
_PyAST_ParamSpec(identifier name, expr_ty default_value, int lineno, int
5063
                 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
5064
1.33k
{
5065
1.33k
    type_param_ty p;
5066
1.33k
    if (!name) {
5067
0
        PyErr_SetString(PyExc_ValueError,
5068
0
                        "field 'name' is required for ParamSpec");
5069
0
        return NULL;
5070
0
    }
5071
1.33k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5072
1.33k
    if (!p)
5073
0
        return NULL;
5074
1.33k
    p->kind = ParamSpec_kind;
5075
1.33k
    p->v.ParamSpec.name = name;
5076
1.33k
    p->v.ParamSpec.default_value = default_value;
5077
1.33k
    p->lineno = lineno;
5078
1.33k
    p->col_offset = col_offset;
5079
1.33k
    p->end_lineno = end_lineno;
5080
1.33k
    p->end_col_offset = end_col_offset;
5081
1.33k
    return p;
5082
1.33k
}
5083
5084
type_param_ty
5085
_PyAST_TypeVarTuple(identifier name, expr_ty default_value, int lineno, int
5086
                    col_offset, int end_lineno, int end_col_offset, PyArena
5087
                    *arena)
5088
2.88k
{
5089
2.88k
    type_param_ty p;
5090
2.88k
    if (!name) {
5091
0
        PyErr_SetString(PyExc_ValueError,
5092
0
                        "field 'name' is required for TypeVarTuple");
5093
0
        return NULL;
5094
0
    }
5095
2.88k
    p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
5096
2.88k
    if (!p)
5097
0
        return NULL;
5098
2.88k
    p->kind = TypeVarTuple_kind;
5099
2.88k
    p->v.TypeVarTuple.name = name;
5100
2.88k
    p->v.TypeVarTuple.default_value = default_value;
5101
2.88k
    p->lineno = lineno;
5102
2.88k
    p->col_offset = col_offset;
5103
2.88k
    p->end_lineno = end_lineno;
5104
2.88k
    p->end_col_offset = end_col_offset;
5105
2.88k
    return p;
5106
2.88k
}
5107
5108
5109
PyObject*
5110
ast2obj_mod(struct ast_state *state, void* _o)
5111
1.95k
{
5112
1.95k
    mod_ty o = (mod_ty)_o;
5113
1.95k
    PyObject *result = NULL, *value = NULL;
5114
1.95k
    PyTypeObject *tp;
5115
1.95k
    if (!o) {
5116
0
        Py_RETURN_NONE;
5117
0
    }
5118
1.95k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5119
0
        return NULL;
5120
0
    }
5121
1.95k
    switch (o->kind) {
5122
1.34k
    case Module_kind:
5123
1.34k
        tp = (PyTypeObject *)state->Module_type;
5124
1.34k
        result = PyType_GenericNew(tp, NULL, NULL);
5125
1.34k
        if (!result) goto failed;
5126
1.34k
        value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
5127
1.34k
        if (!value) goto failed;
5128
1.34k
        if (PyObject_SetAttr(result, state->body, value) == -1)
5129
0
            goto failed;
5130
1.34k
        Py_DECREF(value);
5131
1.34k
        value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
5132
1.34k
                             ast2obj_type_ignore);
5133
1.34k
        if (!value) goto failed;
5134
1.34k
        if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
5135
0
            goto failed;
5136
1.34k
        Py_DECREF(value);
5137
1.34k
        break;
5138
385
    case Interactive_kind:
5139
385
        tp = (PyTypeObject *)state->Interactive_type;
5140
385
        result = PyType_GenericNew(tp, NULL, NULL);
5141
385
        if (!result) goto failed;
5142
385
        value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
5143
385
                             ast2obj_stmt);
5144
385
        if (!value) goto failed;
5145
385
        if (PyObject_SetAttr(result, state->body, value) == -1)
5146
0
            goto failed;
5147
385
        Py_DECREF(value);
5148
385
        break;
5149
228
    case Expression_kind:
5150
228
        tp = (PyTypeObject *)state->Expression_type;
5151
228
        result = PyType_GenericNew(tp, NULL, NULL);
5152
228
        if (!result) goto failed;
5153
228
        value = ast2obj_expr(state, o->v.Expression.body);
5154
228
        if (!value) goto failed;
5155
228
        if (PyObject_SetAttr(result, state->body, value) == -1)
5156
0
            goto failed;
5157
228
        Py_DECREF(value);
5158
228
        break;
5159
0
    case FunctionType_kind:
5160
0
        tp = (PyTypeObject *)state->FunctionType_type;
5161
0
        result = PyType_GenericNew(tp, NULL, NULL);
5162
0
        if (!result) goto failed;
5163
0
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
5164
0
                             ast2obj_expr);
5165
0
        if (!value) goto failed;
5166
0
        if (PyObject_SetAttr(result, state->argtypes, value) == -1)
5167
0
            goto failed;
5168
0
        Py_DECREF(value);
5169
0
        value = ast2obj_expr(state, o->v.FunctionType.returns);
5170
0
        if (!value) goto failed;
5171
0
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5172
0
            goto failed;
5173
0
        Py_DECREF(value);
5174
0
        break;
5175
1.95k
    }
5176
1.95k
    Py_LeaveRecursiveCall();
5177
1.95k
    return result;
5178
0
failed:
5179
0
    Py_LeaveRecursiveCall();
5180
0
    Py_XDECREF(value);
5181
0
    Py_XDECREF(result);
5182
0
    return NULL;
5183
1.95k
}
5184
5185
PyObject*
5186
ast2obj_stmt(struct ast_state *state, void* _o)
5187
30.7k
{
5188
30.7k
    stmt_ty o = (stmt_ty)_o;
5189
30.7k
    PyObject *result = NULL, *value = NULL;
5190
30.7k
    PyTypeObject *tp;
5191
30.7k
    if (!o) {
5192
0
        Py_RETURN_NONE;
5193
0
    }
5194
30.7k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5195
0
        return NULL;
5196
0
    }
5197
30.7k
    switch (o->kind) {
5198
924
    case FunctionDef_kind:
5199
924
        tp = (PyTypeObject *)state->FunctionDef_type;
5200
924
        result = PyType_GenericNew(tp, NULL, NULL);
5201
924
        if (!result) goto failed;
5202
924
        value = ast2obj_identifier(state, o->v.FunctionDef.name);
5203
924
        if (!value) goto failed;
5204
924
        if (PyObject_SetAttr(result, state->name, value) == -1)
5205
0
            goto failed;
5206
924
        Py_DECREF(value);
5207
924
        value = ast2obj_arguments(state, o->v.FunctionDef.args);
5208
924
        if (!value) goto failed;
5209
924
        if (PyObject_SetAttr(result, state->args, value) == -1)
5210
0
            goto failed;
5211
924
        Py_DECREF(value);
5212
924
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
5213
924
                             ast2obj_stmt);
5214
924
        if (!value) goto failed;
5215
924
        if (PyObject_SetAttr(result, state->body, value) == -1)
5216
0
            goto failed;
5217
924
        Py_DECREF(value);
5218
924
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
5219
924
                             ast2obj_expr);
5220
924
        if (!value) goto failed;
5221
924
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5222
0
            goto failed;
5223
924
        Py_DECREF(value);
5224
924
        value = ast2obj_expr(state, o->v.FunctionDef.returns);
5225
924
        if (!value) goto failed;
5226
924
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5227
0
            goto failed;
5228
924
        Py_DECREF(value);
5229
924
        value = ast2obj_string(state, o->v.FunctionDef.type_comment);
5230
924
        if (!value) goto failed;
5231
924
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5232
0
            goto failed;
5233
924
        Py_DECREF(value);
5234
924
        value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.type_params,
5235
924
                             ast2obj_type_param);
5236
924
        if (!value) goto failed;
5237
924
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5238
0
            goto failed;
5239
924
        Py_DECREF(value);
5240
924
        break;
5241
422
    case AsyncFunctionDef_kind:
5242
422
        tp = (PyTypeObject *)state->AsyncFunctionDef_type;
5243
422
        result = PyType_GenericNew(tp, NULL, NULL);
5244
422
        if (!result) goto failed;
5245
422
        value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
5246
422
        if (!value) goto failed;
5247
422
        if (PyObject_SetAttr(result, state->name, value) == -1)
5248
0
            goto failed;
5249
422
        Py_DECREF(value);
5250
422
        value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
5251
422
        if (!value) goto failed;
5252
422
        if (PyObject_SetAttr(result, state->args, value) == -1)
5253
0
            goto failed;
5254
422
        Py_DECREF(value);
5255
422
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
5256
422
                             ast2obj_stmt);
5257
422
        if (!value) goto failed;
5258
422
        if (PyObject_SetAttr(result, state->body, value) == -1)
5259
0
            goto failed;
5260
422
        Py_DECREF(value);
5261
422
        value = ast2obj_list(state,
5262
422
                             (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
5263
422
                             ast2obj_expr);
5264
422
        if (!value) goto failed;
5265
422
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5266
0
            goto failed;
5267
422
        Py_DECREF(value);
5268
422
        value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
5269
422
        if (!value) goto failed;
5270
422
        if (PyObject_SetAttr(result, state->returns, value) == -1)
5271
0
            goto failed;
5272
422
        Py_DECREF(value);
5273
422
        value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
5274
422
        if (!value) goto failed;
5275
422
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5276
0
            goto failed;
5277
422
        Py_DECREF(value);
5278
422
        value = ast2obj_list(state,
5279
422
                             (asdl_seq*)o->v.AsyncFunctionDef.type_params,
5280
422
                             ast2obj_type_param);
5281
422
        if (!value) goto failed;
5282
422
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5283
0
            goto failed;
5284
422
        Py_DECREF(value);
5285
422
        break;
5286
475
    case ClassDef_kind:
5287
475
        tp = (PyTypeObject *)state->ClassDef_type;
5288
475
        result = PyType_GenericNew(tp, NULL, NULL);
5289
475
        if (!result) goto failed;
5290
475
        value = ast2obj_identifier(state, o->v.ClassDef.name);
5291
475
        if (!value) goto failed;
5292
475
        if (PyObject_SetAttr(result, state->name, value) == -1)
5293
0
            goto failed;
5294
475
        Py_DECREF(value);
5295
475
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
5296
475
                             ast2obj_expr);
5297
475
        if (!value) goto failed;
5298
475
        if (PyObject_SetAttr(result, state->bases, value) == -1)
5299
0
            goto failed;
5300
475
        Py_DECREF(value);
5301
475
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
5302
475
                             ast2obj_keyword);
5303
475
        if (!value) goto failed;
5304
475
        if (PyObject_SetAttr(result, state->keywords, value) == -1)
5305
0
            goto failed;
5306
475
        Py_DECREF(value);
5307
475
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
5308
475
                             ast2obj_stmt);
5309
475
        if (!value) goto failed;
5310
475
        if (PyObject_SetAttr(result, state->body, value) == -1)
5311
0
            goto failed;
5312
475
        Py_DECREF(value);
5313
475
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
5314
475
                             ast2obj_expr);
5315
475
        if (!value) goto failed;
5316
475
        if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
5317
0
            goto failed;
5318
475
        Py_DECREF(value);
5319
475
        value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.type_params,
5320
475
                             ast2obj_type_param);
5321
475
        if (!value) goto failed;
5322
475
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5323
0
            goto failed;
5324
475
        Py_DECREF(value);
5325
475
        break;
5326
599
    case Return_kind:
5327
599
        tp = (PyTypeObject *)state->Return_type;
5328
599
        result = PyType_GenericNew(tp, NULL, NULL);
5329
599
        if (!result) goto failed;
5330
599
        value = ast2obj_expr(state, o->v.Return.value);
5331
599
        if (!value) goto failed;
5332
599
        if (PyObject_SetAttr(result, state->value, value) == -1)
5333
0
            goto failed;
5334
599
        Py_DECREF(value);
5335
599
        break;
5336
56
    case Delete_kind:
5337
56
        tp = (PyTypeObject *)state->Delete_type;
5338
56
        result = PyType_GenericNew(tp, NULL, NULL);
5339
56
        if (!result) goto failed;
5340
56
        value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
5341
56
                             ast2obj_expr);
5342
56
        if (!value) goto failed;
5343
56
        if (PyObject_SetAttr(result, state->targets, value) == -1)
5344
0
            goto failed;
5345
56
        Py_DECREF(value);
5346
56
        break;
5347
317
    case Assign_kind:
5348
317
        tp = (PyTypeObject *)state->Assign_type;
5349
317
        result = PyType_GenericNew(tp, NULL, NULL);
5350
317
        if (!result) goto failed;
5351
317
        value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
5352
317
                             ast2obj_expr);
5353
317
        if (!value) goto failed;
5354
317
        if (PyObject_SetAttr(result, state->targets, value) == -1)
5355
0
            goto failed;
5356
317
        Py_DECREF(value);
5357
317
        value = ast2obj_expr(state, o->v.Assign.value);
5358
317
        if (!value) goto failed;
5359
317
        if (PyObject_SetAttr(result, state->value, value) == -1)
5360
0
            goto failed;
5361
317
        Py_DECREF(value);
5362
317
        value = ast2obj_string(state, o->v.Assign.type_comment);
5363
317
        if (!value) goto failed;
5364
317
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5365
0
            goto failed;
5366
317
        Py_DECREF(value);
5367
317
        break;
5368
226
    case TypeAlias_kind:
5369
226
        tp = (PyTypeObject *)state->TypeAlias_type;
5370
226
        result = PyType_GenericNew(tp, NULL, NULL);
5371
226
        if (!result) goto failed;
5372
226
        value = ast2obj_expr(state, o->v.TypeAlias.name);
5373
226
        if (!value) goto failed;
5374
226
        if (PyObject_SetAttr(result, state->name, value) == -1)
5375
0
            goto failed;
5376
226
        Py_DECREF(value);
5377
226
        value = ast2obj_list(state, (asdl_seq*)o->v.TypeAlias.type_params,
5378
226
                             ast2obj_type_param);
5379
226
        if (!value) goto failed;
5380
226
        if (PyObject_SetAttr(result, state->type_params, value) == -1)
5381
0
            goto failed;
5382
226
        Py_DECREF(value);
5383
226
        value = ast2obj_expr(state, o->v.TypeAlias.value);
5384
226
        if (!value) goto failed;
5385
226
        if (PyObject_SetAttr(result, state->value, value) == -1)
5386
0
            goto failed;
5387
226
        Py_DECREF(value);
5388
226
        break;
5389
624
    case AugAssign_kind:
5390
624
        tp = (PyTypeObject *)state->AugAssign_type;
5391
624
        result = PyType_GenericNew(tp, NULL, NULL);
5392
624
        if (!result) goto failed;
5393
624
        value = ast2obj_expr(state, o->v.AugAssign.target);
5394
624
        if (!value) goto failed;
5395
624
        if (PyObject_SetAttr(result, state->target, value) == -1)
5396
0
            goto failed;
5397
624
        Py_DECREF(value);
5398
624
        value = ast2obj_operator(state, o->v.AugAssign.op);
5399
624
        if (!value) goto failed;
5400
624
        if (PyObject_SetAttr(result, state->op, value) == -1)
5401
0
            goto failed;
5402
624
        Py_DECREF(value);
5403
624
        value = ast2obj_expr(state, o->v.AugAssign.value);
5404
624
        if (!value) goto failed;
5405
624
        if (PyObject_SetAttr(result, state->value, value) == -1)
5406
0
            goto failed;
5407
624
        Py_DECREF(value);
5408
624
        break;
5409
1.12k
    case AnnAssign_kind:
5410
1.12k
        tp = (PyTypeObject *)state->AnnAssign_type;
5411
1.12k
        result = PyType_GenericNew(tp, NULL, NULL);
5412
1.12k
        if (!result) goto failed;
5413
1.12k
        value = ast2obj_expr(state, o->v.AnnAssign.target);
5414
1.12k
        if (!value) goto failed;
5415
1.12k
        if (PyObject_SetAttr(result, state->target, value) == -1)
5416
0
            goto failed;
5417
1.12k
        Py_DECREF(value);
5418
1.12k
        value = ast2obj_expr(state, o->v.AnnAssign.annotation);
5419
1.12k
        if (!value) goto failed;
5420
1.12k
        if (PyObject_SetAttr(result, state->annotation, value) == -1)
5421
0
            goto failed;
5422
1.12k
        Py_DECREF(value);
5423
1.12k
        value = ast2obj_expr(state, o->v.AnnAssign.value);
5424
1.12k
        if (!value) goto failed;
5425
1.12k
        if (PyObject_SetAttr(result, state->value, value) == -1)
5426
0
            goto failed;
5427
1.12k
        Py_DECREF(value);
5428
1.12k
        value = ast2obj_int(state, o->v.AnnAssign.simple);
5429
1.12k
        if (!value) goto failed;
5430
1.12k
        if (PyObject_SetAttr(result, state->simple, value) == -1)
5431
0
            goto failed;
5432
1.12k
        Py_DECREF(value);
5433
1.12k
        break;
5434
198
    case For_kind:
5435
198
        tp = (PyTypeObject *)state->For_type;
5436
198
        result = PyType_GenericNew(tp, NULL, NULL);
5437
198
        if (!result) goto failed;
5438
198
        value = ast2obj_expr(state, o->v.For.target);
5439
198
        if (!value) goto failed;
5440
198
        if (PyObject_SetAttr(result, state->target, value) == -1)
5441
0
            goto failed;
5442
198
        Py_DECREF(value);
5443
198
        value = ast2obj_expr(state, o->v.For.iter);
5444
198
        if (!value) goto failed;
5445
198
        if (PyObject_SetAttr(result, state->iter, value) == -1)
5446
0
            goto failed;
5447
198
        Py_DECREF(value);
5448
198
        value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
5449
198
        if (!value) goto failed;
5450
198
        if (PyObject_SetAttr(result, state->body, value) == -1)
5451
0
            goto failed;
5452
198
        Py_DECREF(value);
5453
198
        value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
5454
198
        if (!value) goto failed;
5455
198
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5456
0
            goto failed;
5457
198
        Py_DECREF(value);
5458
198
        value = ast2obj_string(state, o->v.For.type_comment);
5459
198
        if (!value) goto failed;
5460
198
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5461
0
            goto failed;
5462
198
        Py_DECREF(value);
5463
198
        break;
5464
119
    case AsyncFor_kind:
5465
119
        tp = (PyTypeObject *)state->AsyncFor_type;
5466
119
        result = PyType_GenericNew(tp, NULL, NULL);
5467
119
        if (!result) goto failed;
5468
119
        value = ast2obj_expr(state, o->v.AsyncFor.target);
5469
119
        if (!value) goto failed;
5470
119
        if (PyObject_SetAttr(result, state->target, value) == -1)
5471
0
            goto failed;
5472
119
        Py_DECREF(value);
5473
119
        value = ast2obj_expr(state, o->v.AsyncFor.iter);
5474
119
        if (!value) goto failed;
5475
119
        if (PyObject_SetAttr(result, state->iter, value) == -1)
5476
0
            goto failed;
5477
119
        Py_DECREF(value);
5478
119
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
5479
119
                             ast2obj_stmt);
5480
119
        if (!value) goto failed;
5481
119
        if (PyObject_SetAttr(result, state->body, value) == -1)
5482
0
            goto failed;
5483
119
        Py_DECREF(value);
5484
119
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
5485
119
                             ast2obj_stmt);
5486
119
        if (!value) goto failed;
5487
119
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5488
0
            goto failed;
5489
119
        Py_DECREF(value);
5490
119
        value = ast2obj_string(state, o->v.AsyncFor.type_comment);
5491
119
        if (!value) goto failed;
5492
119
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5493
0
            goto failed;
5494
119
        Py_DECREF(value);
5495
119
        break;
5496
190
    case While_kind:
5497
190
        tp = (PyTypeObject *)state->While_type;
5498
190
        result = PyType_GenericNew(tp, NULL, NULL);
5499
190
        if (!result) goto failed;
5500
190
        value = ast2obj_expr(state, o->v.While.test);
5501
190
        if (!value) goto failed;
5502
190
        if (PyObject_SetAttr(result, state->test, value) == -1)
5503
0
            goto failed;
5504
190
        Py_DECREF(value);
5505
190
        value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
5506
190
        if (!value) goto failed;
5507
190
        if (PyObject_SetAttr(result, state->body, value) == -1)
5508
0
            goto failed;
5509
190
        Py_DECREF(value);
5510
190
        value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
5511
190
        if (!value) goto failed;
5512
190
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5513
0
            goto failed;
5514
190
        Py_DECREF(value);
5515
190
        break;
5516
197
    case If_kind:
5517
197
        tp = (PyTypeObject *)state->If_type;
5518
197
        result = PyType_GenericNew(tp, NULL, NULL);
5519
197
        if (!result) goto failed;
5520
197
        value = ast2obj_expr(state, o->v.If.test);
5521
197
        if (!value) goto failed;
5522
197
        if (PyObject_SetAttr(result, state->test, value) == -1)
5523
0
            goto failed;
5524
197
        Py_DECREF(value);
5525
197
        value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
5526
197
        if (!value) goto failed;
5527
197
        if (PyObject_SetAttr(result, state->body, value) == -1)
5528
0
            goto failed;
5529
197
        Py_DECREF(value);
5530
197
        value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
5531
197
        if (!value) goto failed;
5532
197
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5533
0
            goto failed;
5534
197
        Py_DECREF(value);
5535
197
        break;
5536
200
    case With_kind:
5537
200
        tp = (PyTypeObject *)state->With_type;
5538
200
        result = PyType_GenericNew(tp, NULL, NULL);
5539
200
        if (!result) goto failed;
5540
200
        value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
5541
200
                             ast2obj_withitem);
5542
200
        if (!value) goto failed;
5543
200
        if (PyObject_SetAttr(result, state->items, value) == -1)
5544
0
            goto failed;
5545
200
        Py_DECREF(value);
5546
200
        value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
5547
200
        if (!value) goto failed;
5548
200
        if (PyObject_SetAttr(result, state->body, value) == -1)
5549
0
            goto failed;
5550
200
        Py_DECREF(value);
5551
200
        value = ast2obj_string(state, o->v.With.type_comment);
5552
200
        if (!value) goto failed;
5553
200
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5554
0
            goto failed;
5555
200
        Py_DECREF(value);
5556
200
        break;
5557
184
    case AsyncWith_kind:
5558
184
        tp = (PyTypeObject *)state->AsyncWith_type;
5559
184
        result = PyType_GenericNew(tp, NULL, NULL);
5560
184
        if (!result) goto failed;
5561
184
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
5562
184
                             ast2obj_withitem);
5563
184
        if (!value) goto failed;
5564
184
        if (PyObject_SetAttr(result, state->items, value) == -1)
5565
0
            goto failed;
5566
184
        Py_DECREF(value);
5567
184
        value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
5568
184
                             ast2obj_stmt);
5569
184
        if (!value) goto failed;
5570
184
        if (PyObject_SetAttr(result, state->body, value) == -1)
5571
0
            goto failed;
5572
184
        Py_DECREF(value);
5573
184
        value = ast2obj_string(state, o->v.AsyncWith.type_comment);
5574
184
        if (!value) goto failed;
5575
184
        if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5576
0
            goto failed;
5577
184
        Py_DECREF(value);
5578
184
        break;
5579
208
    case Match_kind:
5580
208
        tp = (PyTypeObject *)state->Match_type;
5581
208
        result = PyType_GenericNew(tp, NULL, NULL);
5582
208
        if (!result) goto failed;
5583
208
        value = ast2obj_expr(state, o->v.Match.subject);
5584
208
        if (!value) goto failed;
5585
208
        if (PyObject_SetAttr(result, state->subject, value) == -1)
5586
0
            goto failed;
5587
208
        Py_DECREF(value);
5588
208
        value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
5589
208
                             ast2obj_match_case);
5590
208
        if (!value) goto failed;
5591
208
        if (PyObject_SetAttr(result, state->cases, value) == -1)
5592
0
            goto failed;
5593
208
        Py_DECREF(value);
5594
208
        break;
5595
247
    case Raise_kind:
5596
247
        tp = (PyTypeObject *)state->Raise_type;
5597
247
        result = PyType_GenericNew(tp, NULL, NULL);
5598
247
        if (!result) goto failed;
5599
247
        value = ast2obj_expr(state, o->v.Raise.exc);
5600
247
        if (!value) goto failed;
5601
247
        if (PyObject_SetAttr(result, state->exc, value) == -1)
5602
0
            goto failed;
5603
247
        Py_DECREF(value);
5604
247
        value = ast2obj_expr(state, o->v.Raise.cause);
5605
247
        if (!value) goto failed;
5606
247
        if (PyObject_SetAttr(result, state->cause, value) == -1)
5607
0
            goto failed;
5608
247
        Py_DECREF(value);
5609
247
        break;
5610
517
    case Try_kind:
5611
517
        tp = (PyTypeObject *)state->Try_type;
5612
517
        result = PyType_GenericNew(tp, NULL, NULL);
5613
517
        if (!result) goto failed;
5614
517
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
5615
517
        if (!value) goto failed;
5616
517
        if (PyObject_SetAttr(result, state->body, value) == -1)
5617
0
            goto failed;
5618
517
        Py_DECREF(value);
5619
517
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
5620
517
                             ast2obj_excepthandler);
5621
517
        if (!value) goto failed;
5622
517
        if (PyObject_SetAttr(result, state->handlers, value) == -1)
5623
0
            goto failed;
5624
517
        Py_DECREF(value);
5625
517
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
5626
517
        if (!value) goto failed;
5627
517
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5628
0
            goto failed;
5629
517
        Py_DECREF(value);
5630
517
        value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
5631
517
                             ast2obj_stmt);
5632
517
        if (!value) goto failed;
5633
517
        if (PyObject_SetAttr(result, state->finalbody, value) == -1)
5634
0
            goto failed;
5635
517
        Py_DECREF(value);
5636
517
        break;
5637
212
    case TryStar_kind:
5638
212
        tp = (PyTypeObject *)state->TryStar_type;
5639
212
        result = PyType_GenericNew(tp, NULL, NULL);
5640
212
        if (!result) goto failed;
5641
212
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.body, ast2obj_stmt);
5642
212
        if (!value) goto failed;
5643
212
        if (PyObject_SetAttr(result, state->body, value) == -1)
5644
0
            goto failed;
5645
212
        Py_DECREF(value);
5646
212
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.handlers,
5647
212
                             ast2obj_excepthandler);
5648
212
        if (!value) goto failed;
5649
212
        if (PyObject_SetAttr(result, state->handlers, value) == -1)
5650
0
            goto failed;
5651
212
        Py_DECREF(value);
5652
212
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.orelse,
5653
212
                             ast2obj_stmt);
5654
212
        if (!value) goto failed;
5655
212
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5656
0
            goto failed;
5657
212
        Py_DECREF(value);
5658
212
        value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.finalbody,
5659
212
                             ast2obj_stmt);
5660
212
        if (!value) goto failed;
5661
212
        if (PyObject_SetAttr(result, state->finalbody, value) == -1)
5662
0
            goto failed;
5663
212
        Py_DECREF(value);
5664
212
        break;
5665
692
    case Assert_kind:
5666
692
        tp = (PyTypeObject *)state->Assert_type;
5667
692
        result = PyType_GenericNew(tp, NULL, NULL);
5668
692
        if (!result) goto failed;
5669
692
        value = ast2obj_expr(state, o->v.Assert.test);
5670
692
        if (!value) goto failed;
5671
692
        if (PyObject_SetAttr(result, state->test, value) == -1)
5672
0
            goto failed;
5673
692
        Py_DECREF(value);
5674
692
        value = ast2obj_expr(state, o->v.Assert.msg);
5675
692
        if (!value) goto failed;
5676
692
        if (PyObject_SetAttr(result, state->msg, value) == -1)
5677
0
            goto failed;
5678
692
        Py_DECREF(value);
5679
692
        break;
5680
304
    case Import_kind:
5681
304
        tp = (PyTypeObject *)state->Import_type;
5682
304
        result = PyType_GenericNew(tp, NULL, NULL);
5683
304
        if (!result) goto failed;
5684
304
        value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
5685
304
                             ast2obj_alias);
5686
304
        if (!value) goto failed;
5687
304
        if (PyObject_SetAttr(result, state->names, value) == -1)
5688
0
            goto failed;
5689
304
        Py_DECREF(value);
5690
304
        value = ast2obj_int(state, o->v.Import.is_lazy);
5691
304
        if (!value) goto failed;
5692
304
        if (PyObject_SetAttr(result, state->is_lazy, value) == -1)
5693
0
            goto failed;
5694
304
        Py_DECREF(value);
5695
304
        break;
5696
320
    case ImportFrom_kind:
5697
320
        tp = (PyTypeObject *)state->ImportFrom_type;
5698
320
        result = PyType_GenericNew(tp, NULL, NULL);
5699
320
        if (!result) goto failed;
5700
320
        value = ast2obj_identifier(state, o->v.ImportFrom.module);
5701
320
        if (!value) goto failed;
5702
320
        if (PyObject_SetAttr(result, state->module, value) == -1)
5703
0
            goto failed;
5704
320
        Py_DECREF(value);
5705
320
        value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
5706
320
                             ast2obj_alias);
5707
320
        if (!value) goto failed;
5708
320
        if (PyObject_SetAttr(result, state->names, value) == -1)
5709
0
            goto failed;
5710
320
        Py_DECREF(value);
5711
320
        value = ast2obj_int(state, o->v.ImportFrom.level);
5712
320
        if (!value) goto failed;
5713
320
        if (PyObject_SetAttr(result, state->level, value) == -1)
5714
0
            goto failed;
5715
320
        Py_DECREF(value);
5716
320
        value = ast2obj_int(state, o->v.ImportFrom.is_lazy);
5717
320
        if (!value) goto failed;
5718
320
        if (PyObject_SetAttr(result, state->is_lazy, value) == -1)
5719
0
            goto failed;
5720
320
        Py_DECREF(value);
5721
320
        break;
5722
30
    case Global_kind:
5723
30
        tp = (PyTypeObject *)state->Global_type;
5724
30
        result = PyType_GenericNew(tp, NULL, NULL);
5725
30
        if (!result) goto failed;
5726
30
        value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
5727
30
                             ast2obj_identifier);
5728
30
        if (!value) goto failed;
5729
30
        if (PyObject_SetAttr(result, state->names, value) == -1)
5730
0
            goto failed;
5731
30
        Py_DECREF(value);
5732
30
        break;
5733
73
    case Nonlocal_kind:
5734
73
        tp = (PyTypeObject *)state->Nonlocal_type;
5735
73
        result = PyType_GenericNew(tp, NULL, NULL);
5736
73
        if (!result) goto failed;
5737
73
        value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
5738
73
                             ast2obj_identifier);
5739
73
        if (!value) goto failed;
5740
73
        if (PyObject_SetAttr(result, state->names, value) == -1)
5741
0
            goto failed;
5742
73
        Py_DECREF(value);
5743
73
        break;
5744
21.8k
    case Expr_kind:
5745
21.8k
        tp = (PyTypeObject *)state->Expr_type;
5746
21.8k
        result = PyType_GenericNew(tp, NULL, NULL);
5747
21.8k
        if (!result) goto failed;
5748
21.8k
        value = ast2obj_expr(state, o->v.Expr.value);
5749
21.8k
        if (!value) goto failed;
5750
21.8k
        if (PyObject_SetAttr(result, state->value, value) == -1)
5751
0
            goto failed;
5752
21.8k
        Py_DECREF(value);
5753
21.8k
        break;
5754
234
    case Pass_kind:
5755
234
        tp = (PyTypeObject *)state->Pass_type;
5756
234
        result = PyType_GenericNew(tp, NULL, NULL);
5757
234
        if (!result) goto failed;
5758
234
        break;
5759
234
    case Break_kind:
5760
69
        tp = (PyTypeObject *)state->Break_type;
5761
69
        result = PyType_GenericNew(tp, NULL, NULL);
5762
69
        if (!result) goto failed;
5763
69
        break;
5764
108
    case Continue_kind:
5765
108
        tp = (PyTypeObject *)state->Continue_type;
5766
108
        result = PyType_GenericNew(tp, NULL, NULL);
5767
108
        if (!result) goto failed;
5768
108
        break;
5769
30.7k
    }
5770
30.7k
    value = ast2obj_int(state, o->lineno);
5771
30.7k
    if (!value) goto failed;
5772
30.7k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
5773
0
        goto failed;
5774
30.7k
    Py_DECREF(value);
5775
30.7k
    value = ast2obj_int(state, o->col_offset);
5776
30.7k
    if (!value) goto failed;
5777
30.7k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5778
0
        goto failed;
5779
30.7k
    Py_DECREF(value);
5780
30.7k
    value = ast2obj_int(state, o->end_lineno);
5781
30.7k
    if (!value) goto failed;
5782
30.7k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5783
0
        goto failed;
5784
30.7k
    Py_DECREF(value);
5785
30.7k
    value = ast2obj_int(state, o->end_col_offset);
5786
30.7k
    if (!value) goto failed;
5787
30.7k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5788
0
        goto failed;
5789
30.7k
    Py_DECREF(value);
5790
30.7k
    Py_LeaveRecursiveCall();
5791
30.7k
    return result;
5792
0
failed:
5793
0
    Py_LeaveRecursiveCall();
5794
0
    Py_XDECREF(value);
5795
0
    Py_XDECREF(result);
5796
0
    return NULL;
5797
30.7k
}
5798
5799
PyObject*
5800
ast2obj_expr(struct ast_state *state, void* _o)
5801
292k
{
5802
292k
    expr_ty o = (expr_ty)_o;
5803
292k
    PyObject *result = NULL, *value = NULL;
5804
292k
    PyTypeObject *tp;
5805
292k
    if (!o) {
5806
17.6k
        Py_RETURN_NONE;
5807
17.6k
    }
5808
274k
    if (Py_EnterRecursiveCall("during  ast construction")) {
5809
0
        return NULL;
5810
0
    }
5811
274k
    switch (o->kind) {
5812
775
    case BoolOp_kind:
5813
775
        tp = (PyTypeObject *)state->BoolOp_type;
5814
775
        result = PyType_GenericNew(tp, NULL, NULL);
5815
775
        if (!result) goto failed;
5816
775
        value = ast2obj_boolop(state, o->v.BoolOp.op);
5817
775
        if (!value) goto failed;
5818
775
        if (PyObject_SetAttr(result, state->op, value) == -1)
5819
0
            goto failed;
5820
775
        Py_DECREF(value);
5821
775
        value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
5822
775
                             ast2obj_expr);
5823
775
        if (!value) goto failed;
5824
775
        if (PyObject_SetAttr(result, state->values, value) == -1)
5825
0
            goto failed;
5826
775
        Py_DECREF(value);
5827
775
        break;
5828
59
    case NamedExpr_kind:
5829
59
        tp = (PyTypeObject *)state->NamedExpr_type;
5830
59
        result = PyType_GenericNew(tp, NULL, NULL);
5831
59
        if (!result) goto failed;
5832
59
        value = ast2obj_expr(state, o->v.NamedExpr.target);
5833
59
        if (!value) goto failed;
5834
59
        if (PyObject_SetAttr(result, state->target, value) == -1)
5835
0
            goto failed;
5836
59
        Py_DECREF(value);
5837
59
        value = ast2obj_expr(state, o->v.NamedExpr.value);
5838
59
        if (!value) goto failed;
5839
59
        if (PyObject_SetAttr(result, state->value, value) == -1)
5840
0
            goto failed;
5841
59
        Py_DECREF(value);
5842
59
        break;
5843
52.6k
    case BinOp_kind:
5844
52.6k
        tp = (PyTypeObject *)state->BinOp_type;
5845
52.6k
        result = PyType_GenericNew(tp, NULL, NULL);
5846
52.6k
        if (!result) goto failed;
5847
52.6k
        value = ast2obj_expr(state, o->v.BinOp.left);
5848
52.6k
        if (!value) goto failed;
5849
52.6k
        if (PyObject_SetAttr(result, state->left, value) == -1)
5850
0
            goto failed;
5851
52.6k
        Py_DECREF(value);
5852
52.6k
        value = ast2obj_operator(state, o->v.BinOp.op);
5853
52.6k
        if (!value) goto failed;
5854
52.6k
        if (PyObject_SetAttr(result, state->op, value) == -1)
5855
0
            goto failed;
5856
52.6k
        Py_DECREF(value);
5857
52.6k
        value = ast2obj_expr(state, o->v.BinOp.right);
5858
52.6k
        if (!value) goto failed;
5859
52.6k
        if (PyObject_SetAttr(result, state->right, value) == -1)
5860
0
            goto failed;
5861
52.6k
        Py_DECREF(value);
5862
52.6k
        break;
5863
97.9k
    case UnaryOp_kind:
5864
97.9k
        tp = (PyTypeObject *)state->UnaryOp_type;
5865
97.9k
        result = PyType_GenericNew(tp, NULL, NULL);
5866
97.9k
        if (!result) goto failed;
5867
97.9k
        value = ast2obj_unaryop(state, o->v.UnaryOp.op);
5868
97.9k
        if (!value) goto failed;
5869
97.9k
        if (PyObject_SetAttr(result, state->op, value) == -1)
5870
0
            goto failed;
5871
97.9k
        Py_DECREF(value);
5872
97.9k
        value = ast2obj_expr(state, o->v.UnaryOp.operand);
5873
97.9k
        if (!value) goto failed;
5874
97.9k
        if (PyObject_SetAttr(result, state->operand, value) == -1)
5875
0
            goto failed;
5876
97.9k
        Py_DECREF(value);
5877
97.9k
        break;
5878
421
    case Lambda_kind:
5879
421
        tp = (PyTypeObject *)state->Lambda_type;
5880
421
        result = PyType_GenericNew(tp, NULL, NULL);
5881
421
        if (!result) goto failed;
5882
421
        value = ast2obj_arguments(state, o->v.Lambda.args);
5883
421
        if (!value) goto failed;
5884
421
        if (PyObject_SetAttr(result, state->args, value) == -1)
5885
0
            goto failed;
5886
421
        Py_DECREF(value);
5887
421
        value = ast2obj_expr(state, o->v.Lambda.body);
5888
421
        if (!value) goto failed;
5889
421
        if (PyObject_SetAttr(result, state->body, value) == -1)
5890
0
            goto failed;
5891
421
        Py_DECREF(value);
5892
421
        break;
5893
487
    case IfExp_kind:
5894
487
        tp = (PyTypeObject *)state->IfExp_type;
5895
487
        result = PyType_GenericNew(tp, NULL, NULL);
5896
487
        if (!result) goto failed;
5897
487
        value = ast2obj_expr(state, o->v.IfExp.test);
5898
487
        if (!value) goto failed;
5899
487
        if (PyObject_SetAttr(result, state->test, value) == -1)
5900
0
            goto failed;
5901
487
        Py_DECREF(value);
5902
487
        value = ast2obj_expr(state, o->v.IfExp.body);
5903
487
        if (!value) goto failed;
5904
487
        if (PyObject_SetAttr(result, state->body, value) == -1)
5905
0
            goto failed;
5906
487
        Py_DECREF(value);
5907
487
        value = ast2obj_expr(state, o->v.IfExp.orelse);
5908
487
        if (!value) goto failed;
5909
487
        if (PyObject_SetAttr(result, state->orelse, value) == -1)
5910
0
            goto failed;
5911
487
        Py_DECREF(value);
5912
487
        break;
5913
219
    case Dict_kind:
5914
219
        tp = (PyTypeObject *)state->Dict_type;
5915
219
        result = PyType_GenericNew(tp, NULL, NULL);
5916
219
        if (!result) goto failed;
5917
219
        value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
5918
219
        if (!value) goto failed;
5919
219
        if (PyObject_SetAttr(result, state->keys, value) == -1)
5920
0
            goto failed;
5921
219
        Py_DECREF(value);
5922
219
        value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
5923
219
        if (!value) goto failed;
5924
219
        if (PyObject_SetAttr(result, state->values, value) == -1)
5925
0
            goto failed;
5926
219
        Py_DECREF(value);
5927
219
        break;
5928
231
    case Set_kind:
5929
231
        tp = (PyTypeObject *)state->Set_type;
5930
231
        result = PyType_GenericNew(tp, NULL, NULL);
5931
231
        if (!result) goto failed;
5932
231
        value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
5933
231
        if (!value) goto failed;
5934
231
        if (PyObject_SetAttr(result, state->elts, value) == -1)
5935
0
            goto failed;
5936
231
        Py_DECREF(value);
5937
231
        break;
5938
203
    case ListComp_kind:
5939
203
        tp = (PyTypeObject *)state->ListComp_type;
5940
203
        result = PyType_GenericNew(tp, NULL, NULL);
5941
203
        if (!result) goto failed;
5942
203
        value = ast2obj_expr(state, o->v.ListComp.elt);
5943
203
        if (!value) goto failed;
5944
203
        if (PyObject_SetAttr(result, state->elt, value) == -1)
5945
0
            goto failed;
5946
203
        Py_DECREF(value);
5947
203
        value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
5948
203
                             ast2obj_comprehension);
5949
203
        if (!value) goto failed;
5950
203
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5951
0
            goto failed;
5952
203
        Py_DECREF(value);
5953
203
        break;
5954
85
    case SetComp_kind:
5955
85
        tp = (PyTypeObject *)state->SetComp_type;
5956
85
        result = PyType_GenericNew(tp, NULL, NULL);
5957
85
        if (!result) goto failed;
5958
85
        value = ast2obj_expr(state, o->v.SetComp.elt);
5959
85
        if (!value) goto failed;
5960
85
        if (PyObject_SetAttr(result, state->elt, value) == -1)
5961
0
            goto failed;
5962
85
        Py_DECREF(value);
5963
85
        value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
5964
85
                             ast2obj_comprehension);
5965
85
        if (!value) goto failed;
5966
85
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5967
0
            goto failed;
5968
85
        Py_DECREF(value);
5969
85
        break;
5970
173
    case DictComp_kind:
5971
173
        tp = (PyTypeObject *)state->DictComp_type;
5972
173
        result = PyType_GenericNew(tp, NULL, NULL);
5973
173
        if (!result) goto failed;
5974
173
        value = ast2obj_expr(state, o->v.DictComp.key);
5975
173
        if (!value) goto failed;
5976
173
        if (PyObject_SetAttr(result, state->key, value) == -1)
5977
0
            goto failed;
5978
173
        Py_DECREF(value);
5979
173
        value = ast2obj_expr(state, o->v.DictComp.value);
5980
173
        if (!value) goto failed;
5981
173
        if (PyObject_SetAttr(result, state->value, value) == -1)
5982
0
            goto failed;
5983
173
        Py_DECREF(value);
5984
173
        value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
5985
173
                             ast2obj_comprehension);
5986
173
        if (!value) goto failed;
5987
173
        if (PyObject_SetAttr(result, state->generators, value) == -1)
5988
0
            goto failed;
5989
173
        Py_DECREF(value);
5990
173
        break;
5991
113
    case GeneratorExp_kind:
5992
113
        tp = (PyTypeObject *)state->GeneratorExp_type;
5993
113
        result = PyType_GenericNew(tp, NULL, NULL);
5994
113
        if (!result) goto failed;
5995
113
        value = ast2obj_expr(state, o->v.GeneratorExp.elt);
5996
113
        if (!value) goto failed;
5997
113
        if (PyObject_SetAttr(result, state->elt, value) == -1)
5998
0
            goto failed;
5999
113
        Py_DECREF(value);
6000
113
        value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
6001
113
                             ast2obj_comprehension);
6002
113
        if (!value) goto failed;
6003
113
        if (PyObject_SetAttr(result, state->generators, value) == -1)
6004
0
            goto failed;
6005
113
        Py_DECREF(value);
6006
113
        break;
6007
170
    case Await_kind:
6008
170
        tp = (PyTypeObject *)state->Await_type;
6009
170
        result = PyType_GenericNew(tp, NULL, NULL);
6010
170
        if (!result) goto failed;
6011
170
        value = ast2obj_expr(state, o->v.Await.value);
6012
170
        if (!value) goto failed;
6013
170
        if (PyObject_SetAttr(result, state->value, value) == -1)
6014
0
            goto failed;
6015
170
        Py_DECREF(value);
6016
170
        break;
6017
388
    case Yield_kind:
6018
388
        tp = (PyTypeObject *)state->Yield_type;
6019
388
        result = PyType_GenericNew(tp, NULL, NULL);
6020
388
        if (!result) goto failed;
6021
388
        value = ast2obj_expr(state, o->v.Yield.value);
6022
388
        if (!value) goto failed;
6023
388
        if (PyObject_SetAttr(result, state->value, value) == -1)
6024
0
            goto failed;
6025
388
        Py_DECREF(value);
6026
388
        break;
6027
15
    case YieldFrom_kind:
6028
15
        tp = (PyTypeObject *)state->YieldFrom_type;
6029
15
        result = PyType_GenericNew(tp, NULL, NULL);
6030
15
        if (!result) goto failed;
6031
15
        value = ast2obj_expr(state, o->v.YieldFrom.value);
6032
15
        if (!value) goto failed;
6033
15
        if (PyObject_SetAttr(result, state->value, value) == -1)
6034
0
            goto failed;
6035
15
        Py_DECREF(value);
6036
15
        break;
6037
1.90k
    case Compare_kind:
6038
1.90k
        tp = (PyTypeObject *)state->Compare_type;
6039
1.90k
        result = PyType_GenericNew(tp, NULL, NULL);
6040
1.90k
        if (!result) goto failed;
6041
1.90k
        value = ast2obj_expr(state, o->v.Compare.left);
6042
1.90k
        if (!value) goto failed;
6043
1.90k
        if (PyObject_SetAttr(result, state->left, value) == -1)
6044
0
            goto failed;
6045
1.90k
        Py_DECREF(value);
6046
1.90k
        {
6047
1.90k
            Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
6048
1.90k
            value = PyList_New(n);
6049
1.90k
            if (!value) goto failed;
6050
7.53k
            for(i = 0; i < n; i++)
6051
5.63k
                PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
6052
1.90k
        }
6053
1.90k
        if (!value) goto failed;
6054
1.90k
        if (PyObject_SetAttr(result, state->ops, value) == -1)
6055
0
            goto failed;
6056
1.90k
        Py_DECREF(value);
6057
1.90k
        value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
6058
1.90k
                             ast2obj_expr);
6059
1.90k
        if (!value) goto failed;
6060
1.90k
        if (PyObject_SetAttr(result, state->comparators, value) == -1)
6061
0
            goto failed;
6062
1.90k
        Py_DECREF(value);
6063
1.90k
        break;
6064
1.09k
    case Call_kind:
6065
1.09k
        tp = (PyTypeObject *)state->Call_type;
6066
1.09k
        result = PyType_GenericNew(tp, NULL, NULL);
6067
1.09k
        if (!result) goto failed;
6068
1.09k
        value = ast2obj_expr(state, o->v.Call.func);
6069
1.09k
        if (!value) goto failed;
6070
1.09k
        if (PyObject_SetAttr(result, state->func, value) == -1)
6071
0
            goto failed;
6072
1.09k
        Py_DECREF(value);
6073
1.09k
        value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
6074
1.09k
        if (!value) goto failed;
6075
1.09k
        if (PyObject_SetAttr(result, state->args, value) == -1)
6076
0
            goto failed;
6077
1.09k
        Py_DECREF(value);
6078
1.09k
        value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
6079
1.09k
                             ast2obj_keyword);
6080
1.09k
        if (!value) goto failed;
6081
1.09k
        if (PyObject_SetAttr(result, state->keywords, value) == -1)
6082
0
            goto failed;
6083
1.09k
        Py_DECREF(value);
6084
1.09k
        break;
6085
525
    case FormattedValue_kind:
6086
525
        tp = (PyTypeObject *)state->FormattedValue_type;
6087
525
        result = PyType_GenericNew(tp, NULL, NULL);
6088
525
        if (!result) goto failed;
6089
525
        value = ast2obj_expr(state, o->v.FormattedValue.value);
6090
525
        if (!value) goto failed;
6091
525
        if (PyObject_SetAttr(result, state->value, value) == -1)
6092
0
            goto failed;
6093
525
        Py_DECREF(value);
6094
525
        value = ast2obj_int(state, o->v.FormattedValue.conversion);
6095
525
        if (!value) goto failed;
6096
525
        if (PyObject_SetAttr(result, state->conversion, value) == -1)
6097
0
            goto failed;
6098
525
        Py_DECREF(value);
6099
525
        value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
6100
525
        if (!value) goto failed;
6101
525
        if (PyObject_SetAttr(result, state->format_spec, value) == -1)
6102
0
            goto failed;
6103
525
        Py_DECREF(value);
6104
525
        break;
6105
681
    case Interpolation_kind:
6106
681
        tp = (PyTypeObject *)state->Interpolation_type;
6107
681
        result = PyType_GenericNew(tp, NULL, NULL);
6108
681
        if (!result) goto failed;
6109
681
        value = ast2obj_expr(state, o->v.Interpolation.value);
6110
681
        if (!value) goto failed;
6111
681
        if (PyObject_SetAttr(result, state->value, value) == -1)
6112
0
            goto failed;
6113
681
        Py_DECREF(value);
6114
681
        value = ast2obj_constant(state, o->v.Interpolation.str);
6115
681
        if (!value) goto failed;
6116
681
        if (PyObject_SetAttr(result, state->str, value) == -1)
6117
0
            goto failed;
6118
681
        Py_DECREF(value);
6119
681
        value = ast2obj_int(state, o->v.Interpolation.conversion);
6120
681
        if (!value) goto failed;
6121
681
        if (PyObject_SetAttr(result, state->conversion, value) == -1)
6122
0
            goto failed;
6123
681
        Py_DECREF(value);
6124
681
        value = ast2obj_expr(state, o->v.Interpolation.format_spec);
6125
681
        if (!value) goto failed;
6126
681
        if (PyObject_SetAttr(result, state->format_spec, value) == -1)
6127
0
            goto failed;
6128
681
        Py_DECREF(value);
6129
681
        break;
6130
1.00k
    case JoinedStr_kind:
6131
1.00k
        tp = (PyTypeObject *)state->JoinedStr_type;
6132
1.00k
        result = PyType_GenericNew(tp, NULL, NULL);
6133
1.00k
        if (!result) goto failed;
6134
1.00k
        value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
6135
1.00k
                             ast2obj_expr);
6136
1.00k
        if (!value) goto failed;
6137
1.00k
        if (PyObject_SetAttr(result, state->values, value) == -1)
6138
0
            goto failed;
6139
1.00k
        Py_DECREF(value);
6140
1.00k
        break;
6141
169
    case TemplateStr_kind:
6142
169
        tp = (PyTypeObject *)state->TemplateStr_type;
6143
169
        result = PyType_GenericNew(tp, NULL, NULL);
6144
169
        if (!result) goto failed;
6145
169
        value = ast2obj_list(state, (asdl_seq*)o->v.TemplateStr.values,
6146
169
                             ast2obj_expr);
6147
169
        if (!value) goto failed;
6148
169
        if (PyObject_SetAttr(result, state->values, value) == -1)
6149
0
            goto failed;
6150
169
        Py_DECREF(value);
6151
169
        break;
6152
63.7k
    case Constant_kind:
6153
63.7k
        tp = (PyTypeObject *)state->Constant_type;
6154
63.7k
        result = PyType_GenericNew(tp, NULL, NULL);
6155
63.7k
        if (!result) goto failed;
6156
63.7k
        value = ast2obj_constant(state, o->v.Constant.value);
6157
63.7k
        if (!value) goto failed;
6158
63.7k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6159
0
            goto failed;
6160
63.7k
        Py_DECREF(value);
6161
63.7k
        value = ast2obj_string(state, o->v.Constant.kind);
6162
63.7k
        if (!value) goto failed;
6163
63.7k
        if (PyObject_SetAttr(result, state->kind, value) == -1)
6164
0
            goto failed;
6165
63.7k
        Py_DECREF(value);
6166
63.7k
        break;
6167
1.67k
    case Attribute_kind:
6168
1.67k
        tp = (PyTypeObject *)state->Attribute_type;
6169
1.67k
        result = PyType_GenericNew(tp, NULL, NULL);
6170
1.67k
        if (!result) goto failed;
6171
1.67k
        value = ast2obj_expr(state, o->v.Attribute.value);
6172
1.67k
        if (!value) goto failed;
6173
1.67k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6174
0
            goto failed;
6175
1.67k
        Py_DECREF(value);
6176
1.67k
        value = ast2obj_identifier(state, o->v.Attribute.attr);
6177
1.67k
        if (!value) goto failed;
6178
1.67k
        if (PyObject_SetAttr(result, state->attr, value) == -1)
6179
0
            goto failed;
6180
1.67k
        Py_DECREF(value);
6181
1.67k
        value = ast2obj_expr_context(state, o->v.Attribute.ctx);
6182
1.67k
        if (!value) goto failed;
6183
1.67k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6184
0
            goto failed;
6185
1.67k
        Py_DECREF(value);
6186
1.67k
        break;
6187
466
    case Subscript_kind:
6188
466
        tp = (PyTypeObject *)state->Subscript_type;
6189
466
        result = PyType_GenericNew(tp, NULL, NULL);
6190
466
        if (!result) goto failed;
6191
466
        value = ast2obj_expr(state, o->v.Subscript.value);
6192
466
        if (!value) goto failed;
6193
466
        if (PyObject_SetAttr(result, state->value, value) == -1)
6194
0
            goto failed;
6195
466
        Py_DECREF(value);
6196
466
        value = ast2obj_expr(state, o->v.Subscript.slice);
6197
466
        if (!value) goto failed;
6198
466
        if (PyObject_SetAttr(result, state->slice, value) == -1)
6199
0
            goto failed;
6200
466
        Py_DECREF(value);
6201
466
        value = ast2obj_expr_context(state, o->v.Subscript.ctx);
6202
466
        if (!value) goto failed;
6203
466
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6204
0
            goto failed;
6205
466
        Py_DECREF(value);
6206
466
        break;
6207
809
    case Starred_kind:
6208
809
        tp = (PyTypeObject *)state->Starred_type;
6209
809
        result = PyType_GenericNew(tp, NULL, NULL);
6210
809
        if (!result) goto failed;
6211
809
        value = ast2obj_expr(state, o->v.Starred.value);
6212
809
        if (!value) goto failed;
6213
809
        if (PyObject_SetAttr(result, state->value, value) == -1)
6214
0
            goto failed;
6215
809
        Py_DECREF(value);
6216
809
        value = ast2obj_expr_context(state, o->v.Starred.ctx);
6217
809
        if (!value) goto failed;
6218
809
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6219
0
            goto failed;
6220
809
        Py_DECREF(value);
6221
809
        break;
6222
44.2k
    case Name_kind:
6223
44.2k
        tp = (PyTypeObject *)state->Name_type;
6224
44.2k
        result = PyType_GenericNew(tp, NULL, NULL);
6225
44.2k
        if (!result) goto failed;
6226
44.2k
        value = ast2obj_identifier(state, o->v.Name.id);
6227
44.2k
        if (!value) goto failed;
6228
44.2k
        if (PyObject_SetAttr(result, state->id, value) == -1)
6229
0
            goto failed;
6230
44.2k
        Py_DECREF(value);
6231
44.2k
        value = ast2obj_expr_context(state, o->v.Name.ctx);
6232
44.2k
        if (!value) goto failed;
6233
44.2k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6234
0
            goto failed;
6235
44.2k
        Py_DECREF(value);
6236
44.2k
        break;
6237
489
    case List_kind:
6238
489
        tp = (PyTypeObject *)state->List_type;
6239
489
        result = PyType_GenericNew(tp, NULL, NULL);
6240
489
        if (!result) goto failed;
6241
489
        value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
6242
489
        if (!value) goto failed;
6243
489
        if (PyObject_SetAttr(result, state->elts, value) == -1)
6244
0
            goto failed;
6245
489
        Py_DECREF(value);
6246
489
        value = ast2obj_expr_context(state, o->v.List.ctx);
6247
489
        if (!value) goto failed;
6248
489
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6249
0
            goto failed;
6250
489
        Py_DECREF(value);
6251
489
        break;
6252
3.15k
    case Tuple_kind:
6253
3.15k
        tp = (PyTypeObject *)state->Tuple_type;
6254
3.15k
        result = PyType_GenericNew(tp, NULL, NULL);
6255
3.15k
        if (!result) goto failed;
6256
3.15k
        value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
6257
3.15k
        if (!value) goto failed;
6258
3.15k
        if (PyObject_SetAttr(result, state->elts, value) == -1)
6259
0
            goto failed;
6260
3.15k
        Py_DECREF(value);
6261
3.15k
        value = ast2obj_expr_context(state, o->v.Tuple.ctx);
6262
3.15k
        if (!value) goto failed;
6263
3.15k
        if (PyObject_SetAttr(result, state->ctx, value) == -1)
6264
0
            goto failed;
6265
3.15k
        Py_DECREF(value);
6266
3.15k
        break;
6267
760
    case Slice_kind:
6268
760
        tp = (PyTypeObject *)state->Slice_type;
6269
760
        result = PyType_GenericNew(tp, NULL, NULL);
6270
760
        if (!result) goto failed;
6271
760
        value = ast2obj_expr(state, o->v.Slice.lower);
6272
760
        if (!value) goto failed;
6273
760
        if (PyObject_SetAttr(result, state->lower, value) == -1)
6274
0
            goto failed;
6275
760
        Py_DECREF(value);
6276
760
        value = ast2obj_expr(state, o->v.Slice.upper);
6277
760
        if (!value) goto failed;
6278
760
        if (PyObject_SetAttr(result, state->upper, value) == -1)
6279
0
            goto failed;
6280
760
        Py_DECREF(value);
6281
760
        value = ast2obj_expr(state, o->v.Slice.step);
6282
760
        if (!value) goto failed;
6283
760
        if (PyObject_SetAttr(result, state->step, value) == -1)
6284
0
            goto failed;
6285
760
        Py_DECREF(value);
6286
760
        break;
6287
274k
    }
6288
274k
    value = ast2obj_int(state, o->lineno);
6289
274k
    if (!value) goto failed;
6290
274k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6291
0
        goto failed;
6292
274k
    Py_DECREF(value);
6293
274k
    value = ast2obj_int(state, o->col_offset);
6294
274k
    if (!value) goto failed;
6295
274k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6296
0
        goto failed;
6297
274k
    Py_DECREF(value);
6298
274k
    value = ast2obj_int(state, o->end_lineno);
6299
274k
    if (!value) goto failed;
6300
274k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6301
0
        goto failed;
6302
274k
    Py_DECREF(value);
6303
274k
    value = ast2obj_int(state, o->end_col_offset);
6304
274k
    if (!value) goto failed;
6305
274k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6306
0
        goto failed;
6307
274k
    Py_DECREF(value);
6308
274k
    Py_LeaveRecursiveCall();
6309
274k
    return result;
6310
0
failed:
6311
0
    Py_LeaveRecursiveCall();
6312
0
    Py_XDECREF(value);
6313
0
    Py_XDECREF(result);
6314
0
    return NULL;
6315
274k
}
6316
6317
PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
6318
50.7k
{
6319
50.7k
    switch(o) {
6320
44.0k
        case Load:
6321
44.0k
            return Py_NewRef(state->Load_singleton);
6322
6.45k
        case Store:
6323
6.45k
            return Py_NewRef(state->Store_singleton);
6324
262
        case Del:
6325
262
            return Py_NewRef(state->Del_singleton);
6326
50.7k
    }
6327
50.7k
    Py_UNREACHABLE();
6328
50.7k
}
6329
PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
6330
775
{
6331
775
    switch(o) {
6332
482
        case And:
6333
482
            return Py_NewRef(state->And_singleton);
6334
293
        case Or:
6335
293
            return Py_NewRef(state->Or_singleton);
6336
775
    }
6337
775
    Py_UNREACHABLE();
6338
775
}
6339
PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
6340
53.3k
{
6341
53.3k
    switch(o) {
6342
25.2k
        case Add:
6343
25.2k
            return Py_NewRef(state->Add_singleton);
6344
16.7k
        case Sub:
6345
16.7k
            return Py_NewRef(state->Sub_singleton);
6346
2.50k
        case Mult:
6347
2.50k
            return Py_NewRef(state->Mult_singleton);
6348
396
        case MatMult:
6349
396
            return Py_NewRef(state->MatMult_singleton);
6350
1.31k
        case Div:
6351
1.31k
            return Py_NewRef(state->Div_singleton);
6352
1.25k
        case Mod:
6353
1.25k
            return Py_NewRef(state->Mod_singleton);
6354
575
        case Pow:
6355
575
            return Py_NewRef(state->Pow_singleton);
6356
2.94k
        case LShift:
6357
2.94k
            return Py_NewRef(state->LShift_singleton);
6358
546
        case RShift:
6359
546
            return Py_NewRef(state->RShift_singleton);
6360
300
        case BitOr:
6361
300
            return Py_NewRef(state->BitOr_singleton);
6362
713
        case BitXor:
6363
713
            return Py_NewRef(state->BitXor_singleton);
6364
477
        case BitAnd:
6365
477
            return Py_NewRef(state->BitAnd_singleton);
6366
270
        case FloorDiv:
6367
270
            return Py_NewRef(state->FloorDiv_singleton);
6368
53.3k
    }
6369
53.3k
    Py_UNREACHABLE();
6370
53.3k
}
6371
PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
6372
97.9k
{
6373
97.9k
    switch(o) {
6374
81.1k
        case Invert:
6375
81.1k
            return Py_NewRef(state->Invert_singleton);
6376
20
        case Not:
6377
20
            return Py_NewRef(state->Not_singleton);
6378
8.59k
        case UAdd:
6379
8.59k
            return Py_NewRef(state->UAdd_singleton);
6380
8.11k
        case USub:
6381
8.11k
            return Py_NewRef(state->USub_singleton);
6382
97.9k
    }
6383
97.9k
    Py_UNREACHABLE();
6384
97.9k
}
6385
PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
6386
5.63k
{
6387
5.63k
    switch(o) {
6388
369
        case Eq:
6389
369
            return Py_NewRef(state->Eq_singleton);
6390
208
        case NotEq:
6391
208
            return Py_NewRef(state->NotEq_singleton);
6392
1.40k
        case Lt:
6393
1.40k
            return Py_NewRef(state->Lt_singleton);
6394
521
        case LtE:
6395
521
            return Py_NewRef(state->LtE_singleton);
6396
1.59k
        case Gt:
6397
1.59k
            return Py_NewRef(state->Gt_singleton);
6398
400
        case GtE:
6399
400
            return Py_NewRef(state->GtE_singleton);
6400
249
        case Is:
6401
249
            return Py_NewRef(state->Is_singleton);
6402
49
        case IsNot:
6403
49
            return Py_NewRef(state->IsNot_singleton);
6404
563
        case In:
6405
563
            return Py_NewRef(state->In_singleton);
6406
274
        case NotIn:
6407
274
            return Py_NewRef(state->NotIn_singleton);
6408
5.63k
    }
6409
5.63k
    Py_UNREACHABLE();
6410
5.63k
}
6411
PyObject*
6412
ast2obj_comprehension(struct ast_state *state, void* _o)
6413
721
{
6414
721
    comprehension_ty o = (comprehension_ty)_o;
6415
721
    PyObject *result = NULL, *value = NULL;
6416
721
    PyTypeObject *tp;
6417
721
    if (!o) {
6418
0
        Py_RETURN_NONE;
6419
0
    }
6420
721
    if (Py_EnterRecursiveCall("during  ast construction")) {
6421
0
        return NULL;
6422
0
    }
6423
721
    tp = (PyTypeObject *)state->comprehension_type;
6424
721
    result = PyType_GenericNew(tp, NULL, NULL);
6425
721
    if (!result) return NULL;
6426
721
    value = ast2obj_expr(state, o->target);
6427
721
    if (!value) goto failed;
6428
721
    if (PyObject_SetAttr(result, state->target, value) == -1)
6429
0
        goto failed;
6430
721
    Py_DECREF(value);
6431
721
    value = ast2obj_expr(state, o->iter);
6432
721
    if (!value) goto failed;
6433
721
    if (PyObject_SetAttr(result, state->iter, value) == -1)
6434
0
        goto failed;
6435
721
    Py_DECREF(value);
6436
721
    value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
6437
721
    if (!value) goto failed;
6438
721
    if (PyObject_SetAttr(result, state->ifs, value) == -1)
6439
0
        goto failed;
6440
721
    Py_DECREF(value);
6441
721
    value = ast2obj_int(state, o->is_async);
6442
721
    if (!value) goto failed;
6443
721
    if (PyObject_SetAttr(result, state->is_async, value) == -1)
6444
0
        goto failed;
6445
721
    Py_DECREF(value);
6446
721
    Py_LeaveRecursiveCall();
6447
721
    return result;
6448
0
failed:
6449
0
    Py_LeaveRecursiveCall();
6450
0
    Py_XDECREF(value);
6451
0
    Py_XDECREF(result);
6452
0
    return NULL;
6453
721
}
6454
6455
PyObject*
6456
ast2obj_excepthandler(struct ast_state *state, void* _o)
6457
1.01k
{
6458
1.01k
    excepthandler_ty o = (excepthandler_ty)_o;
6459
1.01k
    PyObject *result = NULL, *value = NULL;
6460
1.01k
    PyTypeObject *tp;
6461
1.01k
    if (!o) {
6462
0
        Py_RETURN_NONE;
6463
0
    }
6464
1.01k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6465
0
        return NULL;
6466
0
    }
6467
1.01k
    switch (o->kind) {
6468
1.01k
    case ExceptHandler_kind:
6469
1.01k
        tp = (PyTypeObject *)state->ExceptHandler_type;
6470
1.01k
        result = PyType_GenericNew(tp, NULL, NULL);
6471
1.01k
        if (!result) goto failed;
6472
1.01k
        value = ast2obj_expr(state, o->v.ExceptHandler.type);
6473
1.01k
        if (!value) goto failed;
6474
1.01k
        if (PyObject_SetAttr(result, state->type, value) == -1)
6475
0
            goto failed;
6476
1.01k
        Py_DECREF(value);
6477
1.01k
        value = ast2obj_identifier(state, o->v.ExceptHandler.name);
6478
1.01k
        if (!value) goto failed;
6479
1.01k
        if (PyObject_SetAttr(result, state->name, value) == -1)
6480
0
            goto failed;
6481
1.01k
        Py_DECREF(value);
6482
1.01k
        value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
6483
1.01k
                             ast2obj_stmt);
6484
1.01k
        if (!value) goto failed;
6485
1.01k
        if (PyObject_SetAttr(result, state->body, value) == -1)
6486
0
            goto failed;
6487
1.01k
        Py_DECREF(value);
6488
1.01k
        break;
6489
1.01k
    }
6490
1.01k
    value = ast2obj_int(state, o->lineno);
6491
1.01k
    if (!value) goto failed;
6492
1.01k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6493
0
        goto failed;
6494
1.01k
    Py_DECREF(value);
6495
1.01k
    value = ast2obj_int(state, o->col_offset);
6496
1.01k
    if (!value) goto failed;
6497
1.01k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6498
0
        goto failed;
6499
1.01k
    Py_DECREF(value);
6500
1.01k
    value = ast2obj_int(state, o->end_lineno);
6501
1.01k
    if (!value) goto failed;
6502
1.01k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6503
0
        goto failed;
6504
1.01k
    Py_DECREF(value);
6505
1.01k
    value = ast2obj_int(state, o->end_col_offset);
6506
1.01k
    if (!value) goto failed;
6507
1.01k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6508
0
        goto failed;
6509
1.01k
    Py_DECREF(value);
6510
1.01k
    Py_LeaveRecursiveCall();
6511
1.01k
    return result;
6512
0
failed:
6513
0
    Py_LeaveRecursiveCall();
6514
0
    Py_XDECREF(value);
6515
0
    Py_XDECREF(result);
6516
0
    return NULL;
6517
1.01k
}
6518
6519
PyObject*
6520
ast2obj_arguments(struct ast_state *state, void* _o)
6521
1.76k
{
6522
1.76k
    arguments_ty o = (arguments_ty)_o;
6523
1.76k
    PyObject *result = NULL, *value = NULL;
6524
1.76k
    PyTypeObject *tp;
6525
1.76k
    if (!o) {
6526
0
        Py_RETURN_NONE;
6527
0
    }
6528
1.76k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6529
0
        return NULL;
6530
0
    }
6531
1.76k
    tp = (PyTypeObject *)state->arguments_type;
6532
1.76k
    result = PyType_GenericNew(tp, NULL, NULL);
6533
1.76k
    if (!result) return NULL;
6534
1.76k
    value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
6535
1.76k
    if (!value) goto failed;
6536
1.76k
    if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
6537
0
        goto failed;
6538
1.76k
    Py_DECREF(value);
6539
1.76k
    value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
6540
1.76k
    if (!value) goto failed;
6541
1.76k
    if (PyObject_SetAttr(result, state->args, value) == -1)
6542
0
        goto failed;
6543
1.76k
    Py_DECREF(value);
6544
1.76k
    value = ast2obj_arg(state, o->vararg);
6545
1.76k
    if (!value) goto failed;
6546
1.76k
    if (PyObject_SetAttr(result, state->vararg, value) == -1)
6547
0
        goto failed;
6548
1.76k
    Py_DECREF(value);
6549
1.76k
    value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
6550
1.76k
    if (!value) goto failed;
6551
1.76k
    if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
6552
0
        goto failed;
6553
1.76k
    Py_DECREF(value);
6554
1.76k
    value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
6555
1.76k
    if (!value) goto failed;
6556
1.76k
    if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
6557
0
        goto failed;
6558
1.76k
    Py_DECREF(value);
6559
1.76k
    value = ast2obj_arg(state, o->kwarg);
6560
1.76k
    if (!value) goto failed;
6561
1.76k
    if (PyObject_SetAttr(result, state->kwarg, value) == -1)
6562
0
        goto failed;
6563
1.76k
    Py_DECREF(value);
6564
1.76k
    value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
6565
1.76k
    if (!value) goto failed;
6566
1.76k
    if (PyObject_SetAttr(result, state->defaults, value) == -1)
6567
0
        goto failed;
6568
1.76k
    Py_DECREF(value);
6569
1.76k
    Py_LeaveRecursiveCall();
6570
1.76k
    return result;
6571
0
failed:
6572
0
    Py_LeaveRecursiveCall();
6573
0
    Py_XDECREF(value);
6574
0
    Py_XDECREF(result);
6575
0
    return NULL;
6576
1.76k
}
6577
6578
PyObject*
6579
ast2obj_arg(struct ast_state *state, void* _o)
6580
6.64k
{
6581
6.64k
    arg_ty o = (arg_ty)_o;
6582
6.64k
    PyObject *result = NULL, *value = NULL;
6583
6.64k
    PyTypeObject *tp;
6584
6.64k
    if (!o) {
6585
2.93k
        Py_RETURN_NONE;
6586
2.93k
    }
6587
3.71k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6588
0
        return NULL;
6589
0
    }
6590
3.71k
    tp = (PyTypeObject *)state->arg_type;
6591
3.71k
    result = PyType_GenericNew(tp, NULL, NULL);
6592
3.71k
    if (!result) return NULL;
6593
3.71k
    value = ast2obj_identifier(state, o->arg);
6594
3.71k
    if (!value) goto failed;
6595
3.71k
    if (PyObject_SetAttr(result, state->arg, value) == -1)
6596
0
        goto failed;
6597
3.71k
    Py_DECREF(value);
6598
3.71k
    value = ast2obj_expr(state, o->annotation);
6599
3.71k
    if (!value) goto failed;
6600
3.71k
    if (PyObject_SetAttr(result, state->annotation, value) == -1)
6601
0
        goto failed;
6602
3.71k
    Py_DECREF(value);
6603
3.71k
    value = ast2obj_string(state, o->type_comment);
6604
3.71k
    if (!value) goto failed;
6605
3.71k
    if (PyObject_SetAttr(result, state->type_comment, value) == -1)
6606
0
        goto failed;
6607
3.71k
    Py_DECREF(value);
6608
3.71k
    value = ast2obj_int(state, o->lineno);
6609
3.71k
    if (!value) goto failed;
6610
3.71k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6611
0
        goto failed;
6612
3.71k
    Py_DECREF(value);
6613
3.71k
    value = ast2obj_int(state, o->col_offset);
6614
3.71k
    if (!value) goto failed;
6615
3.71k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6616
0
        goto failed;
6617
3.71k
    Py_DECREF(value);
6618
3.71k
    value = ast2obj_int(state, o->end_lineno);
6619
3.71k
    if (!value) goto failed;
6620
3.71k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6621
0
        goto failed;
6622
3.71k
    Py_DECREF(value);
6623
3.71k
    value = ast2obj_int(state, o->end_col_offset);
6624
3.71k
    if (!value) goto failed;
6625
3.71k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6626
0
        goto failed;
6627
3.71k
    Py_DECREF(value);
6628
3.71k
    Py_LeaveRecursiveCall();
6629
3.71k
    return result;
6630
0
failed:
6631
0
    Py_LeaveRecursiveCall();
6632
0
    Py_XDECREF(value);
6633
0
    Py_XDECREF(result);
6634
0
    return NULL;
6635
3.71k
}
6636
6637
PyObject*
6638
ast2obj_keyword(struct ast_state *state, void* _o)
6639
444
{
6640
444
    keyword_ty o = (keyword_ty)_o;
6641
444
    PyObject *result = NULL, *value = NULL;
6642
444
    PyTypeObject *tp;
6643
444
    if (!o) {
6644
0
        Py_RETURN_NONE;
6645
0
    }
6646
444
    if (Py_EnterRecursiveCall("during  ast construction")) {
6647
0
        return NULL;
6648
0
    }
6649
444
    tp = (PyTypeObject *)state->keyword_type;
6650
444
    result = PyType_GenericNew(tp, NULL, NULL);
6651
444
    if (!result) return NULL;
6652
444
    value = ast2obj_identifier(state, o->arg);
6653
444
    if (!value) goto failed;
6654
444
    if (PyObject_SetAttr(result, state->arg, value) == -1)
6655
0
        goto failed;
6656
444
    Py_DECREF(value);
6657
444
    value = ast2obj_expr(state, o->value);
6658
444
    if (!value) goto failed;
6659
444
    if (PyObject_SetAttr(result, state->value, value) == -1)
6660
0
        goto failed;
6661
444
    Py_DECREF(value);
6662
444
    value = ast2obj_int(state, o->lineno);
6663
444
    if (!value) goto failed;
6664
444
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6665
0
        goto failed;
6666
444
    Py_DECREF(value);
6667
444
    value = ast2obj_int(state, o->col_offset);
6668
444
    if (!value) goto failed;
6669
444
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6670
0
        goto failed;
6671
444
    Py_DECREF(value);
6672
444
    value = ast2obj_int(state, o->end_lineno);
6673
444
    if (!value) goto failed;
6674
444
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6675
0
        goto failed;
6676
444
    Py_DECREF(value);
6677
444
    value = ast2obj_int(state, o->end_col_offset);
6678
444
    if (!value) goto failed;
6679
444
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6680
0
        goto failed;
6681
444
    Py_DECREF(value);
6682
444
    Py_LeaveRecursiveCall();
6683
444
    return result;
6684
0
failed:
6685
0
    Py_LeaveRecursiveCall();
6686
0
    Py_XDECREF(value);
6687
0
    Py_XDECREF(result);
6688
0
    return NULL;
6689
444
}
6690
6691
PyObject*
6692
ast2obj_alias(struct ast_state *state, void* _o)
6693
1.51k
{
6694
1.51k
    alias_ty o = (alias_ty)_o;
6695
1.51k
    PyObject *result = NULL, *value = NULL;
6696
1.51k
    PyTypeObject *tp;
6697
1.51k
    if (!o) {
6698
0
        Py_RETURN_NONE;
6699
0
    }
6700
1.51k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6701
0
        return NULL;
6702
0
    }
6703
1.51k
    tp = (PyTypeObject *)state->alias_type;
6704
1.51k
    result = PyType_GenericNew(tp, NULL, NULL);
6705
1.51k
    if (!result) return NULL;
6706
1.51k
    value = ast2obj_identifier(state, o->name);
6707
1.51k
    if (!value) goto failed;
6708
1.51k
    if (PyObject_SetAttr(result, state->name, value) == -1)
6709
0
        goto failed;
6710
1.51k
    Py_DECREF(value);
6711
1.51k
    value = ast2obj_identifier(state, o->asname);
6712
1.51k
    if (!value) goto failed;
6713
1.51k
    if (PyObject_SetAttr(result, state->asname, value) == -1)
6714
0
        goto failed;
6715
1.51k
    Py_DECREF(value);
6716
1.51k
    value = ast2obj_int(state, o->lineno);
6717
1.51k
    if (!value) goto failed;
6718
1.51k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6719
0
        goto failed;
6720
1.51k
    Py_DECREF(value);
6721
1.51k
    value = ast2obj_int(state, o->col_offset);
6722
1.51k
    if (!value) goto failed;
6723
1.51k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6724
0
        goto failed;
6725
1.51k
    Py_DECREF(value);
6726
1.51k
    value = ast2obj_int(state, o->end_lineno);
6727
1.51k
    if (!value) goto failed;
6728
1.51k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6729
0
        goto failed;
6730
1.51k
    Py_DECREF(value);
6731
1.51k
    value = ast2obj_int(state, o->end_col_offset);
6732
1.51k
    if (!value) goto failed;
6733
1.51k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6734
0
        goto failed;
6735
1.51k
    Py_DECREF(value);
6736
1.51k
    Py_LeaveRecursiveCall();
6737
1.51k
    return result;
6738
0
failed:
6739
0
    Py_LeaveRecursiveCall();
6740
0
    Py_XDECREF(value);
6741
0
    Py_XDECREF(result);
6742
0
    return NULL;
6743
1.51k
}
6744
6745
PyObject*
6746
ast2obj_withitem(struct ast_state *state, void* _o)
6747
721
{
6748
721
    withitem_ty o = (withitem_ty)_o;
6749
721
    PyObject *result = NULL, *value = NULL;
6750
721
    PyTypeObject *tp;
6751
721
    if (!o) {
6752
0
        Py_RETURN_NONE;
6753
0
    }
6754
721
    if (Py_EnterRecursiveCall("during  ast construction")) {
6755
0
        return NULL;
6756
0
    }
6757
721
    tp = (PyTypeObject *)state->withitem_type;
6758
721
    result = PyType_GenericNew(tp, NULL, NULL);
6759
721
    if (!result) return NULL;
6760
721
    value = ast2obj_expr(state, o->context_expr);
6761
721
    if (!value) goto failed;
6762
721
    if (PyObject_SetAttr(result, state->context_expr, value) == -1)
6763
0
        goto failed;
6764
721
    Py_DECREF(value);
6765
721
    value = ast2obj_expr(state, o->optional_vars);
6766
721
    if (!value) goto failed;
6767
721
    if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
6768
0
        goto failed;
6769
721
    Py_DECREF(value);
6770
721
    Py_LeaveRecursiveCall();
6771
721
    return result;
6772
0
failed:
6773
0
    Py_LeaveRecursiveCall();
6774
0
    Py_XDECREF(value);
6775
0
    Py_XDECREF(result);
6776
0
    return NULL;
6777
721
}
6778
6779
PyObject*
6780
ast2obj_match_case(struct ast_state *state, void* _o)
6781
799
{
6782
799
    match_case_ty o = (match_case_ty)_o;
6783
799
    PyObject *result = NULL, *value = NULL;
6784
799
    PyTypeObject *tp;
6785
799
    if (!o) {
6786
0
        Py_RETURN_NONE;
6787
0
    }
6788
799
    if (Py_EnterRecursiveCall("during  ast construction")) {
6789
0
        return NULL;
6790
0
    }
6791
799
    tp = (PyTypeObject *)state->match_case_type;
6792
799
    result = PyType_GenericNew(tp, NULL, NULL);
6793
799
    if (!result) return NULL;
6794
799
    value = ast2obj_pattern(state, o->pattern);
6795
799
    if (!value) goto failed;
6796
799
    if (PyObject_SetAttr(result, state->pattern, value) == -1)
6797
0
        goto failed;
6798
799
    Py_DECREF(value);
6799
799
    value = ast2obj_expr(state, o->guard);
6800
799
    if (!value) goto failed;
6801
799
    if (PyObject_SetAttr(result, state->guard, value) == -1)
6802
0
        goto failed;
6803
799
    Py_DECREF(value);
6804
799
    value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
6805
799
    if (!value) goto failed;
6806
799
    if (PyObject_SetAttr(result, state->body, value) == -1)
6807
0
        goto failed;
6808
799
    Py_DECREF(value);
6809
799
    Py_LeaveRecursiveCall();
6810
799
    return result;
6811
0
failed:
6812
0
    Py_LeaveRecursiveCall();
6813
0
    Py_XDECREF(value);
6814
0
    Py_XDECREF(result);
6815
0
    return NULL;
6816
799
}
6817
6818
PyObject*
6819
ast2obj_pattern(struct ast_state *state, void* _o)
6820
12.6k
{
6821
12.6k
    pattern_ty o = (pattern_ty)_o;
6822
12.6k
    PyObject *result = NULL, *value = NULL;
6823
12.6k
    PyTypeObject *tp;
6824
12.6k
    if (!o) {
6825
4.52k
        Py_RETURN_NONE;
6826
4.52k
    }
6827
8.11k
    if (Py_EnterRecursiveCall("during  ast construction")) {
6828
0
        return NULL;
6829
0
    }
6830
8.11k
    switch (o->kind) {
6831
1.05k
    case MatchValue_kind:
6832
1.05k
        tp = (PyTypeObject *)state->MatchValue_type;
6833
1.05k
        result = PyType_GenericNew(tp, NULL, NULL);
6834
1.05k
        if (!result) goto failed;
6835
1.05k
        value = ast2obj_expr(state, o->v.MatchValue.value);
6836
1.05k
        if (!value) goto failed;
6837
1.05k
        if (PyObject_SetAttr(result, state->value, value) == -1)
6838
0
            goto failed;
6839
1.05k
        Py_DECREF(value);
6840
1.05k
        break;
6841
273
    case MatchSingleton_kind:
6842
273
        tp = (PyTypeObject *)state->MatchSingleton_type;
6843
273
        result = PyType_GenericNew(tp, NULL, NULL);
6844
273
        if (!result) goto failed;
6845
273
        value = ast2obj_constant(state, o->v.MatchSingleton.value);
6846
273
        if (!value) goto failed;
6847
273
        if (PyObject_SetAttr(result, state->value, value) == -1)
6848
0
            goto failed;
6849
273
        Py_DECREF(value);
6850
273
        break;
6851
547
    case MatchSequence_kind:
6852
547
        tp = (PyTypeObject *)state->MatchSequence_type;
6853
547
        result = PyType_GenericNew(tp, NULL, NULL);
6854
547
        if (!result) goto failed;
6855
547
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
6856
547
                             ast2obj_pattern);
6857
547
        if (!value) goto failed;
6858
547
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6859
0
            goto failed;
6860
547
        Py_DECREF(value);
6861
547
        break;
6862
214
    case MatchMapping_kind:
6863
214
        tp = (PyTypeObject *)state->MatchMapping_type;
6864
214
        result = PyType_GenericNew(tp, NULL, NULL);
6865
214
        if (!result) goto failed;
6866
214
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
6867
214
                             ast2obj_expr);
6868
214
        if (!value) goto failed;
6869
214
        if (PyObject_SetAttr(result, state->keys, value) == -1)
6870
0
            goto failed;
6871
214
        Py_DECREF(value);
6872
214
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
6873
214
                             ast2obj_pattern);
6874
214
        if (!value) goto failed;
6875
214
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6876
0
            goto failed;
6877
214
        Py_DECREF(value);
6878
214
        value = ast2obj_identifier(state, o->v.MatchMapping.rest);
6879
214
        if (!value) goto failed;
6880
214
        if (PyObject_SetAttr(result, state->rest, value) == -1)
6881
0
            goto failed;
6882
214
        Py_DECREF(value);
6883
214
        break;
6884
229
    case MatchClass_kind:
6885
229
        tp = (PyTypeObject *)state->MatchClass_type;
6886
229
        result = PyType_GenericNew(tp, NULL, NULL);
6887
229
        if (!result) goto failed;
6888
229
        value = ast2obj_expr(state, o->v.MatchClass.cls);
6889
229
        if (!value) goto failed;
6890
229
        if (PyObject_SetAttr(result, state->cls, value) == -1)
6891
0
            goto failed;
6892
229
        Py_DECREF(value);
6893
229
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
6894
229
                             ast2obj_pattern);
6895
229
        if (!value) goto failed;
6896
229
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6897
0
            goto failed;
6898
229
        Py_DECREF(value);
6899
229
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
6900
229
                             ast2obj_identifier);
6901
229
        if (!value) goto failed;
6902
229
        if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
6903
0
            goto failed;
6904
229
        Py_DECREF(value);
6905
229
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
6906
229
                             ast2obj_pattern);
6907
229
        if (!value) goto failed;
6908
229
        if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
6909
0
            goto failed;
6910
229
        Py_DECREF(value);
6911
229
        break;
6912
660
    case MatchStar_kind:
6913
660
        tp = (PyTypeObject *)state->MatchStar_type;
6914
660
        result = PyType_GenericNew(tp, NULL, NULL);
6915
660
        if (!result) goto failed;
6916
660
        value = ast2obj_identifier(state, o->v.MatchStar.name);
6917
660
        if (!value) goto failed;
6918
660
        if (PyObject_SetAttr(result, state->name, value) == -1)
6919
0
            goto failed;
6920
660
        Py_DECREF(value);
6921
660
        break;
6922
4.55k
    case MatchAs_kind:
6923
4.55k
        tp = (PyTypeObject *)state->MatchAs_type;
6924
4.55k
        result = PyType_GenericNew(tp, NULL, NULL);
6925
4.55k
        if (!result) goto failed;
6926
4.55k
        value = ast2obj_pattern(state, o->v.MatchAs.pattern);
6927
4.55k
        if (!value) goto failed;
6928
4.55k
        if (PyObject_SetAttr(result, state->pattern, value) == -1)
6929
0
            goto failed;
6930
4.55k
        Py_DECREF(value);
6931
4.55k
        value = ast2obj_identifier(state, o->v.MatchAs.name);
6932
4.55k
        if (!value) goto failed;
6933
4.55k
        if (PyObject_SetAttr(result, state->name, value) == -1)
6934
0
            goto failed;
6935
4.55k
        Py_DECREF(value);
6936
4.55k
        break;
6937
584
    case MatchOr_kind:
6938
584
        tp = (PyTypeObject *)state->MatchOr_type;
6939
584
        result = PyType_GenericNew(tp, NULL, NULL);
6940
584
        if (!result) goto failed;
6941
584
        value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
6942
584
                             ast2obj_pattern);
6943
584
        if (!value) goto failed;
6944
584
        if (PyObject_SetAttr(result, state->patterns, value) == -1)
6945
0
            goto failed;
6946
584
        Py_DECREF(value);
6947
584
        break;
6948
8.11k
    }
6949
8.11k
    value = ast2obj_int(state, o->lineno);
6950
8.11k
    if (!value) goto failed;
6951
8.11k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
6952
0
        goto failed;
6953
8.11k
    Py_DECREF(value);
6954
8.11k
    value = ast2obj_int(state, o->col_offset);
6955
8.11k
    if (!value) goto failed;
6956
8.11k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
6957
0
        goto failed;
6958
8.11k
    Py_DECREF(value);
6959
8.11k
    value = ast2obj_int(state, o->end_lineno);
6960
8.11k
    if (!value) goto failed;
6961
8.11k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
6962
0
        goto failed;
6963
8.11k
    Py_DECREF(value);
6964
8.11k
    value = ast2obj_int(state, o->end_col_offset);
6965
8.11k
    if (!value) goto failed;
6966
8.11k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
6967
0
        goto failed;
6968
8.11k
    Py_DECREF(value);
6969
8.11k
    Py_LeaveRecursiveCall();
6970
8.11k
    return result;
6971
0
failed:
6972
0
    Py_LeaveRecursiveCall();
6973
0
    Py_XDECREF(value);
6974
0
    Py_XDECREF(result);
6975
0
    return NULL;
6976
8.11k
}
6977
6978
PyObject*
6979
ast2obj_type_ignore(struct ast_state *state, void* _o)
6980
810
{
6981
810
    type_ignore_ty o = (type_ignore_ty)_o;
6982
810
    PyObject *result = NULL, *value = NULL;
6983
810
    PyTypeObject *tp;
6984
810
    if (!o) {
6985
0
        Py_RETURN_NONE;
6986
0
    }
6987
810
    if (Py_EnterRecursiveCall("during  ast construction")) {
6988
0
        return NULL;
6989
0
    }
6990
810
    switch (o->kind) {
6991
810
    case TypeIgnore_kind:
6992
810
        tp = (PyTypeObject *)state->TypeIgnore_type;
6993
810
        result = PyType_GenericNew(tp, NULL, NULL);
6994
810
        if (!result) goto failed;
6995
810
        value = ast2obj_int(state, o->v.TypeIgnore.lineno);
6996
810
        if (!value) goto failed;
6997
810
        if (PyObject_SetAttr(result, state->lineno, value) == -1)
6998
0
            goto failed;
6999
810
        Py_DECREF(value);
7000
810
        value = ast2obj_string(state, o->v.TypeIgnore.tag);
7001
810
        if (!value) goto failed;
7002
810
        if (PyObject_SetAttr(result, state->tag, value) == -1)
7003
0
            goto failed;
7004
810
        Py_DECREF(value);
7005
810
        break;
7006
810
    }
7007
810
    Py_LeaveRecursiveCall();
7008
810
    return result;
7009
0
failed:
7010
0
    Py_LeaveRecursiveCall();
7011
0
    Py_XDECREF(value);
7012
0
    Py_XDECREF(result);
7013
0
    return NULL;
7014
810
}
7015
7016
PyObject*
7017
ast2obj_type_param(struct ast_state *state, void* _o)
7018
3.39k
{
7019
3.39k
    type_param_ty o = (type_param_ty)_o;
7020
3.39k
    PyObject *result = NULL, *value = NULL;
7021
3.39k
    PyTypeObject *tp;
7022
3.39k
    if (!o) {
7023
0
        Py_RETURN_NONE;
7024
0
    }
7025
3.39k
    if (Py_EnterRecursiveCall("during  ast construction")) {
7026
0
        return NULL;
7027
0
    }
7028
3.39k
    switch (o->kind) {
7029
2.47k
    case TypeVar_kind:
7030
2.47k
        tp = (PyTypeObject *)state->TypeVar_type;
7031
2.47k
        result = PyType_GenericNew(tp, NULL, NULL);
7032
2.47k
        if (!result) goto failed;
7033
2.47k
        value = ast2obj_identifier(state, o->v.TypeVar.name);
7034
2.47k
        if (!value) goto failed;
7035
2.47k
        if (PyObject_SetAttr(result, state->name, value) == -1)
7036
0
            goto failed;
7037
2.47k
        Py_DECREF(value);
7038
2.47k
        value = ast2obj_expr(state, o->v.TypeVar.bound);
7039
2.47k
        if (!value) goto failed;
7040
2.47k
        if (PyObject_SetAttr(result, state->bound, value) == -1)
7041
0
            goto failed;
7042
2.47k
        Py_DECREF(value);
7043
2.47k
        value = ast2obj_expr(state, o->v.TypeVar.default_value);
7044
2.47k
        if (!value) goto failed;
7045
2.47k
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7046
0
            goto failed;
7047
2.47k
        Py_DECREF(value);
7048
2.47k
        break;
7049
524
    case ParamSpec_kind:
7050
524
        tp = (PyTypeObject *)state->ParamSpec_type;
7051
524
        result = PyType_GenericNew(tp, NULL, NULL);
7052
524
        if (!result) goto failed;
7053
524
        value = ast2obj_identifier(state, o->v.ParamSpec.name);
7054
524
        if (!value) goto failed;
7055
524
        if (PyObject_SetAttr(result, state->name, value) == -1)
7056
0
            goto failed;
7057
524
        Py_DECREF(value);
7058
524
        value = ast2obj_expr(state, o->v.ParamSpec.default_value);
7059
524
        if (!value) goto failed;
7060
524
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7061
0
            goto failed;
7062
524
        Py_DECREF(value);
7063
524
        break;
7064
394
    case TypeVarTuple_kind:
7065
394
        tp = (PyTypeObject *)state->TypeVarTuple_type;
7066
394
        result = PyType_GenericNew(tp, NULL, NULL);
7067
394
        if (!result) goto failed;
7068
394
        value = ast2obj_identifier(state, o->v.TypeVarTuple.name);
7069
394
        if (!value) goto failed;
7070
394
        if (PyObject_SetAttr(result, state->name, value) == -1)
7071
0
            goto failed;
7072
394
        Py_DECREF(value);
7073
394
        value = ast2obj_expr(state, o->v.TypeVarTuple.default_value);
7074
394
        if (!value) goto failed;
7075
394
        if (PyObject_SetAttr(result, state->default_value, value) == -1)
7076
0
            goto failed;
7077
394
        Py_DECREF(value);
7078
394
        break;
7079
3.39k
    }
7080
3.39k
    value = ast2obj_int(state, o->lineno);
7081
3.39k
    if (!value) goto failed;
7082
3.39k
    if (PyObject_SetAttr(result, state->lineno, value) < 0)
7083
0
        goto failed;
7084
3.39k
    Py_DECREF(value);
7085
3.39k
    value = ast2obj_int(state, o->col_offset);
7086
3.39k
    if (!value) goto failed;
7087
3.39k
    if (PyObject_SetAttr(result, state->col_offset, value) < 0)
7088
0
        goto failed;
7089
3.39k
    Py_DECREF(value);
7090
3.39k
    value = ast2obj_int(state, o->end_lineno);
7091
3.39k
    if (!value) goto failed;
7092
3.39k
    if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
7093
0
        goto failed;
7094
3.39k
    Py_DECREF(value);
7095
3.39k
    value = ast2obj_int(state, o->end_col_offset);
7096
3.39k
    if (!value) goto failed;
7097
3.39k
    if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
7098
0
        goto failed;
7099
3.39k
    Py_DECREF(value);
7100
3.39k
    Py_LeaveRecursiveCall();
7101
3.39k
    return result;
7102
0
failed:
7103
0
    Py_LeaveRecursiveCall();
7104
0
    Py_XDECREF(value);
7105
0
    Py_XDECREF(result);
7106
0
    return NULL;
7107
3.39k
}
7108
7109
7110
int
7111
obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, const char*
7112
            field, PyArena* arena)
7113
0
{
7114
0
    int isinstance;
7115
7116
0
    PyObject *tmp = NULL;
7117
0
    PyObject *tp;
7118
7119
0
    if (obj == Py_None) {
7120
0
        *out = NULL;
7121
0
        return 0;
7122
0
    }
7123
0
    tp = state->mod_type;
7124
0
    isinstance = PyObject_IsInstance(obj, tp);
7125
0
    if (isinstance == -1) {
7126
0
        return 1;
7127
0
    }
7128
0
    if (!isinstance && field != NULL) {
7129
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'mod', got '%T'", field, obj);
7130
0
        return 1;
7131
0
    }
7132
0
    tp = state->Module_type;
7133
0
    isinstance = PyObject_IsInstance(obj, tp);
7134
0
    if (isinstance == -1) {
7135
0
        return -1;
7136
0
    }
7137
0
    if (isinstance) {
7138
0
        asdl_stmt_seq* body;
7139
0
        asdl_type_ignore_seq* type_ignores;
7140
7141
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7142
0
            return -1;
7143
0
        }
7144
0
        if (tmp == NULL) {
7145
0
            tmp = PyList_New(0);
7146
0
            if (tmp == NULL) {
7147
0
                return -1;
7148
0
            }
7149
0
        }
7150
0
        {
7151
0
            int res;
7152
0
            Py_ssize_t len;
7153
0
            Py_ssize_t i;
7154
0
            if (!PyList_Check(tmp)) {
7155
0
                PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %T", tmp);
7156
0
                goto failed;
7157
0
            }
7158
0
            len = PyList_GET_SIZE(tmp);
7159
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7160
0
            if (body == NULL) goto failed;
7161
0
            for (i = 0; i < len; i++) {
7162
0
                stmt_ty val;
7163
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7164
0
                if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
7165
0
                    goto failed;
7166
0
                }
7167
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7168
0
                _Py_LeaveRecursiveCall();
7169
0
                Py_DECREF(tmp2);
7170
0
                if (res != 0) goto failed;
7171
0
                if (len != PyList_GET_SIZE(tmp)) {
7172
0
                    PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
7173
0
                    goto failed;
7174
0
                }
7175
0
                asdl_seq_SET(body, i, val);
7176
0
            }
7177
0
            Py_CLEAR(tmp);
7178
0
        }
7179
0
        if (PyObject_GetOptionalAttr(obj, state->type_ignores, &tmp) < 0) {
7180
0
            return -1;
7181
0
        }
7182
0
        if (tmp == NULL) {
7183
0
            tmp = PyList_New(0);
7184
0
            if (tmp == NULL) {
7185
0
                return -1;
7186
0
            }
7187
0
        }
7188
0
        {
7189
0
            int res;
7190
0
            Py_ssize_t len;
7191
0
            Py_ssize_t i;
7192
0
            if (!PyList_Check(tmp)) {
7193
0
                PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %T", tmp);
7194
0
                goto failed;
7195
0
            }
7196
0
            len = PyList_GET_SIZE(tmp);
7197
0
            type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
7198
0
            if (type_ignores == NULL) goto failed;
7199
0
            for (i = 0; i < len; i++) {
7200
0
                type_ignore_ty val;
7201
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7202
0
                if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
7203
0
                    goto failed;
7204
0
                }
7205
0
                res = obj2ast_type_ignore(state, tmp2, &val, "type_ignores", arena);
7206
0
                _Py_LeaveRecursiveCall();
7207
0
                Py_DECREF(tmp2);
7208
0
                if (res != 0) goto failed;
7209
0
                if (len != PyList_GET_SIZE(tmp)) {
7210
0
                    PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
7211
0
                    goto failed;
7212
0
                }
7213
0
                asdl_seq_SET(type_ignores, i, val);
7214
0
            }
7215
0
            Py_CLEAR(tmp);
7216
0
        }
7217
0
        *out = _PyAST_Module(body, type_ignores, arena);
7218
0
        if (*out == NULL) goto failed;
7219
0
        return 0;
7220
0
    }
7221
0
    tp = state->Interactive_type;
7222
0
    isinstance = PyObject_IsInstance(obj, tp);
7223
0
    if (isinstance == -1) {
7224
0
        return -1;
7225
0
    }
7226
0
    if (isinstance) {
7227
0
        asdl_stmt_seq* body;
7228
7229
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7230
0
            return -1;
7231
0
        }
7232
0
        if (tmp == NULL) {
7233
0
            tmp = PyList_New(0);
7234
0
            if (tmp == NULL) {
7235
0
                return -1;
7236
0
            }
7237
0
        }
7238
0
        {
7239
0
            int res;
7240
0
            Py_ssize_t len;
7241
0
            Py_ssize_t i;
7242
0
            if (!PyList_Check(tmp)) {
7243
0
                PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %T", tmp);
7244
0
                goto failed;
7245
0
            }
7246
0
            len = PyList_GET_SIZE(tmp);
7247
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7248
0
            if (body == NULL) goto failed;
7249
0
            for (i = 0; i < len; i++) {
7250
0
                stmt_ty val;
7251
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7252
0
                if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
7253
0
                    goto failed;
7254
0
                }
7255
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7256
0
                _Py_LeaveRecursiveCall();
7257
0
                Py_DECREF(tmp2);
7258
0
                if (res != 0) goto failed;
7259
0
                if (len != PyList_GET_SIZE(tmp)) {
7260
0
                    PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
7261
0
                    goto failed;
7262
0
                }
7263
0
                asdl_seq_SET(body, i, val);
7264
0
            }
7265
0
            Py_CLEAR(tmp);
7266
0
        }
7267
0
        *out = _PyAST_Interactive(body, arena);
7268
0
        if (*out == NULL) goto failed;
7269
0
        return 0;
7270
0
    }
7271
0
    tp = state->Expression_type;
7272
0
    isinstance = PyObject_IsInstance(obj, tp);
7273
0
    if (isinstance == -1) {
7274
0
        return -1;
7275
0
    }
7276
0
    if (isinstance) {
7277
0
        expr_ty body;
7278
7279
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7280
0
            return -1;
7281
0
        }
7282
0
        if (tmp == NULL) {
7283
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
7284
0
            return -1;
7285
0
        }
7286
0
        else {
7287
0
            int res;
7288
0
            if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
7289
0
                goto failed;
7290
0
            }
7291
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
7292
0
            _Py_LeaveRecursiveCall();
7293
0
            if (res != 0) goto failed;
7294
0
            Py_CLEAR(tmp);
7295
0
        }
7296
0
        *out = _PyAST_Expression(body, arena);
7297
0
        if (*out == NULL) goto failed;
7298
0
        return 0;
7299
0
    }
7300
0
    tp = state->FunctionType_type;
7301
0
    isinstance = PyObject_IsInstance(obj, tp);
7302
0
    if (isinstance == -1) {
7303
0
        return -1;
7304
0
    }
7305
0
    if (isinstance) {
7306
0
        asdl_expr_seq* argtypes;
7307
0
        expr_ty returns;
7308
7309
0
        if (PyObject_GetOptionalAttr(obj, state->argtypes, &tmp) < 0) {
7310
0
            return -1;
7311
0
        }
7312
0
        if (tmp == NULL) {
7313
0
            tmp = PyList_New(0);
7314
0
            if (tmp == NULL) {
7315
0
                return -1;
7316
0
            }
7317
0
        }
7318
0
        {
7319
0
            int res;
7320
0
            Py_ssize_t len;
7321
0
            Py_ssize_t i;
7322
0
            if (!PyList_Check(tmp)) {
7323
0
                PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %T", tmp);
7324
0
                goto failed;
7325
0
            }
7326
0
            len = PyList_GET_SIZE(tmp);
7327
0
            argtypes = _Py_asdl_expr_seq_new(len, arena);
7328
0
            if (argtypes == NULL) goto failed;
7329
0
            for (i = 0; i < len; i++) {
7330
0
                expr_ty val;
7331
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7332
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
7333
0
                    goto failed;
7334
0
                }
7335
0
                res = obj2ast_expr(state, tmp2, &val, "argtypes", arena);
7336
0
                _Py_LeaveRecursiveCall();
7337
0
                Py_DECREF(tmp2);
7338
0
                if (res != 0) goto failed;
7339
0
                if (len != PyList_GET_SIZE(tmp)) {
7340
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
7341
0
                    goto failed;
7342
0
                }
7343
0
                asdl_seq_SET(argtypes, i, val);
7344
0
            }
7345
0
            Py_CLEAR(tmp);
7346
0
        }
7347
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7348
0
            return -1;
7349
0
        }
7350
0
        if (tmp == NULL) {
7351
0
            PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
7352
0
            return -1;
7353
0
        }
7354
0
        else {
7355
0
            int res;
7356
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
7357
0
                goto failed;
7358
0
            }
7359
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7360
0
            _Py_LeaveRecursiveCall();
7361
0
            if (res != 0) goto failed;
7362
0
            Py_CLEAR(tmp);
7363
0
        }
7364
0
        *out = _PyAST_FunctionType(argtypes, returns, arena);
7365
0
        if (*out == NULL) goto failed;
7366
0
        return 0;
7367
0
    }
7368
7369
0
    PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
7370
0
    failed:
7371
0
    Py_XDECREF(tmp);
7372
0
    return -1;
7373
0
}
7374
7375
int
7376
obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, const char*
7377
             field, PyArena* arena)
7378
0
{
7379
0
    int isinstance;
7380
7381
0
    PyObject *tmp = NULL;
7382
0
    PyObject *tp;
7383
0
    int lineno;
7384
0
    int col_offset;
7385
0
    int end_lineno;
7386
0
    int end_col_offset;
7387
7388
0
    if (obj == Py_None) {
7389
0
        *out = NULL;
7390
0
        return 0;
7391
0
    }
7392
0
    tp = state->stmt_type;
7393
0
    isinstance = PyObject_IsInstance(obj, tp);
7394
0
    if (isinstance == -1) {
7395
0
        return 1;
7396
0
    }
7397
0
    if (!isinstance && field != NULL) {
7398
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'stmt', got '%T'", field, obj);
7399
0
        return 1;
7400
0
    }
7401
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
7402
0
        return -1;
7403
0
    }
7404
0
    if (tmp == NULL) {
7405
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
7406
0
        return -1;
7407
0
    }
7408
0
    else {
7409
0
        int res;
7410
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7411
0
            goto failed;
7412
0
        }
7413
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
7414
0
        _Py_LeaveRecursiveCall();
7415
0
        if (res != 0) goto failed;
7416
0
        Py_CLEAR(tmp);
7417
0
    }
7418
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
7419
0
        return -1;
7420
0
    }
7421
0
    if (tmp == NULL) {
7422
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
7423
0
        return -1;
7424
0
    }
7425
0
    else {
7426
0
        int res;
7427
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7428
0
            goto failed;
7429
0
        }
7430
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
7431
0
        _Py_LeaveRecursiveCall();
7432
0
        if (res != 0) goto failed;
7433
0
        Py_CLEAR(tmp);
7434
0
    }
7435
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
7436
0
        return -1;
7437
0
    }
7438
0
    if (tmp == NULL || tmp == Py_None) {
7439
0
        Py_CLEAR(tmp);
7440
0
        end_lineno = lineno;
7441
0
    }
7442
0
    else {
7443
0
        int res;
7444
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7445
0
            goto failed;
7446
0
        }
7447
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
7448
0
        _Py_LeaveRecursiveCall();
7449
0
        if (res != 0) goto failed;
7450
0
        Py_CLEAR(tmp);
7451
0
    }
7452
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
7453
0
        return -1;
7454
0
    }
7455
0
    if (tmp == NULL || tmp == Py_None) {
7456
0
        Py_CLEAR(tmp);
7457
0
        end_col_offset = col_offset;
7458
0
    }
7459
0
    else {
7460
0
        int res;
7461
0
        if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
7462
0
            goto failed;
7463
0
        }
7464
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
7465
0
        _Py_LeaveRecursiveCall();
7466
0
        if (res != 0) goto failed;
7467
0
        Py_CLEAR(tmp);
7468
0
    }
7469
0
    tp = state->FunctionDef_type;
7470
0
    isinstance = PyObject_IsInstance(obj, tp);
7471
0
    if (isinstance == -1) {
7472
0
        return -1;
7473
0
    }
7474
0
    if (isinstance) {
7475
0
        identifier name;
7476
0
        arguments_ty args;
7477
0
        asdl_stmt_seq* body;
7478
0
        asdl_expr_seq* decorator_list;
7479
0
        expr_ty returns;
7480
0
        string type_comment;
7481
0
        asdl_type_param_seq* type_params;
7482
7483
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7484
0
            return -1;
7485
0
        }
7486
0
        if (tmp == NULL) {
7487
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
7488
0
            return -1;
7489
0
        }
7490
0
        else {
7491
0
            int res;
7492
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7493
0
                goto failed;
7494
0
            }
7495
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7496
0
            _Py_LeaveRecursiveCall();
7497
0
            if (res != 0) goto failed;
7498
0
            Py_CLEAR(tmp);
7499
0
        }
7500
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
7501
0
            return -1;
7502
0
        }
7503
0
        if (tmp == NULL) {
7504
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
7505
0
            return -1;
7506
0
        }
7507
0
        else {
7508
0
            int res;
7509
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7510
0
                goto failed;
7511
0
            }
7512
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
7513
0
            _Py_LeaveRecursiveCall();
7514
0
            if (res != 0) goto failed;
7515
0
            Py_CLEAR(tmp);
7516
0
        }
7517
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7518
0
            return -1;
7519
0
        }
7520
0
        if (tmp == NULL) {
7521
0
            tmp = PyList_New(0);
7522
0
            if (tmp == NULL) {
7523
0
                return -1;
7524
0
            }
7525
0
        }
7526
0
        {
7527
0
            int res;
7528
0
            Py_ssize_t len;
7529
0
            Py_ssize_t i;
7530
0
            if (!PyList_Check(tmp)) {
7531
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %T", tmp);
7532
0
                goto failed;
7533
0
            }
7534
0
            len = PyList_GET_SIZE(tmp);
7535
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7536
0
            if (body == NULL) goto failed;
7537
0
            for (i = 0; i < len; i++) {
7538
0
                stmt_ty val;
7539
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7540
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7541
0
                    goto failed;
7542
0
                }
7543
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7544
0
                _Py_LeaveRecursiveCall();
7545
0
                Py_DECREF(tmp2);
7546
0
                if (res != 0) goto failed;
7547
0
                if (len != PyList_GET_SIZE(tmp)) {
7548
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
7549
0
                    goto failed;
7550
0
                }
7551
0
                asdl_seq_SET(body, i, val);
7552
0
            }
7553
0
            Py_CLEAR(tmp);
7554
0
        }
7555
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
7556
0
            return -1;
7557
0
        }
7558
0
        if (tmp == NULL) {
7559
0
            tmp = PyList_New(0);
7560
0
            if (tmp == NULL) {
7561
0
                return -1;
7562
0
            }
7563
0
        }
7564
0
        {
7565
0
            int res;
7566
0
            Py_ssize_t len;
7567
0
            Py_ssize_t i;
7568
0
            if (!PyList_Check(tmp)) {
7569
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %T", tmp);
7570
0
                goto failed;
7571
0
            }
7572
0
            len = PyList_GET_SIZE(tmp);
7573
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
7574
0
            if (decorator_list == NULL) goto failed;
7575
0
            for (i = 0; i < len; i++) {
7576
0
                expr_ty val;
7577
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7578
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7579
0
                    goto failed;
7580
0
                }
7581
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
7582
0
                _Py_LeaveRecursiveCall();
7583
0
                Py_DECREF(tmp2);
7584
0
                if (res != 0) goto failed;
7585
0
                if (len != PyList_GET_SIZE(tmp)) {
7586
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
7587
0
                    goto failed;
7588
0
                }
7589
0
                asdl_seq_SET(decorator_list, i, val);
7590
0
            }
7591
0
            Py_CLEAR(tmp);
7592
0
        }
7593
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7594
0
            return -1;
7595
0
        }
7596
0
        if (tmp == NULL || tmp == Py_None) {
7597
0
            Py_CLEAR(tmp);
7598
0
            returns = NULL;
7599
0
        }
7600
0
        else {
7601
0
            int res;
7602
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7603
0
                goto failed;
7604
0
            }
7605
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7606
0
            _Py_LeaveRecursiveCall();
7607
0
            if (res != 0) goto failed;
7608
0
            Py_CLEAR(tmp);
7609
0
        }
7610
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
7611
0
            return -1;
7612
0
        }
7613
0
        if (tmp == NULL || tmp == Py_None) {
7614
0
            Py_CLEAR(tmp);
7615
0
            type_comment = NULL;
7616
0
        }
7617
0
        else {
7618
0
            int res;
7619
0
            if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7620
0
                goto failed;
7621
0
            }
7622
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
7623
0
                                 arena);
7624
0
            _Py_LeaveRecursiveCall();
7625
0
            if (res != 0) goto failed;
7626
0
            Py_CLEAR(tmp);
7627
0
        }
7628
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
7629
0
            return -1;
7630
0
        }
7631
0
        if (tmp == NULL) {
7632
0
            tmp = PyList_New(0);
7633
0
            if (tmp == NULL) {
7634
0
                return -1;
7635
0
            }
7636
0
        }
7637
0
        {
7638
0
            int res;
7639
0
            Py_ssize_t len;
7640
0
            Py_ssize_t i;
7641
0
            if (!PyList_Check(tmp)) {
7642
0
                PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %T", tmp);
7643
0
                goto failed;
7644
0
            }
7645
0
            len = PyList_GET_SIZE(tmp);
7646
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
7647
0
            if (type_params == NULL) goto failed;
7648
0
            for (i = 0; i < len; i++) {
7649
0
                type_param_ty val;
7650
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7651
0
                if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
7652
0
                    goto failed;
7653
0
                }
7654
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
7655
0
                _Py_LeaveRecursiveCall();
7656
0
                Py_DECREF(tmp2);
7657
0
                if (res != 0) goto failed;
7658
0
                if (len != PyList_GET_SIZE(tmp)) {
7659
0
                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
7660
0
                    goto failed;
7661
0
                }
7662
0
                asdl_seq_SET(type_params, i, val);
7663
0
            }
7664
0
            Py_CLEAR(tmp);
7665
0
        }
7666
0
        *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
7667
0
                                  type_comment, type_params, lineno,
7668
0
                                  col_offset, end_lineno, end_col_offset,
7669
0
                                  arena);
7670
0
        if (*out == NULL) goto failed;
7671
0
        return 0;
7672
0
    }
7673
0
    tp = state->AsyncFunctionDef_type;
7674
0
    isinstance = PyObject_IsInstance(obj, tp);
7675
0
    if (isinstance == -1) {
7676
0
        return -1;
7677
0
    }
7678
0
    if (isinstance) {
7679
0
        identifier name;
7680
0
        arguments_ty args;
7681
0
        asdl_stmt_seq* body;
7682
0
        asdl_expr_seq* decorator_list;
7683
0
        expr_ty returns;
7684
0
        string type_comment;
7685
0
        asdl_type_param_seq* type_params;
7686
7687
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7688
0
            return -1;
7689
0
        }
7690
0
        if (tmp == NULL) {
7691
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
7692
0
            return -1;
7693
0
        }
7694
0
        else {
7695
0
            int res;
7696
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7697
0
                goto failed;
7698
0
            }
7699
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7700
0
            _Py_LeaveRecursiveCall();
7701
0
            if (res != 0) goto failed;
7702
0
            Py_CLEAR(tmp);
7703
0
        }
7704
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
7705
0
            return -1;
7706
0
        }
7707
0
        if (tmp == NULL) {
7708
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
7709
0
            return -1;
7710
0
        }
7711
0
        else {
7712
0
            int res;
7713
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7714
0
                goto failed;
7715
0
            }
7716
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
7717
0
            _Py_LeaveRecursiveCall();
7718
0
            if (res != 0) goto failed;
7719
0
            Py_CLEAR(tmp);
7720
0
        }
7721
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7722
0
            return -1;
7723
0
        }
7724
0
        if (tmp == NULL) {
7725
0
            tmp = PyList_New(0);
7726
0
            if (tmp == NULL) {
7727
0
                return -1;
7728
0
            }
7729
0
        }
7730
0
        {
7731
0
            int res;
7732
0
            Py_ssize_t len;
7733
0
            Py_ssize_t i;
7734
0
            if (!PyList_Check(tmp)) {
7735
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %T", tmp);
7736
0
                goto failed;
7737
0
            }
7738
0
            len = PyList_GET_SIZE(tmp);
7739
0
            body = _Py_asdl_stmt_seq_new(len, arena);
7740
0
            if (body == NULL) goto failed;
7741
0
            for (i = 0; i < len; i++) {
7742
0
                stmt_ty val;
7743
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7744
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7745
0
                    goto failed;
7746
0
                }
7747
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
7748
0
                _Py_LeaveRecursiveCall();
7749
0
                Py_DECREF(tmp2);
7750
0
                if (res != 0) goto failed;
7751
0
                if (len != PyList_GET_SIZE(tmp)) {
7752
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
7753
0
                    goto failed;
7754
0
                }
7755
0
                asdl_seq_SET(body, i, val);
7756
0
            }
7757
0
            Py_CLEAR(tmp);
7758
0
        }
7759
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
7760
0
            return -1;
7761
0
        }
7762
0
        if (tmp == NULL) {
7763
0
            tmp = PyList_New(0);
7764
0
            if (tmp == NULL) {
7765
0
                return -1;
7766
0
            }
7767
0
        }
7768
0
        {
7769
0
            int res;
7770
0
            Py_ssize_t len;
7771
0
            Py_ssize_t i;
7772
0
            if (!PyList_Check(tmp)) {
7773
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %T", tmp);
7774
0
                goto failed;
7775
0
            }
7776
0
            len = PyList_GET_SIZE(tmp);
7777
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
7778
0
            if (decorator_list == NULL) goto failed;
7779
0
            for (i = 0; i < len; i++) {
7780
0
                expr_ty val;
7781
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7782
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7783
0
                    goto failed;
7784
0
                }
7785
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
7786
0
                _Py_LeaveRecursiveCall();
7787
0
                Py_DECREF(tmp2);
7788
0
                if (res != 0) goto failed;
7789
0
                if (len != PyList_GET_SIZE(tmp)) {
7790
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
7791
0
                    goto failed;
7792
0
                }
7793
0
                asdl_seq_SET(decorator_list, i, val);
7794
0
            }
7795
0
            Py_CLEAR(tmp);
7796
0
        }
7797
0
        if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
7798
0
            return -1;
7799
0
        }
7800
0
        if (tmp == NULL || tmp == Py_None) {
7801
0
            Py_CLEAR(tmp);
7802
0
            returns = NULL;
7803
0
        }
7804
0
        else {
7805
0
            int res;
7806
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7807
0
                goto failed;
7808
0
            }
7809
0
            res = obj2ast_expr(state, tmp, &returns, "returns", arena);
7810
0
            _Py_LeaveRecursiveCall();
7811
0
            if (res != 0) goto failed;
7812
0
            Py_CLEAR(tmp);
7813
0
        }
7814
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
7815
0
            return -1;
7816
0
        }
7817
0
        if (tmp == NULL || tmp == Py_None) {
7818
0
            Py_CLEAR(tmp);
7819
0
            type_comment = NULL;
7820
0
        }
7821
0
        else {
7822
0
            int res;
7823
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7824
0
                goto failed;
7825
0
            }
7826
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
7827
0
                                 arena);
7828
0
            _Py_LeaveRecursiveCall();
7829
0
            if (res != 0) goto failed;
7830
0
            Py_CLEAR(tmp);
7831
0
        }
7832
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
7833
0
            return -1;
7834
0
        }
7835
0
        if (tmp == NULL) {
7836
0
            tmp = PyList_New(0);
7837
0
            if (tmp == NULL) {
7838
0
                return -1;
7839
0
            }
7840
0
        }
7841
0
        {
7842
0
            int res;
7843
0
            Py_ssize_t len;
7844
0
            Py_ssize_t i;
7845
0
            if (!PyList_Check(tmp)) {
7846
0
                PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %T", tmp);
7847
0
                goto failed;
7848
0
            }
7849
0
            len = PyList_GET_SIZE(tmp);
7850
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
7851
0
            if (type_params == NULL) goto failed;
7852
0
            for (i = 0; i < len; i++) {
7853
0
                type_param_ty val;
7854
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7855
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
7856
0
                    goto failed;
7857
0
                }
7858
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
7859
0
                _Py_LeaveRecursiveCall();
7860
0
                Py_DECREF(tmp2);
7861
0
                if (res != 0) goto failed;
7862
0
                if (len != PyList_GET_SIZE(tmp)) {
7863
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
7864
0
                    goto failed;
7865
0
                }
7866
0
                asdl_seq_SET(type_params, i, val);
7867
0
            }
7868
0
            Py_CLEAR(tmp);
7869
0
        }
7870
0
        *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
7871
0
                                       returns, type_comment, type_params,
7872
0
                                       lineno, col_offset, end_lineno,
7873
0
                                       end_col_offset, arena);
7874
0
        if (*out == NULL) goto failed;
7875
0
        return 0;
7876
0
    }
7877
0
    tp = state->ClassDef_type;
7878
0
    isinstance = PyObject_IsInstance(obj, tp);
7879
0
    if (isinstance == -1) {
7880
0
        return -1;
7881
0
    }
7882
0
    if (isinstance) {
7883
0
        identifier name;
7884
0
        asdl_expr_seq* bases;
7885
0
        asdl_keyword_seq* keywords;
7886
0
        asdl_stmt_seq* body;
7887
0
        asdl_expr_seq* decorator_list;
7888
0
        asdl_type_param_seq* type_params;
7889
7890
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
7891
0
            return -1;
7892
0
        }
7893
0
        if (tmp == NULL) {
7894
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
7895
0
            return -1;
7896
0
        }
7897
0
        else {
7898
0
            int res;
7899
0
            if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7900
0
                goto failed;
7901
0
            }
7902
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
7903
0
            _Py_LeaveRecursiveCall();
7904
0
            if (res != 0) goto failed;
7905
0
            Py_CLEAR(tmp);
7906
0
        }
7907
0
        if (PyObject_GetOptionalAttr(obj, state->bases, &tmp) < 0) {
7908
0
            return -1;
7909
0
        }
7910
0
        if (tmp == NULL) {
7911
0
            tmp = PyList_New(0);
7912
0
            if (tmp == NULL) {
7913
0
                return -1;
7914
0
            }
7915
0
        }
7916
0
        {
7917
0
            int res;
7918
0
            Py_ssize_t len;
7919
0
            Py_ssize_t i;
7920
0
            if (!PyList_Check(tmp)) {
7921
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %T", tmp);
7922
0
                goto failed;
7923
0
            }
7924
0
            len = PyList_GET_SIZE(tmp);
7925
0
            bases = _Py_asdl_expr_seq_new(len, arena);
7926
0
            if (bases == NULL) goto failed;
7927
0
            for (i = 0; i < len; i++) {
7928
0
                expr_ty val;
7929
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7930
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7931
0
                    goto failed;
7932
0
                }
7933
0
                res = obj2ast_expr(state, tmp2, &val, "bases", arena);
7934
0
                _Py_LeaveRecursiveCall();
7935
0
                Py_DECREF(tmp2);
7936
0
                if (res != 0) goto failed;
7937
0
                if (len != PyList_GET_SIZE(tmp)) {
7938
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
7939
0
                    goto failed;
7940
0
                }
7941
0
                asdl_seq_SET(bases, i, val);
7942
0
            }
7943
0
            Py_CLEAR(tmp);
7944
0
        }
7945
0
        if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
7946
0
            return -1;
7947
0
        }
7948
0
        if (tmp == NULL) {
7949
0
            tmp = PyList_New(0);
7950
0
            if (tmp == NULL) {
7951
0
                return -1;
7952
0
            }
7953
0
        }
7954
0
        {
7955
0
            int res;
7956
0
            Py_ssize_t len;
7957
0
            Py_ssize_t i;
7958
0
            if (!PyList_Check(tmp)) {
7959
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %T", tmp);
7960
0
                goto failed;
7961
0
            }
7962
0
            len = PyList_GET_SIZE(tmp);
7963
0
            keywords = _Py_asdl_keyword_seq_new(len, arena);
7964
0
            if (keywords == NULL) goto failed;
7965
0
            for (i = 0; i < len; i++) {
7966
0
                keyword_ty val;
7967
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7968
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
7969
0
                    goto failed;
7970
0
                }
7971
0
                res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
7972
0
                _Py_LeaveRecursiveCall();
7973
0
                Py_DECREF(tmp2);
7974
0
                if (res != 0) goto failed;
7975
0
                if (len != PyList_GET_SIZE(tmp)) {
7976
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
7977
0
                    goto failed;
7978
0
                }
7979
0
                asdl_seq_SET(keywords, i, val);
7980
0
            }
7981
0
            Py_CLEAR(tmp);
7982
0
        }
7983
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
7984
0
            return -1;
7985
0
        }
7986
0
        if (tmp == NULL) {
7987
0
            tmp = PyList_New(0);
7988
0
            if (tmp == NULL) {
7989
0
                return -1;
7990
0
            }
7991
0
        }
7992
0
        {
7993
0
            int res;
7994
0
            Py_ssize_t len;
7995
0
            Py_ssize_t i;
7996
0
            if (!PyList_Check(tmp)) {
7997
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %T", tmp);
7998
0
                goto failed;
7999
0
            }
8000
0
            len = PyList_GET_SIZE(tmp);
8001
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8002
0
            if (body == NULL) goto failed;
8003
0
            for (i = 0; i < len; i++) {
8004
0
                stmt_ty val;
8005
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8006
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8007
0
                    goto failed;
8008
0
                }
8009
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8010
0
                _Py_LeaveRecursiveCall();
8011
0
                Py_DECREF(tmp2);
8012
0
                if (res != 0) goto failed;
8013
0
                if (len != PyList_GET_SIZE(tmp)) {
8014
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
8015
0
                    goto failed;
8016
0
                }
8017
0
                asdl_seq_SET(body, i, val);
8018
0
            }
8019
0
            Py_CLEAR(tmp);
8020
0
        }
8021
0
        if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
8022
0
            return -1;
8023
0
        }
8024
0
        if (tmp == NULL) {
8025
0
            tmp = PyList_New(0);
8026
0
            if (tmp == NULL) {
8027
0
                return -1;
8028
0
            }
8029
0
        }
8030
0
        {
8031
0
            int res;
8032
0
            Py_ssize_t len;
8033
0
            Py_ssize_t i;
8034
0
            if (!PyList_Check(tmp)) {
8035
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %T", tmp);
8036
0
                goto failed;
8037
0
            }
8038
0
            len = PyList_GET_SIZE(tmp);
8039
0
            decorator_list = _Py_asdl_expr_seq_new(len, arena);
8040
0
            if (decorator_list == NULL) goto failed;
8041
0
            for (i = 0; i < len; i++) {
8042
0
                expr_ty val;
8043
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8044
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8045
0
                    goto failed;
8046
0
                }
8047
0
                res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
8048
0
                _Py_LeaveRecursiveCall();
8049
0
                Py_DECREF(tmp2);
8050
0
                if (res != 0) goto failed;
8051
0
                if (len != PyList_GET_SIZE(tmp)) {
8052
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
8053
0
                    goto failed;
8054
0
                }
8055
0
                asdl_seq_SET(decorator_list, i, val);
8056
0
            }
8057
0
            Py_CLEAR(tmp);
8058
0
        }
8059
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
8060
0
            return -1;
8061
0
        }
8062
0
        if (tmp == NULL) {
8063
0
            tmp = PyList_New(0);
8064
0
            if (tmp == NULL) {
8065
0
                return -1;
8066
0
            }
8067
0
        }
8068
0
        {
8069
0
            int res;
8070
0
            Py_ssize_t len;
8071
0
            Py_ssize_t i;
8072
0
            if (!PyList_Check(tmp)) {
8073
0
                PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %T", tmp);
8074
0
                goto failed;
8075
0
            }
8076
0
            len = PyList_GET_SIZE(tmp);
8077
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
8078
0
            if (type_params == NULL) goto failed;
8079
0
            for (i = 0; i < len; i++) {
8080
0
                type_param_ty val;
8081
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8082
0
                if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
8083
0
                    goto failed;
8084
0
                }
8085
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
8086
0
                _Py_LeaveRecursiveCall();
8087
0
                Py_DECREF(tmp2);
8088
0
                if (res != 0) goto failed;
8089
0
                if (len != PyList_GET_SIZE(tmp)) {
8090
0
                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
8091
0
                    goto failed;
8092
0
                }
8093
0
                asdl_seq_SET(type_params, i, val);
8094
0
            }
8095
0
            Py_CLEAR(tmp);
8096
0
        }
8097
0
        *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
8098
0
                               type_params, lineno, col_offset, end_lineno,
8099
0
                               end_col_offset, arena);
8100
0
        if (*out == NULL) goto failed;
8101
0
        return 0;
8102
0
    }
8103
0
    tp = state->Return_type;
8104
0
    isinstance = PyObject_IsInstance(obj, tp);
8105
0
    if (isinstance == -1) {
8106
0
        return -1;
8107
0
    }
8108
0
    if (isinstance) {
8109
0
        expr_ty value;
8110
8111
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8112
0
            return -1;
8113
0
        }
8114
0
        if (tmp == NULL || tmp == Py_None) {
8115
0
            Py_CLEAR(tmp);
8116
0
            value = NULL;
8117
0
        }
8118
0
        else {
8119
0
            int res;
8120
0
            if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
8121
0
                goto failed;
8122
0
            }
8123
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8124
0
            _Py_LeaveRecursiveCall();
8125
0
            if (res != 0) goto failed;
8126
0
            Py_CLEAR(tmp);
8127
0
        }
8128
0
        *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
8129
0
                             end_col_offset, arena);
8130
0
        if (*out == NULL) goto failed;
8131
0
        return 0;
8132
0
    }
8133
0
    tp = state->Delete_type;
8134
0
    isinstance = PyObject_IsInstance(obj, tp);
8135
0
    if (isinstance == -1) {
8136
0
        return -1;
8137
0
    }
8138
0
    if (isinstance) {
8139
0
        asdl_expr_seq* targets;
8140
8141
0
        if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
8142
0
            return -1;
8143
0
        }
8144
0
        if (tmp == NULL) {
8145
0
            tmp = PyList_New(0);
8146
0
            if (tmp == NULL) {
8147
0
                return -1;
8148
0
            }
8149
0
        }
8150
0
        {
8151
0
            int res;
8152
0
            Py_ssize_t len;
8153
0
            Py_ssize_t i;
8154
0
            if (!PyList_Check(tmp)) {
8155
0
                PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %T", tmp);
8156
0
                goto failed;
8157
0
            }
8158
0
            len = PyList_GET_SIZE(tmp);
8159
0
            targets = _Py_asdl_expr_seq_new(len, arena);
8160
0
            if (targets == NULL) goto failed;
8161
0
            for (i = 0; i < len; i++) {
8162
0
                expr_ty val;
8163
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8164
0
                if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
8165
0
                    goto failed;
8166
0
                }
8167
0
                res = obj2ast_expr(state, tmp2, &val, "targets", arena);
8168
0
                _Py_LeaveRecursiveCall();
8169
0
                Py_DECREF(tmp2);
8170
0
                if (res != 0) goto failed;
8171
0
                if (len != PyList_GET_SIZE(tmp)) {
8172
0
                    PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
8173
0
                    goto failed;
8174
0
                }
8175
0
                asdl_seq_SET(targets, i, val);
8176
0
            }
8177
0
            Py_CLEAR(tmp);
8178
0
        }
8179
0
        *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
8180
0
                             end_col_offset, arena);
8181
0
        if (*out == NULL) goto failed;
8182
0
        return 0;
8183
0
    }
8184
0
    tp = state->Assign_type;
8185
0
    isinstance = PyObject_IsInstance(obj, tp);
8186
0
    if (isinstance == -1) {
8187
0
        return -1;
8188
0
    }
8189
0
    if (isinstance) {
8190
0
        asdl_expr_seq* targets;
8191
0
        expr_ty value;
8192
0
        string type_comment;
8193
8194
0
        if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
8195
0
            return -1;
8196
0
        }
8197
0
        if (tmp == NULL) {
8198
0
            tmp = PyList_New(0);
8199
0
            if (tmp == NULL) {
8200
0
                return -1;
8201
0
            }
8202
0
        }
8203
0
        {
8204
0
            int res;
8205
0
            Py_ssize_t len;
8206
0
            Py_ssize_t i;
8207
0
            if (!PyList_Check(tmp)) {
8208
0
                PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %T", tmp);
8209
0
                goto failed;
8210
0
            }
8211
0
            len = PyList_GET_SIZE(tmp);
8212
0
            targets = _Py_asdl_expr_seq_new(len, arena);
8213
0
            if (targets == NULL) goto failed;
8214
0
            for (i = 0; i < len; i++) {
8215
0
                expr_ty val;
8216
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8217
0
                if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8218
0
                    goto failed;
8219
0
                }
8220
0
                res = obj2ast_expr(state, tmp2, &val, "targets", arena);
8221
0
                _Py_LeaveRecursiveCall();
8222
0
                Py_DECREF(tmp2);
8223
0
                if (res != 0) goto failed;
8224
0
                if (len != PyList_GET_SIZE(tmp)) {
8225
0
                    PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
8226
0
                    goto failed;
8227
0
                }
8228
0
                asdl_seq_SET(targets, i, val);
8229
0
            }
8230
0
            Py_CLEAR(tmp);
8231
0
        }
8232
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8233
0
            return -1;
8234
0
        }
8235
0
        if (tmp == NULL) {
8236
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
8237
0
            return -1;
8238
0
        }
8239
0
        else {
8240
0
            int res;
8241
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8242
0
                goto failed;
8243
0
            }
8244
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8245
0
            _Py_LeaveRecursiveCall();
8246
0
            if (res != 0) goto failed;
8247
0
            Py_CLEAR(tmp);
8248
0
        }
8249
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8250
0
            return -1;
8251
0
        }
8252
0
        if (tmp == NULL || tmp == Py_None) {
8253
0
            Py_CLEAR(tmp);
8254
0
            type_comment = NULL;
8255
0
        }
8256
0
        else {
8257
0
            int res;
8258
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
8259
0
                goto failed;
8260
0
            }
8261
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8262
0
                                 arena);
8263
0
            _Py_LeaveRecursiveCall();
8264
0
            if (res != 0) goto failed;
8265
0
            Py_CLEAR(tmp);
8266
0
        }
8267
0
        *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
8268
0
                             end_lineno, end_col_offset, arena);
8269
0
        if (*out == NULL) goto failed;
8270
0
        return 0;
8271
0
    }
8272
0
    tp = state->TypeAlias_type;
8273
0
    isinstance = PyObject_IsInstance(obj, tp);
8274
0
    if (isinstance == -1) {
8275
0
        return -1;
8276
0
    }
8277
0
    if (isinstance) {
8278
0
        expr_ty name;
8279
0
        asdl_type_param_seq* type_params;
8280
0
        expr_ty value;
8281
8282
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
8283
0
            return -1;
8284
0
        }
8285
0
        if (tmp == NULL) {
8286
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
8287
0
            return -1;
8288
0
        }
8289
0
        else {
8290
0
            int res;
8291
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8292
0
                goto failed;
8293
0
            }
8294
0
            res = obj2ast_expr(state, tmp, &name, "name", arena);
8295
0
            _Py_LeaveRecursiveCall();
8296
0
            if (res != 0) goto failed;
8297
0
            Py_CLEAR(tmp);
8298
0
        }
8299
0
        if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
8300
0
            return -1;
8301
0
        }
8302
0
        if (tmp == NULL) {
8303
0
            tmp = PyList_New(0);
8304
0
            if (tmp == NULL) {
8305
0
                return -1;
8306
0
            }
8307
0
        }
8308
0
        {
8309
0
            int res;
8310
0
            Py_ssize_t len;
8311
0
            Py_ssize_t i;
8312
0
            if (!PyList_Check(tmp)) {
8313
0
                PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %T", tmp);
8314
0
                goto failed;
8315
0
            }
8316
0
            len = PyList_GET_SIZE(tmp);
8317
0
            type_params = _Py_asdl_type_param_seq_new(len, arena);
8318
0
            if (type_params == NULL) goto failed;
8319
0
            for (i = 0; i < len; i++) {
8320
0
                type_param_ty val;
8321
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8322
0
                if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8323
0
                    goto failed;
8324
0
                }
8325
0
                res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
8326
0
                _Py_LeaveRecursiveCall();
8327
0
                Py_DECREF(tmp2);
8328
0
                if (res != 0) goto failed;
8329
0
                if (len != PyList_GET_SIZE(tmp)) {
8330
0
                    PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
8331
0
                    goto failed;
8332
0
                }
8333
0
                asdl_seq_SET(type_params, i, val);
8334
0
            }
8335
0
            Py_CLEAR(tmp);
8336
0
        }
8337
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8338
0
            return -1;
8339
0
        }
8340
0
        if (tmp == NULL) {
8341
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
8342
0
            return -1;
8343
0
        }
8344
0
        else {
8345
0
            int res;
8346
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
8347
0
                goto failed;
8348
0
            }
8349
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8350
0
            _Py_LeaveRecursiveCall();
8351
0
            if (res != 0) goto failed;
8352
0
            Py_CLEAR(tmp);
8353
0
        }
8354
0
        *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
8355
0
                                end_lineno, end_col_offset, arena);
8356
0
        if (*out == NULL) goto failed;
8357
0
        return 0;
8358
0
    }
8359
0
    tp = state->AugAssign_type;
8360
0
    isinstance = PyObject_IsInstance(obj, tp);
8361
0
    if (isinstance == -1) {
8362
0
        return -1;
8363
0
    }
8364
0
    if (isinstance) {
8365
0
        expr_ty target;
8366
0
        operator_ty op;
8367
0
        expr_ty value;
8368
8369
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8370
0
            return -1;
8371
0
        }
8372
0
        if (tmp == NULL) {
8373
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
8374
0
            return -1;
8375
0
        }
8376
0
        else {
8377
0
            int res;
8378
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8379
0
                goto failed;
8380
0
            }
8381
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8382
0
            _Py_LeaveRecursiveCall();
8383
0
            if (res != 0) goto failed;
8384
0
            Py_CLEAR(tmp);
8385
0
        }
8386
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
8387
0
            return -1;
8388
0
        }
8389
0
        if (tmp == NULL) {
8390
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
8391
0
            return -1;
8392
0
        }
8393
0
        else {
8394
0
            int res;
8395
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8396
0
                goto failed;
8397
0
            }
8398
0
            res = obj2ast_operator(state, tmp, &op, "op", arena);
8399
0
            _Py_LeaveRecursiveCall();
8400
0
            if (res != 0) goto failed;
8401
0
            Py_CLEAR(tmp);
8402
0
        }
8403
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8404
0
            return -1;
8405
0
        }
8406
0
        if (tmp == NULL) {
8407
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
8408
0
            return -1;
8409
0
        }
8410
0
        else {
8411
0
            int res;
8412
0
            if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
8413
0
                goto failed;
8414
0
            }
8415
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8416
0
            _Py_LeaveRecursiveCall();
8417
0
            if (res != 0) goto failed;
8418
0
            Py_CLEAR(tmp);
8419
0
        }
8420
0
        *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
8421
0
                                end_lineno, end_col_offset, arena);
8422
0
        if (*out == NULL) goto failed;
8423
0
        return 0;
8424
0
    }
8425
0
    tp = state->AnnAssign_type;
8426
0
    isinstance = PyObject_IsInstance(obj, tp);
8427
0
    if (isinstance == -1) {
8428
0
        return -1;
8429
0
    }
8430
0
    if (isinstance) {
8431
0
        expr_ty target;
8432
0
        expr_ty annotation;
8433
0
        expr_ty value;
8434
0
        int simple;
8435
8436
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8437
0
            return -1;
8438
0
        }
8439
0
        if (tmp == NULL) {
8440
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
8441
0
            return -1;
8442
0
        }
8443
0
        else {
8444
0
            int res;
8445
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8446
0
                goto failed;
8447
0
            }
8448
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8449
0
            _Py_LeaveRecursiveCall();
8450
0
            if (res != 0) goto failed;
8451
0
            Py_CLEAR(tmp);
8452
0
        }
8453
0
        if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
8454
0
            return -1;
8455
0
        }
8456
0
        if (tmp == NULL) {
8457
0
            PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
8458
0
            return -1;
8459
0
        }
8460
0
        else {
8461
0
            int res;
8462
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8463
0
                goto failed;
8464
0
            }
8465
0
            res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
8466
0
            _Py_LeaveRecursiveCall();
8467
0
            if (res != 0) goto failed;
8468
0
            Py_CLEAR(tmp);
8469
0
        }
8470
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
8471
0
            return -1;
8472
0
        }
8473
0
        if (tmp == NULL || tmp == Py_None) {
8474
0
            Py_CLEAR(tmp);
8475
0
            value = NULL;
8476
0
        }
8477
0
        else {
8478
0
            int res;
8479
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8480
0
                goto failed;
8481
0
            }
8482
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
8483
0
            _Py_LeaveRecursiveCall();
8484
0
            if (res != 0) goto failed;
8485
0
            Py_CLEAR(tmp);
8486
0
        }
8487
0
        if (PyObject_GetOptionalAttr(obj, state->simple, &tmp) < 0) {
8488
0
            return -1;
8489
0
        }
8490
0
        if (tmp == NULL) {
8491
0
            PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
8492
0
            return -1;
8493
0
        }
8494
0
        else {
8495
0
            int res;
8496
0
            if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
8497
0
                goto failed;
8498
0
            }
8499
0
            res = obj2ast_int(state, tmp, &simple, "simple", arena);
8500
0
            _Py_LeaveRecursiveCall();
8501
0
            if (res != 0) goto failed;
8502
0
            Py_CLEAR(tmp);
8503
0
        }
8504
0
        *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
8505
0
                                col_offset, end_lineno, end_col_offset, arena);
8506
0
        if (*out == NULL) goto failed;
8507
0
        return 0;
8508
0
    }
8509
0
    tp = state->For_type;
8510
0
    isinstance = PyObject_IsInstance(obj, tp);
8511
0
    if (isinstance == -1) {
8512
0
        return -1;
8513
0
    }
8514
0
    if (isinstance) {
8515
0
        expr_ty target;
8516
0
        expr_ty iter;
8517
0
        asdl_stmt_seq* body;
8518
0
        asdl_stmt_seq* orelse;
8519
0
        string type_comment;
8520
8521
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8522
0
            return -1;
8523
0
        }
8524
0
        if (tmp == NULL) {
8525
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
8526
0
            return -1;
8527
0
        }
8528
0
        else {
8529
0
            int res;
8530
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8531
0
                goto failed;
8532
0
            }
8533
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8534
0
            _Py_LeaveRecursiveCall();
8535
0
            if (res != 0) goto failed;
8536
0
            Py_CLEAR(tmp);
8537
0
        }
8538
0
        if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
8539
0
            return -1;
8540
0
        }
8541
0
        if (tmp == NULL) {
8542
0
            PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
8543
0
            return -1;
8544
0
        }
8545
0
        else {
8546
0
            int res;
8547
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8548
0
                goto failed;
8549
0
            }
8550
0
            res = obj2ast_expr(state, tmp, &iter, "iter", arena);
8551
0
            _Py_LeaveRecursiveCall();
8552
0
            if (res != 0) goto failed;
8553
0
            Py_CLEAR(tmp);
8554
0
        }
8555
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8556
0
            return -1;
8557
0
        }
8558
0
        if (tmp == NULL) {
8559
0
            tmp = PyList_New(0);
8560
0
            if (tmp == NULL) {
8561
0
                return -1;
8562
0
            }
8563
0
        }
8564
0
        {
8565
0
            int res;
8566
0
            Py_ssize_t len;
8567
0
            Py_ssize_t i;
8568
0
            if (!PyList_Check(tmp)) {
8569
0
                PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %T", tmp);
8570
0
                goto failed;
8571
0
            }
8572
0
            len = PyList_GET_SIZE(tmp);
8573
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8574
0
            if (body == NULL) goto failed;
8575
0
            for (i = 0; i < len; i++) {
8576
0
                stmt_ty val;
8577
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8578
0
                if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8579
0
                    goto failed;
8580
0
                }
8581
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8582
0
                _Py_LeaveRecursiveCall();
8583
0
                Py_DECREF(tmp2);
8584
0
                if (res != 0) goto failed;
8585
0
                if (len != PyList_GET_SIZE(tmp)) {
8586
0
                    PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
8587
0
                    goto failed;
8588
0
                }
8589
0
                asdl_seq_SET(body, i, val);
8590
0
            }
8591
0
            Py_CLEAR(tmp);
8592
0
        }
8593
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8594
0
            return -1;
8595
0
        }
8596
0
        if (tmp == NULL) {
8597
0
            tmp = PyList_New(0);
8598
0
            if (tmp == NULL) {
8599
0
                return -1;
8600
0
            }
8601
0
        }
8602
0
        {
8603
0
            int res;
8604
0
            Py_ssize_t len;
8605
0
            Py_ssize_t i;
8606
0
            if (!PyList_Check(tmp)) {
8607
0
                PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %T", tmp);
8608
0
                goto failed;
8609
0
            }
8610
0
            len = PyList_GET_SIZE(tmp);
8611
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8612
0
            if (orelse == NULL) goto failed;
8613
0
            for (i = 0; i < len; i++) {
8614
0
                stmt_ty val;
8615
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8616
0
                if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8617
0
                    goto failed;
8618
0
                }
8619
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8620
0
                _Py_LeaveRecursiveCall();
8621
0
                Py_DECREF(tmp2);
8622
0
                if (res != 0) goto failed;
8623
0
                if (len != PyList_GET_SIZE(tmp)) {
8624
0
                    PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
8625
0
                    goto failed;
8626
0
                }
8627
0
                asdl_seq_SET(orelse, i, val);
8628
0
            }
8629
0
            Py_CLEAR(tmp);
8630
0
        }
8631
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8632
0
            return -1;
8633
0
        }
8634
0
        if (tmp == NULL || tmp == Py_None) {
8635
0
            Py_CLEAR(tmp);
8636
0
            type_comment = NULL;
8637
0
        }
8638
0
        else {
8639
0
            int res;
8640
0
            if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
8641
0
                goto failed;
8642
0
            }
8643
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8644
0
                                 arena);
8645
0
            _Py_LeaveRecursiveCall();
8646
0
            if (res != 0) goto failed;
8647
0
            Py_CLEAR(tmp);
8648
0
        }
8649
0
        *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
8650
0
                          col_offset, end_lineno, end_col_offset, arena);
8651
0
        if (*out == NULL) goto failed;
8652
0
        return 0;
8653
0
    }
8654
0
    tp = state->AsyncFor_type;
8655
0
    isinstance = PyObject_IsInstance(obj, tp);
8656
0
    if (isinstance == -1) {
8657
0
        return -1;
8658
0
    }
8659
0
    if (isinstance) {
8660
0
        expr_ty target;
8661
0
        expr_ty iter;
8662
0
        asdl_stmt_seq* body;
8663
0
        asdl_stmt_seq* orelse;
8664
0
        string type_comment;
8665
8666
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
8667
0
            return -1;
8668
0
        }
8669
0
        if (tmp == NULL) {
8670
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
8671
0
            return -1;
8672
0
        }
8673
0
        else {
8674
0
            int res;
8675
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8676
0
                goto failed;
8677
0
            }
8678
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
8679
0
            _Py_LeaveRecursiveCall();
8680
0
            if (res != 0) goto failed;
8681
0
            Py_CLEAR(tmp);
8682
0
        }
8683
0
        if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
8684
0
            return -1;
8685
0
        }
8686
0
        if (tmp == NULL) {
8687
0
            PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
8688
0
            return -1;
8689
0
        }
8690
0
        else {
8691
0
            int res;
8692
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8693
0
                goto failed;
8694
0
            }
8695
0
            res = obj2ast_expr(state, tmp, &iter, "iter", arena);
8696
0
            _Py_LeaveRecursiveCall();
8697
0
            if (res != 0) goto failed;
8698
0
            Py_CLEAR(tmp);
8699
0
        }
8700
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8701
0
            return -1;
8702
0
        }
8703
0
        if (tmp == NULL) {
8704
0
            tmp = PyList_New(0);
8705
0
            if (tmp == NULL) {
8706
0
                return -1;
8707
0
            }
8708
0
        }
8709
0
        {
8710
0
            int res;
8711
0
            Py_ssize_t len;
8712
0
            Py_ssize_t i;
8713
0
            if (!PyList_Check(tmp)) {
8714
0
                PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %T", tmp);
8715
0
                goto failed;
8716
0
            }
8717
0
            len = PyList_GET_SIZE(tmp);
8718
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8719
0
            if (body == NULL) goto failed;
8720
0
            for (i = 0; i < len; i++) {
8721
0
                stmt_ty val;
8722
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8723
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8724
0
                    goto failed;
8725
0
                }
8726
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8727
0
                _Py_LeaveRecursiveCall();
8728
0
                Py_DECREF(tmp2);
8729
0
                if (res != 0) goto failed;
8730
0
                if (len != PyList_GET_SIZE(tmp)) {
8731
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
8732
0
                    goto failed;
8733
0
                }
8734
0
                asdl_seq_SET(body, i, val);
8735
0
            }
8736
0
            Py_CLEAR(tmp);
8737
0
        }
8738
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8739
0
            return -1;
8740
0
        }
8741
0
        if (tmp == NULL) {
8742
0
            tmp = PyList_New(0);
8743
0
            if (tmp == NULL) {
8744
0
                return -1;
8745
0
            }
8746
0
        }
8747
0
        {
8748
0
            int res;
8749
0
            Py_ssize_t len;
8750
0
            Py_ssize_t i;
8751
0
            if (!PyList_Check(tmp)) {
8752
0
                PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %T", tmp);
8753
0
                goto failed;
8754
0
            }
8755
0
            len = PyList_GET_SIZE(tmp);
8756
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8757
0
            if (orelse == NULL) goto failed;
8758
0
            for (i = 0; i < len; i++) {
8759
0
                stmt_ty val;
8760
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8761
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8762
0
                    goto failed;
8763
0
                }
8764
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8765
0
                _Py_LeaveRecursiveCall();
8766
0
                Py_DECREF(tmp2);
8767
0
                if (res != 0) goto failed;
8768
0
                if (len != PyList_GET_SIZE(tmp)) {
8769
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
8770
0
                    goto failed;
8771
0
                }
8772
0
                asdl_seq_SET(orelse, i, val);
8773
0
            }
8774
0
            Py_CLEAR(tmp);
8775
0
        }
8776
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
8777
0
            return -1;
8778
0
        }
8779
0
        if (tmp == NULL || tmp == Py_None) {
8780
0
            Py_CLEAR(tmp);
8781
0
            type_comment = NULL;
8782
0
        }
8783
0
        else {
8784
0
            int res;
8785
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
8786
0
                goto failed;
8787
0
            }
8788
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
8789
0
                                 arena);
8790
0
            _Py_LeaveRecursiveCall();
8791
0
            if (res != 0) goto failed;
8792
0
            Py_CLEAR(tmp);
8793
0
        }
8794
0
        *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
8795
0
                               lineno, col_offset, end_lineno, end_col_offset,
8796
0
                               arena);
8797
0
        if (*out == NULL) goto failed;
8798
0
        return 0;
8799
0
    }
8800
0
    tp = state->While_type;
8801
0
    isinstance = PyObject_IsInstance(obj, tp);
8802
0
    if (isinstance == -1) {
8803
0
        return -1;
8804
0
    }
8805
0
    if (isinstance) {
8806
0
        expr_ty test;
8807
0
        asdl_stmt_seq* body;
8808
0
        asdl_stmt_seq* orelse;
8809
8810
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
8811
0
            return -1;
8812
0
        }
8813
0
        if (tmp == NULL) {
8814
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
8815
0
            return -1;
8816
0
        }
8817
0
        else {
8818
0
            int res;
8819
0
            if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8820
0
                goto failed;
8821
0
            }
8822
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
8823
0
            _Py_LeaveRecursiveCall();
8824
0
            if (res != 0) goto failed;
8825
0
            Py_CLEAR(tmp);
8826
0
        }
8827
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8828
0
            return -1;
8829
0
        }
8830
0
        if (tmp == NULL) {
8831
0
            tmp = PyList_New(0);
8832
0
            if (tmp == NULL) {
8833
0
                return -1;
8834
0
            }
8835
0
        }
8836
0
        {
8837
0
            int res;
8838
0
            Py_ssize_t len;
8839
0
            Py_ssize_t i;
8840
0
            if (!PyList_Check(tmp)) {
8841
0
                PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %T", tmp);
8842
0
                goto failed;
8843
0
            }
8844
0
            len = PyList_GET_SIZE(tmp);
8845
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8846
0
            if (body == NULL) goto failed;
8847
0
            for (i = 0; i < len; i++) {
8848
0
                stmt_ty val;
8849
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8850
0
                if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8851
0
                    goto failed;
8852
0
                }
8853
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8854
0
                _Py_LeaveRecursiveCall();
8855
0
                Py_DECREF(tmp2);
8856
0
                if (res != 0) goto failed;
8857
0
                if (len != PyList_GET_SIZE(tmp)) {
8858
0
                    PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
8859
0
                    goto failed;
8860
0
                }
8861
0
                asdl_seq_SET(body, i, val);
8862
0
            }
8863
0
            Py_CLEAR(tmp);
8864
0
        }
8865
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8866
0
            return -1;
8867
0
        }
8868
0
        if (tmp == NULL) {
8869
0
            tmp = PyList_New(0);
8870
0
            if (tmp == NULL) {
8871
0
                return -1;
8872
0
            }
8873
0
        }
8874
0
        {
8875
0
            int res;
8876
0
            Py_ssize_t len;
8877
0
            Py_ssize_t i;
8878
0
            if (!PyList_Check(tmp)) {
8879
0
                PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %T", tmp);
8880
0
                goto failed;
8881
0
            }
8882
0
            len = PyList_GET_SIZE(tmp);
8883
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8884
0
            if (orelse == NULL) goto failed;
8885
0
            for (i = 0; i < len; i++) {
8886
0
                stmt_ty val;
8887
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8888
0
                if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
8889
0
                    goto failed;
8890
0
                }
8891
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
8892
0
                _Py_LeaveRecursiveCall();
8893
0
                Py_DECREF(tmp2);
8894
0
                if (res != 0) goto failed;
8895
0
                if (len != PyList_GET_SIZE(tmp)) {
8896
0
                    PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
8897
0
                    goto failed;
8898
0
                }
8899
0
                asdl_seq_SET(orelse, i, val);
8900
0
            }
8901
0
            Py_CLEAR(tmp);
8902
0
        }
8903
0
        *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
8904
0
                            end_col_offset, arena);
8905
0
        if (*out == NULL) goto failed;
8906
0
        return 0;
8907
0
    }
8908
0
    tp = state->If_type;
8909
0
    isinstance = PyObject_IsInstance(obj, tp);
8910
0
    if (isinstance == -1) {
8911
0
        return -1;
8912
0
    }
8913
0
    if (isinstance) {
8914
0
        expr_ty test;
8915
0
        asdl_stmt_seq* body;
8916
0
        asdl_stmt_seq* orelse;
8917
8918
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
8919
0
            return -1;
8920
0
        }
8921
0
        if (tmp == NULL) {
8922
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
8923
0
            return -1;
8924
0
        }
8925
0
        else {
8926
0
            int res;
8927
0
            if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
8928
0
                goto failed;
8929
0
            }
8930
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
8931
0
            _Py_LeaveRecursiveCall();
8932
0
            if (res != 0) goto failed;
8933
0
            Py_CLEAR(tmp);
8934
0
        }
8935
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
8936
0
            return -1;
8937
0
        }
8938
0
        if (tmp == NULL) {
8939
0
            tmp = PyList_New(0);
8940
0
            if (tmp == NULL) {
8941
0
                return -1;
8942
0
            }
8943
0
        }
8944
0
        {
8945
0
            int res;
8946
0
            Py_ssize_t len;
8947
0
            Py_ssize_t i;
8948
0
            if (!PyList_Check(tmp)) {
8949
0
                PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %T", tmp);
8950
0
                goto failed;
8951
0
            }
8952
0
            len = PyList_GET_SIZE(tmp);
8953
0
            body = _Py_asdl_stmt_seq_new(len, arena);
8954
0
            if (body == NULL) goto failed;
8955
0
            for (i = 0; i < len; i++) {
8956
0
                stmt_ty val;
8957
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8958
0
                if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
8959
0
                    goto failed;
8960
0
                }
8961
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
8962
0
                _Py_LeaveRecursiveCall();
8963
0
                Py_DECREF(tmp2);
8964
0
                if (res != 0) goto failed;
8965
0
                if (len != PyList_GET_SIZE(tmp)) {
8966
0
                    PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
8967
0
                    goto failed;
8968
0
                }
8969
0
                asdl_seq_SET(body, i, val);
8970
0
            }
8971
0
            Py_CLEAR(tmp);
8972
0
        }
8973
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
8974
0
            return -1;
8975
0
        }
8976
0
        if (tmp == NULL) {
8977
0
            tmp = PyList_New(0);
8978
0
            if (tmp == NULL) {
8979
0
                return -1;
8980
0
            }
8981
0
        }
8982
0
        {
8983
0
            int res;
8984
0
            Py_ssize_t len;
8985
0
            Py_ssize_t i;
8986
0
            if (!PyList_Check(tmp)) {
8987
0
                PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %T", tmp);
8988
0
                goto failed;
8989
0
            }
8990
0
            len = PyList_GET_SIZE(tmp);
8991
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
8992
0
            if (orelse == NULL) goto failed;
8993
0
            for (i = 0; i < len; i++) {
8994
0
                stmt_ty val;
8995
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8996
0
                if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
8997
0
                    goto failed;
8998
0
                }
8999
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9000
0
                _Py_LeaveRecursiveCall();
9001
0
                Py_DECREF(tmp2);
9002
0
                if (res != 0) goto failed;
9003
0
                if (len != PyList_GET_SIZE(tmp)) {
9004
0
                    PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
9005
0
                    goto failed;
9006
0
                }
9007
0
                asdl_seq_SET(orelse, i, val);
9008
0
            }
9009
0
            Py_CLEAR(tmp);
9010
0
        }
9011
0
        *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
9012
0
                         end_col_offset, arena);
9013
0
        if (*out == NULL) goto failed;
9014
0
        return 0;
9015
0
    }
9016
0
    tp = state->With_type;
9017
0
    isinstance = PyObject_IsInstance(obj, tp);
9018
0
    if (isinstance == -1) {
9019
0
        return -1;
9020
0
    }
9021
0
    if (isinstance) {
9022
0
        asdl_withitem_seq* items;
9023
0
        asdl_stmt_seq* body;
9024
0
        string type_comment;
9025
9026
0
        if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
9027
0
            return -1;
9028
0
        }
9029
0
        if (tmp == NULL) {
9030
0
            tmp = PyList_New(0);
9031
0
            if (tmp == NULL) {
9032
0
                return -1;
9033
0
            }
9034
0
        }
9035
0
        {
9036
0
            int res;
9037
0
            Py_ssize_t len;
9038
0
            Py_ssize_t i;
9039
0
            if (!PyList_Check(tmp)) {
9040
0
                PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %T", tmp);
9041
0
                goto failed;
9042
0
            }
9043
0
            len = PyList_GET_SIZE(tmp);
9044
0
            items = _Py_asdl_withitem_seq_new(len, arena);
9045
0
            if (items == NULL) goto failed;
9046
0
            for (i = 0; i < len; i++) {
9047
0
                withitem_ty val;
9048
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9049
0
                if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9050
0
                    goto failed;
9051
0
                }
9052
0
                res = obj2ast_withitem(state, tmp2, &val, "items", arena);
9053
0
                _Py_LeaveRecursiveCall();
9054
0
                Py_DECREF(tmp2);
9055
0
                if (res != 0) goto failed;
9056
0
                if (len != PyList_GET_SIZE(tmp)) {
9057
0
                    PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
9058
0
                    goto failed;
9059
0
                }
9060
0
                asdl_seq_SET(items, i, val);
9061
0
            }
9062
0
            Py_CLEAR(tmp);
9063
0
        }
9064
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9065
0
            return -1;
9066
0
        }
9067
0
        if (tmp == NULL) {
9068
0
            tmp = PyList_New(0);
9069
0
            if (tmp == NULL) {
9070
0
                return -1;
9071
0
            }
9072
0
        }
9073
0
        {
9074
0
            int res;
9075
0
            Py_ssize_t len;
9076
0
            Py_ssize_t i;
9077
0
            if (!PyList_Check(tmp)) {
9078
0
                PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %T", tmp);
9079
0
                goto failed;
9080
0
            }
9081
0
            len = PyList_GET_SIZE(tmp);
9082
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9083
0
            if (body == NULL) goto failed;
9084
0
            for (i = 0; i < len; i++) {
9085
0
                stmt_ty val;
9086
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9087
0
                if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9088
0
                    goto failed;
9089
0
                }
9090
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9091
0
                _Py_LeaveRecursiveCall();
9092
0
                Py_DECREF(tmp2);
9093
0
                if (res != 0) goto failed;
9094
0
                if (len != PyList_GET_SIZE(tmp)) {
9095
0
                    PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
9096
0
                    goto failed;
9097
0
                }
9098
0
                asdl_seq_SET(body, i, val);
9099
0
            }
9100
0
            Py_CLEAR(tmp);
9101
0
        }
9102
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
9103
0
            return -1;
9104
0
        }
9105
0
        if (tmp == NULL || tmp == Py_None) {
9106
0
            Py_CLEAR(tmp);
9107
0
            type_comment = NULL;
9108
0
        }
9109
0
        else {
9110
0
            int res;
9111
0
            if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
9112
0
                goto failed;
9113
0
            }
9114
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
9115
0
                                 arena);
9116
0
            _Py_LeaveRecursiveCall();
9117
0
            if (res != 0) goto failed;
9118
0
            Py_CLEAR(tmp);
9119
0
        }
9120
0
        *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
9121
0
                           end_lineno, end_col_offset, arena);
9122
0
        if (*out == NULL) goto failed;
9123
0
        return 0;
9124
0
    }
9125
0
    tp = state->AsyncWith_type;
9126
0
    isinstance = PyObject_IsInstance(obj, tp);
9127
0
    if (isinstance == -1) {
9128
0
        return -1;
9129
0
    }
9130
0
    if (isinstance) {
9131
0
        asdl_withitem_seq* items;
9132
0
        asdl_stmt_seq* body;
9133
0
        string type_comment;
9134
9135
0
        if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
9136
0
            return -1;
9137
0
        }
9138
0
        if (tmp == NULL) {
9139
0
            tmp = PyList_New(0);
9140
0
            if (tmp == NULL) {
9141
0
                return -1;
9142
0
            }
9143
0
        }
9144
0
        {
9145
0
            int res;
9146
0
            Py_ssize_t len;
9147
0
            Py_ssize_t i;
9148
0
            if (!PyList_Check(tmp)) {
9149
0
                PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %T", tmp);
9150
0
                goto failed;
9151
0
            }
9152
0
            len = PyList_GET_SIZE(tmp);
9153
0
            items = _Py_asdl_withitem_seq_new(len, arena);
9154
0
            if (items == NULL) goto failed;
9155
0
            for (i = 0; i < len; i++) {
9156
0
                withitem_ty val;
9157
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9158
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9159
0
                    goto failed;
9160
0
                }
9161
0
                res = obj2ast_withitem(state, tmp2, &val, "items", arena);
9162
0
                _Py_LeaveRecursiveCall();
9163
0
                Py_DECREF(tmp2);
9164
0
                if (res != 0) goto failed;
9165
0
                if (len != PyList_GET_SIZE(tmp)) {
9166
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
9167
0
                    goto failed;
9168
0
                }
9169
0
                asdl_seq_SET(items, i, val);
9170
0
            }
9171
0
            Py_CLEAR(tmp);
9172
0
        }
9173
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9174
0
            return -1;
9175
0
        }
9176
0
        if (tmp == NULL) {
9177
0
            tmp = PyList_New(0);
9178
0
            if (tmp == NULL) {
9179
0
                return -1;
9180
0
            }
9181
0
        }
9182
0
        {
9183
0
            int res;
9184
0
            Py_ssize_t len;
9185
0
            Py_ssize_t i;
9186
0
            if (!PyList_Check(tmp)) {
9187
0
                PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %T", tmp);
9188
0
                goto failed;
9189
0
            }
9190
0
            len = PyList_GET_SIZE(tmp);
9191
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9192
0
            if (body == NULL) goto failed;
9193
0
            for (i = 0; i < len; i++) {
9194
0
                stmt_ty val;
9195
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9196
0
                if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9197
0
                    goto failed;
9198
0
                }
9199
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9200
0
                _Py_LeaveRecursiveCall();
9201
0
                Py_DECREF(tmp2);
9202
0
                if (res != 0) goto failed;
9203
0
                if (len != PyList_GET_SIZE(tmp)) {
9204
0
                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
9205
0
                    goto failed;
9206
0
                }
9207
0
                asdl_seq_SET(body, i, val);
9208
0
            }
9209
0
            Py_CLEAR(tmp);
9210
0
        }
9211
0
        if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
9212
0
            return -1;
9213
0
        }
9214
0
        if (tmp == NULL || tmp == Py_None) {
9215
0
            Py_CLEAR(tmp);
9216
0
            type_comment = NULL;
9217
0
        }
9218
0
        else {
9219
0
            int res;
9220
0
            if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
9221
0
                goto failed;
9222
0
            }
9223
0
            res = obj2ast_string(state, tmp, &type_comment, "type_comment",
9224
0
                                 arena);
9225
0
            _Py_LeaveRecursiveCall();
9226
0
            if (res != 0) goto failed;
9227
0
            Py_CLEAR(tmp);
9228
0
        }
9229
0
        *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
9230
0
                                end_lineno, end_col_offset, arena);
9231
0
        if (*out == NULL) goto failed;
9232
0
        return 0;
9233
0
    }
9234
0
    tp = state->Match_type;
9235
0
    isinstance = PyObject_IsInstance(obj, tp);
9236
0
    if (isinstance == -1) {
9237
0
        return -1;
9238
0
    }
9239
0
    if (isinstance) {
9240
0
        expr_ty subject;
9241
0
        asdl_match_case_seq* cases;
9242
9243
0
        if (PyObject_GetOptionalAttr(obj, state->subject, &tmp) < 0) {
9244
0
            return -1;
9245
0
        }
9246
0
        if (tmp == NULL) {
9247
0
            PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
9248
0
            return -1;
9249
0
        }
9250
0
        else {
9251
0
            int res;
9252
0
            if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
9253
0
                goto failed;
9254
0
            }
9255
0
            res = obj2ast_expr(state, tmp, &subject, "subject", arena);
9256
0
            _Py_LeaveRecursiveCall();
9257
0
            if (res != 0) goto failed;
9258
0
            Py_CLEAR(tmp);
9259
0
        }
9260
0
        if (PyObject_GetOptionalAttr(obj, state->cases, &tmp) < 0) {
9261
0
            return -1;
9262
0
        }
9263
0
        if (tmp == NULL) {
9264
0
            tmp = PyList_New(0);
9265
0
            if (tmp == NULL) {
9266
0
                return -1;
9267
0
            }
9268
0
        }
9269
0
        {
9270
0
            int res;
9271
0
            Py_ssize_t len;
9272
0
            Py_ssize_t i;
9273
0
            if (!PyList_Check(tmp)) {
9274
0
                PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %T", tmp);
9275
0
                goto failed;
9276
0
            }
9277
0
            len = PyList_GET_SIZE(tmp);
9278
0
            cases = _Py_asdl_match_case_seq_new(len, arena);
9279
0
            if (cases == NULL) goto failed;
9280
0
            for (i = 0; i < len; i++) {
9281
0
                match_case_ty val;
9282
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9283
0
                if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
9284
0
                    goto failed;
9285
0
                }
9286
0
                res = obj2ast_match_case(state, tmp2, &val, "cases", arena);
9287
0
                _Py_LeaveRecursiveCall();
9288
0
                Py_DECREF(tmp2);
9289
0
                if (res != 0) goto failed;
9290
0
                if (len != PyList_GET_SIZE(tmp)) {
9291
0
                    PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
9292
0
                    goto failed;
9293
0
                }
9294
0
                asdl_seq_SET(cases, i, val);
9295
0
            }
9296
0
            Py_CLEAR(tmp);
9297
0
        }
9298
0
        *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
9299
0
                            end_col_offset, arena);
9300
0
        if (*out == NULL) goto failed;
9301
0
        return 0;
9302
0
    }
9303
0
    tp = state->Raise_type;
9304
0
    isinstance = PyObject_IsInstance(obj, tp);
9305
0
    if (isinstance == -1) {
9306
0
        return -1;
9307
0
    }
9308
0
    if (isinstance) {
9309
0
        expr_ty exc;
9310
0
        expr_ty cause;
9311
9312
0
        if (PyObject_GetOptionalAttr(obj, state->exc, &tmp) < 0) {
9313
0
            return -1;
9314
0
        }
9315
0
        if (tmp == NULL || tmp == Py_None) {
9316
0
            Py_CLEAR(tmp);
9317
0
            exc = NULL;
9318
0
        }
9319
0
        else {
9320
0
            int res;
9321
0
            if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
9322
0
                goto failed;
9323
0
            }
9324
0
            res = obj2ast_expr(state, tmp, &exc, "exc", arena);
9325
0
            _Py_LeaveRecursiveCall();
9326
0
            if (res != 0) goto failed;
9327
0
            Py_CLEAR(tmp);
9328
0
        }
9329
0
        if (PyObject_GetOptionalAttr(obj, state->cause, &tmp) < 0) {
9330
0
            return -1;
9331
0
        }
9332
0
        if (tmp == NULL || tmp == Py_None) {
9333
0
            Py_CLEAR(tmp);
9334
0
            cause = NULL;
9335
0
        }
9336
0
        else {
9337
0
            int res;
9338
0
            if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
9339
0
                goto failed;
9340
0
            }
9341
0
            res = obj2ast_expr(state, tmp, &cause, "cause", arena);
9342
0
            _Py_LeaveRecursiveCall();
9343
0
            if (res != 0) goto failed;
9344
0
            Py_CLEAR(tmp);
9345
0
        }
9346
0
        *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
9347
0
                            end_col_offset, arena);
9348
0
        if (*out == NULL) goto failed;
9349
0
        return 0;
9350
0
    }
9351
0
    tp = state->Try_type;
9352
0
    isinstance = PyObject_IsInstance(obj, tp);
9353
0
    if (isinstance == -1) {
9354
0
        return -1;
9355
0
    }
9356
0
    if (isinstance) {
9357
0
        asdl_stmt_seq* body;
9358
0
        asdl_excepthandler_seq* handlers;
9359
0
        asdl_stmt_seq* orelse;
9360
0
        asdl_stmt_seq* finalbody;
9361
9362
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9363
0
            return -1;
9364
0
        }
9365
0
        if (tmp == NULL) {
9366
0
            tmp = PyList_New(0);
9367
0
            if (tmp == NULL) {
9368
0
                return -1;
9369
0
            }
9370
0
        }
9371
0
        {
9372
0
            int res;
9373
0
            Py_ssize_t len;
9374
0
            Py_ssize_t i;
9375
0
            if (!PyList_Check(tmp)) {
9376
0
                PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %T", tmp);
9377
0
                goto failed;
9378
0
            }
9379
0
            len = PyList_GET_SIZE(tmp);
9380
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9381
0
            if (body == NULL) goto failed;
9382
0
            for (i = 0; i < len; i++) {
9383
0
                stmt_ty val;
9384
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9385
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9386
0
                    goto failed;
9387
0
                }
9388
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9389
0
                _Py_LeaveRecursiveCall();
9390
0
                Py_DECREF(tmp2);
9391
0
                if (res != 0) goto failed;
9392
0
                if (len != PyList_GET_SIZE(tmp)) {
9393
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
9394
0
                    goto failed;
9395
0
                }
9396
0
                asdl_seq_SET(body, i, val);
9397
0
            }
9398
0
            Py_CLEAR(tmp);
9399
0
        }
9400
0
        if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
9401
0
            return -1;
9402
0
        }
9403
0
        if (tmp == NULL) {
9404
0
            tmp = PyList_New(0);
9405
0
            if (tmp == NULL) {
9406
0
                return -1;
9407
0
            }
9408
0
        }
9409
0
        {
9410
0
            int res;
9411
0
            Py_ssize_t len;
9412
0
            Py_ssize_t i;
9413
0
            if (!PyList_Check(tmp)) {
9414
0
                PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %T", tmp);
9415
0
                goto failed;
9416
0
            }
9417
0
            len = PyList_GET_SIZE(tmp);
9418
0
            handlers = _Py_asdl_excepthandler_seq_new(len, arena);
9419
0
            if (handlers == NULL) goto failed;
9420
0
            for (i = 0; i < len; i++) {
9421
0
                excepthandler_ty val;
9422
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9423
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9424
0
                    goto failed;
9425
0
                }
9426
0
                res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
9427
0
                _Py_LeaveRecursiveCall();
9428
0
                Py_DECREF(tmp2);
9429
0
                if (res != 0) goto failed;
9430
0
                if (len != PyList_GET_SIZE(tmp)) {
9431
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
9432
0
                    goto failed;
9433
0
                }
9434
0
                asdl_seq_SET(handlers, i, val);
9435
0
            }
9436
0
            Py_CLEAR(tmp);
9437
0
        }
9438
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
9439
0
            return -1;
9440
0
        }
9441
0
        if (tmp == NULL) {
9442
0
            tmp = PyList_New(0);
9443
0
            if (tmp == NULL) {
9444
0
                return -1;
9445
0
            }
9446
0
        }
9447
0
        {
9448
0
            int res;
9449
0
            Py_ssize_t len;
9450
0
            Py_ssize_t i;
9451
0
            if (!PyList_Check(tmp)) {
9452
0
                PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %T", tmp);
9453
0
                goto failed;
9454
0
            }
9455
0
            len = PyList_GET_SIZE(tmp);
9456
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
9457
0
            if (orelse == NULL) goto failed;
9458
0
            for (i = 0; i < len; i++) {
9459
0
                stmt_ty val;
9460
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9461
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9462
0
                    goto failed;
9463
0
                }
9464
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9465
0
                _Py_LeaveRecursiveCall();
9466
0
                Py_DECREF(tmp2);
9467
0
                if (res != 0) goto failed;
9468
0
                if (len != PyList_GET_SIZE(tmp)) {
9469
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
9470
0
                    goto failed;
9471
0
                }
9472
0
                asdl_seq_SET(orelse, i, val);
9473
0
            }
9474
0
            Py_CLEAR(tmp);
9475
0
        }
9476
0
        if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
9477
0
            return -1;
9478
0
        }
9479
0
        if (tmp == NULL) {
9480
0
            tmp = PyList_New(0);
9481
0
            if (tmp == NULL) {
9482
0
                return -1;
9483
0
            }
9484
0
        }
9485
0
        {
9486
0
            int res;
9487
0
            Py_ssize_t len;
9488
0
            Py_ssize_t i;
9489
0
            if (!PyList_Check(tmp)) {
9490
0
                PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %T", tmp);
9491
0
                goto failed;
9492
0
            }
9493
0
            len = PyList_GET_SIZE(tmp);
9494
0
            finalbody = _Py_asdl_stmt_seq_new(len, arena);
9495
0
            if (finalbody == NULL) goto failed;
9496
0
            for (i = 0; i < len; i++) {
9497
0
                stmt_ty val;
9498
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9499
0
                if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
9500
0
                    goto failed;
9501
0
                }
9502
0
                res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
9503
0
                _Py_LeaveRecursiveCall();
9504
0
                Py_DECREF(tmp2);
9505
0
                if (res != 0) goto failed;
9506
0
                if (len != PyList_GET_SIZE(tmp)) {
9507
0
                    PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
9508
0
                    goto failed;
9509
0
                }
9510
0
                asdl_seq_SET(finalbody, i, val);
9511
0
            }
9512
0
            Py_CLEAR(tmp);
9513
0
        }
9514
0
        *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
9515
0
                          col_offset, end_lineno, end_col_offset, arena);
9516
0
        if (*out == NULL) goto failed;
9517
0
        return 0;
9518
0
    }
9519
0
    tp = state->TryStar_type;
9520
0
    isinstance = PyObject_IsInstance(obj, tp);
9521
0
    if (isinstance == -1) {
9522
0
        return -1;
9523
0
    }
9524
0
    if (isinstance) {
9525
0
        asdl_stmt_seq* body;
9526
0
        asdl_excepthandler_seq* handlers;
9527
0
        asdl_stmt_seq* orelse;
9528
0
        asdl_stmt_seq* finalbody;
9529
9530
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
9531
0
            return -1;
9532
0
        }
9533
0
        if (tmp == NULL) {
9534
0
            tmp = PyList_New(0);
9535
0
            if (tmp == NULL) {
9536
0
                return -1;
9537
0
            }
9538
0
        }
9539
0
        {
9540
0
            int res;
9541
0
            Py_ssize_t len;
9542
0
            Py_ssize_t i;
9543
0
            if (!PyList_Check(tmp)) {
9544
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %T", tmp);
9545
0
                goto failed;
9546
0
            }
9547
0
            len = PyList_GET_SIZE(tmp);
9548
0
            body = _Py_asdl_stmt_seq_new(len, arena);
9549
0
            if (body == NULL) goto failed;
9550
0
            for (i = 0; i < len; i++) {
9551
0
                stmt_ty val;
9552
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9553
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9554
0
                    goto failed;
9555
0
                }
9556
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
9557
0
                _Py_LeaveRecursiveCall();
9558
0
                Py_DECREF(tmp2);
9559
0
                if (res != 0) goto failed;
9560
0
                if (len != PyList_GET_SIZE(tmp)) {
9561
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
9562
0
                    goto failed;
9563
0
                }
9564
0
                asdl_seq_SET(body, i, val);
9565
0
            }
9566
0
            Py_CLEAR(tmp);
9567
0
        }
9568
0
        if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
9569
0
            return -1;
9570
0
        }
9571
0
        if (tmp == NULL) {
9572
0
            tmp = PyList_New(0);
9573
0
            if (tmp == NULL) {
9574
0
                return -1;
9575
0
            }
9576
0
        }
9577
0
        {
9578
0
            int res;
9579
0
            Py_ssize_t len;
9580
0
            Py_ssize_t i;
9581
0
            if (!PyList_Check(tmp)) {
9582
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %T", tmp);
9583
0
                goto failed;
9584
0
            }
9585
0
            len = PyList_GET_SIZE(tmp);
9586
0
            handlers = _Py_asdl_excepthandler_seq_new(len, arena);
9587
0
            if (handlers == NULL) goto failed;
9588
0
            for (i = 0; i < len; i++) {
9589
0
                excepthandler_ty val;
9590
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9591
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9592
0
                    goto failed;
9593
0
                }
9594
0
                res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
9595
0
                _Py_LeaveRecursiveCall();
9596
0
                Py_DECREF(tmp2);
9597
0
                if (res != 0) goto failed;
9598
0
                if (len != PyList_GET_SIZE(tmp)) {
9599
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
9600
0
                    goto failed;
9601
0
                }
9602
0
                asdl_seq_SET(handlers, i, val);
9603
0
            }
9604
0
            Py_CLEAR(tmp);
9605
0
        }
9606
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
9607
0
            return -1;
9608
0
        }
9609
0
        if (tmp == NULL) {
9610
0
            tmp = PyList_New(0);
9611
0
            if (tmp == NULL) {
9612
0
                return -1;
9613
0
            }
9614
0
        }
9615
0
        {
9616
0
            int res;
9617
0
            Py_ssize_t len;
9618
0
            Py_ssize_t i;
9619
0
            if (!PyList_Check(tmp)) {
9620
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %T", tmp);
9621
0
                goto failed;
9622
0
            }
9623
0
            len = PyList_GET_SIZE(tmp);
9624
0
            orelse = _Py_asdl_stmt_seq_new(len, arena);
9625
0
            if (orelse == NULL) goto failed;
9626
0
            for (i = 0; i < len; i++) {
9627
0
                stmt_ty val;
9628
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9629
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9630
0
                    goto failed;
9631
0
                }
9632
0
                res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
9633
0
                _Py_LeaveRecursiveCall();
9634
0
                Py_DECREF(tmp2);
9635
0
                if (res != 0) goto failed;
9636
0
                if (len != PyList_GET_SIZE(tmp)) {
9637
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
9638
0
                    goto failed;
9639
0
                }
9640
0
                asdl_seq_SET(orelse, i, val);
9641
0
            }
9642
0
            Py_CLEAR(tmp);
9643
0
        }
9644
0
        if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
9645
0
            return -1;
9646
0
        }
9647
0
        if (tmp == NULL) {
9648
0
            tmp = PyList_New(0);
9649
0
            if (tmp == NULL) {
9650
0
                return -1;
9651
0
            }
9652
0
        }
9653
0
        {
9654
0
            int res;
9655
0
            Py_ssize_t len;
9656
0
            Py_ssize_t i;
9657
0
            if (!PyList_Check(tmp)) {
9658
0
                PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %T", tmp);
9659
0
                goto failed;
9660
0
            }
9661
0
            len = PyList_GET_SIZE(tmp);
9662
0
            finalbody = _Py_asdl_stmt_seq_new(len, arena);
9663
0
            if (finalbody == NULL) goto failed;
9664
0
            for (i = 0; i < len; i++) {
9665
0
                stmt_ty val;
9666
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9667
0
                if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
9668
0
                    goto failed;
9669
0
                }
9670
0
                res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
9671
0
                _Py_LeaveRecursiveCall();
9672
0
                Py_DECREF(tmp2);
9673
0
                if (res != 0) goto failed;
9674
0
                if (len != PyList_GET_SIZE(tmp)) {
9675
0
                    PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
9676
0
                    goto failed;
9677
0
                }
9678
0
                asdl_seq_SET(finalbody, i, val);
9679
0
            }
9680
0
            Py_CLEAR(tmp);
9681
0
        }
9682
0
        *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
9683
0
                              col_offset, end_lineno, end_col_offset, arena);
9684
0
        if (*out == NULL) goto failed;
9685
0
        return 0;
9686
0
    }
9687
0
    tp = state->Assert_type;
9688
0
    isinstance = PyObject_IsInstance(obj, tp);
9689
0
    if (isinstance == -1) {
9690
0
        return -1;
9691
0
    }
9692
0
    if (isinstance) {
9693
0
        expr_ty test;
9694
0
        expr_ty msg;
9695
9696
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
9697
0
            return -1;
9698
0
        }
9699
0
        if (tmp == NULL) {
9700
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
9701
0
            return -1;
9702
0
        }
9703
0
        else {
9704
0
            int res;
9705
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
9706
0
                goto failed;
9707
0
            }
9708
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
9709
0
            _Py_LeaveRecursiveCall();
9710
0
            if (res != 0) goto failed;
9711
0
            Py_CLEAR(tmp);
9712
0
        }
9713
0
        if (PyObject_GetOptionalAttr(obj, state->msg, &tmp) < 0) {
9714
0
            return -1;
9715
0
        }
9716
0
        if (tmp == NULL || tmp == Py_None) {
9717
0
            Py_CLEAR(tmp);
9718
0
            msg = NULL;
9719
0
        }
9720
0
        else {
9721
0
            int res;
9722
0
            if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
9723
0
                goto failed;
9724
0
            }
9725
0
            res = obj2ast_expr(state, tmp, &msg, "msg", arena);
9726
0
            _Py_LeaveRecursiveCall();
9727
0
            if (res != 0) goto failed;
9728
0
            Py_CLEAR(tmp);
9729
0
        }
9730
0
        *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
9731
0
                             end_col_offset, arena);
9732
0
        if (*out == NULL) goto failed;
9733
0
        return 0;
9734
0
    }
9735
0
    tp = state->Import_type;
9736
0
    isinstance = PyObject_IsInstance(obj, tp);
9737
0
    if (isinstance == -1) {
9738
0
        return -1;
9739
0
    }
9740
0
    if (isinstance) {
9741
0
        asdl_alias_seq* names;
9742
0
        int is_lazy;
9743
9744
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9745
0
            return -1;
9746
0
        }
9747
0
        if (tmp == NULL) {
9748
0
            tmp = PyList_New(0);
9749
0
            if (tmp == NULL) {
9750
0
                return -1;
9751
0
            }
9752
0
        }
9753
0
        {
9754
0
            int res;
9755
0
            Py_ssize_t len;
9756
0
            Py_ssize_t i;
9757
0
            if (!PyList_Check(tmp)) {
9758
0
                PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %T", tmp);
9759
0
                goto failed;
9760
0
            }
9761
0
            len = PyList_GET_SIZE(tmp);
9762
0
            names = _Py_asdl_alias_seq_new(len, arena);
9763
0
            if (names == NULL) goto failed;
9764
0
            for (i = 0; i < len; i++) {
9765
0
                alias_ty val;
9766
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9767
0
                if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
9768
0
                    goto failed;
9769
0
                }
9770
0
                res = obj2ast_alias(state, tmp2, &val, "names", arena);
9771
0
                _Py_LeaveRecursiveCall();
9772
0
                Py_DECREF(tmp2);
9773
0
                if (res != 0) goto failed;
9774
0
                if (len != PyList_GET_SIZE(tmp)) {
9775
0
                    PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
9776
0
                    goto failed;
9777
0
                }
9778
0
                asdl_seq_SET(names, i, val);
9779
0
            }
9780
0
            Py_CLEAR(tmp);
9781
0
        }
9782
0
        if (PyObject_GetOptionalAttr(obj, state->is_lazy, &tmp) < 0) {
9783
0
            return -1;
9784
0
        }
9785
0
        if (tmp == NULL || tmp == Py_None) {
9786
0
            Py_CLEAR(tmp);
9787
0
            is_lazy = 0;
9788
0
        }
9789
0
        else {
9790
0
            int res;
9791
0
            if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
9792
0
                goto failed;
9793
0
            }
9794
0
            res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
9795
0
            _Py_LeaveRecursiveCall();
9796
0
            if (res != 0) goto failed;
9797
0
            Py_CLEAR(tmp);
9798
0
        }
9799
0
        *out = _PyAST_Import(names, is_lazy, lineno, col_offset, end_lineno,
9800
0
                             end_col_offset, arena);
9801
0
        if (*out == NULL) goto failed;
9802
0
        return 0;
9803
0
    }
9804
0
    tp = state->ImportFrom_type;
9805
0
    isinstance = PyObject_IsInstance(obj, tp);
9806
0
    if (isinstance == -1) {
9807
0
        return -1;
9808
0
    }
9809
0
    if (isinstance) {
9810
0
        identifier module;
9811
0
        asdl_alias_seq* names;
9812
0
        int level;
9813
0
        int is_lazy;
9814
9815
0
        if (PyObject_GetOptionalAttr(obj, state->module, &tmp) < 0) {
9816
0
            return -1;
9817
0
        }
9818
0
        if (tmp == NULL || tmp == Py_None) {
9819
0
            Py_CLEAR(tmp);
9820
0
            module = NULL;
9821
0
        }
9822
0
        else {
9823
0
            int res;
9824
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9825
0
                goto failed;
9826
0
            }
9827
0
            res = obj2ast_identifier(state, tmp, &module, "module", arena);
9828
0
            _Py_LeaveRecursiveCall();
9829
0
            if (res != 0) goto failed;
9830
0
            Py_CLEAR(tmp);
9831
0
        }
9832
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9833
0
            return -1;
9834
0
        }
9835
0
        if (tmp == NULL) {
9836
0
            tmp = PyList_New(0);
9837
0
            if (tmp == NULL) {
9838
0
                return -1;
9839
0
            }
9840
0
        }
9841
0
        {
9842
0
            int res;
9843
0
            Py_ssize_t len;
9844
0
            Py_ssize_t i;
9845
0
            if (!PyList_Check(tmp)) {
9846
0
                PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %T", tmp);
9847
0
                goto failed;
9848
0
            }
9849
0
            len = PyList_GET_SIZE(tmp);
9850
0
            names = _Py_asdl_alias_seq_new(len, arena);
9851
0
            if (names == NULL) goto failed;
9852
0
            for (i = 0; i < len; i++) {
9853
0
                alias_ty val;
9854
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9855
0
                if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9856
0
                    goto failed;
9857
0
                }
9858
0
                res = obj2ast_alias(state, tmp2, &val, "names", arena);
9859
0
                _Py_LeaveRecursiveCall();
9860
0
                Py_DECREF(tmp2);
9861
0
                if (res != 0) goto failed;
9862
0
                if (len != PyList_GET_SIZE(tmp)) {
9863
0
                    PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
9864
0
                    goto failed;
9865
0
                }
9866
0
                asdl_seq_SET(names, i, val);
9867
0
            }
9868
0
            Py_CLEAR(tmp);
9869
0
        }
9870
0
        if (PyObject_GetOptionalAttr(obj, state->level, &tmp) < 0) {
9871
0
            return -1;
9872
0
        }
9873
0
        if (tmp == NULL || tmp == Py_None) {
9874
0
            Py_CLEAR(tmp);
9875
0
            level = 0;
9876
0
        }
9877
0
        else {
9878
0
            int res;
9879
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9880
0
                goto failed;
9881
0
            }
9882
0
            res = obj2ast_int(state, tmp, &level, "level", arena);
9883
0
            _Py_LeaveRecursiveCall();
9884
0
            if (res != 0) goto failed;
9885
0
            Py_CLEAR(tmp);
9886
0
        }
9887
0
        if (PyObject_GetOptionalAttr(obj, state->is_lazy, &tmp) < 0) {
9888
0
            return -1;
9889
0
        }
9890
0
        if (tmp == NULL || tmp == Py_None) {
9891
0
            Py_CLEAR(tmp);
9892
0
            is_lazy = 0;
9893
0
        }
9894
0
        else {
9895
0
            int res;
9896
0
            if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
9897
0
                goto failed;
9898
0
            }
9899
0
            res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
9900
0
            _Py_LeaveRecursiveCall();
9901
0
            if (res != 0) goto failed;
9902
0
            Py_CLEAR(tmp);
9903
0
        }
9904
0
        *out = _PyAST_ImportFrom(module, names, level, is_lazy, lineno,
9905
0
                                 col_offset, end_lineno, end_col_offset, arena);
9906
0
        if (*out == NULL) goto failed;
9907
0
        return 0;
9908
0
    }
9909
0
    tp = state->Global_type;
9910
0
    isinstance = PyObject_IsInstance(obj, tp);
9911
0
    if (isinstance == -1) {
9912
0
        return -1;
9913
0
    }
9914
0
    if (isinstance) {
9915
0
        asdl_identifier_seq* names;
9916
9917
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9918
0
            return -1;
9919
0
        }
9920
0
        if (tmp == NULL) {
9921
0
            tmp = PyList_New(0);
9922
0
            if (tmp == NULL) {
9923
0
                return -1;
9924
0
            }
9925
0
        }
9926
0
        {
9927
0
            int res;
9928
0
            Py_ssize_t len;
9929
0
            Py_ssize_t i;
9930
0
            if (!PyList_Check(tmp)) {
9931
0
                PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %T", tmp);
9932
0
                goto failed;
9933
0
            }
9934
0
            len = PyList_GET_SIZE(tmp);
9935
0
            names = _Py_asdl_identifier_seq_new(len, arena);
9936
0
            if (names == NULL) goto failed;
9937
0
            for (i = 0; i < len; i++) {
9938
0
                identifier val;
9939
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9940
0
                if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
9941
0
                    goto failed;
9942
0
                }
9943
0
                res = obj2ast_identifier(state, tmp2, &val, "names", arena);
9944
0
                _Py_LeaveRecursiveCall();
9945
0
                Py_DECREF(tmp2);
9946
0
                if (res != 0) goto failed;
9947
0
                if (len != PyList_GET_SIZE(tmp)) {
9948
0
                    PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
9949
0
                    goto failed;
9950
0
                }
9951
0
                asdl_seq_SET(names, i, val);
9952
0
            }
9953
0
            Py_CLEAR(tmp);
9954
0
        }
9955
0
        *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
9956
0
                             end_col_offset, arena);
9957
0
        if (*out == NULL) goto failed;
9958
0
        return 0;
9959
0
    }
9960
0
    tp = state->Nonlocal_type;
9961
0
    isinstance = PyObject_IsInstance(obj, tp);
9962
0
    if (isinstance == -1) {
9963
0
        return -1;
9964
0
    }
9965
0
    if (isinstance) {
9966
0
        asdl_identifier_seq* names;
9967
9968
0
        if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
9969
0
            return -1;
9970
0
        }
9971
0
        if (tmp == NULL) {
9972
0
            tmp = PyList_New(0);
9973
0
            if (tmp == NULL) {
9974
0
                return -1;
9975
0
            }
9976
0
        }
9977
0
        {
9978
0
            int res;
9979
0
            Py_ssize_t len;
9980
0
            Py_ssize_t i;
9981
0
            if (!PyList_Check(tmp)) {
9982
0
                PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %T", tmp);
9983
0
                goto failed;
9984
0
            }
9985
0
            len = PyList_GET_SIZE(tmp);
9986
0
            names = _Py_asdl_identifier_seq_new(len, arena);
9987
0
            if (names == NULL) goto failed;
9988
0
            for (i = 0; i < len; i++) {
9989
0
                identifier val;
9990
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9991
0
                if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
9992
0
                    goto failed;
9993
0
                }
9994
0
                res = obj2ast_identifier(state, tmp2, &val, "names", arena);
9995
0
                _Py_LeaveRecursiveCall();
9996
0
                Py_DECREF(tmp2);
9997
0
                if (res != 0) goto failed;
9998
0
                if (len != PyList_GET_SIZE(tmp)) {
9999
0
                    PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
10000
0
                    goto failed;
10001
0
                }
10002
0
                asdl_seq_SET(names, i, val);
10003
0
            }
10004
0
            Py_CLEAR(tmp);
10005
0
        }
10006
0
        *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
10007
0
                               end_col_offset, arena);
10008
0
        if (*out == NULL) goto failed;
10009
0
        return 0;
10010
0
    }
10011
0
    tp = state->Expr_type;
10012
0
    isinstance = PyObject_IsInstance(obj, tp);
10013
0
    if (isinstance == -1) {
10014
0
        return -1;
10015
0
    }
10016
0
    if (isinstance) {
10017
0
        expr_ty value;
10018
10019
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10020
0
            return -1;
10021
0
        }
10022
0
        if (tmp == NULL) {
10023
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
10024
0
            return -1;
10025
0
        }
10026
0
        else {
10027
0
            int res;
10028
0
            if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
10029
0
                goto failed;
10030
0
            }
10031
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10032
0
            _Py_LeaveRecursiveCall();
10033
0
            if (res != 0) goto failed;
10034
0
            Py_CLEAR(tmp);
10035
0
        }
10036
0
        *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
10037
0
                           end_col_offset, arena);
10038
0
        if (*out == NULL) goto failed;
10039
0
        return 0;
10040
0
    }
10041
0
    tp = state->Pass_type;
10042
0
    isinstance = PyObject_IsInstance(obj, tp);
10043
0
    if (isinstance == -1) {
10044
0
        return -1;
10045
0
    }
10046
0
    if (isinstance) {
10047
10048
0
        *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
10049
0
                           arena);
10050
0
        if (*out == NULL) goto failed;
10051
0
        return 0;
10052
0
    }
10053
0
    tp = state->Break_type;
10054
0
    isinstance = PyObject_IsInstance(obj, tp);
10055
0
    if (isinstance == -1) {
10056
0
        return -1;
10057
0
    }
10058
0
    if (isinstance) {
10059
10060
0
        *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
10061
0
                            arena);
10062
0
        if (*out == NULL) goto failed;
10063
0
        return 0;
10064
0
    }
10065
0
    tp = state->Continue_type;
10066
0
    isinstance = PyObject_IsInstance(obj, tp);
10067
0
    if (isinstance == -1) {
10068
0
        return -1;
10069
0
    }
10070
0
    if (isinstance) {
10071
10072
0
        *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
10073
0
                               arena);
10074
0
        if (*out == NULL) goto failed;
10075
0
        return 0;
10076
0
    }
10077
10078
0
    PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
10079
0
    failed:
10080
0
    Py_XDECREF(tmp);
10081
0
    return -1;
10082
0
}
10083
10084
int
10085
obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, const char*
10086
             field, PyArena* arena)
10087
0
{
10088
0
    int isinstance;
10089
10090
0
    PyObject *tmp = NULL;
10091
0
    PyObject *tp;
10092
0
    int lineno;
10093
0
    int col_offset;
10094
0
    int end_lineno;
10095
0
    int end_col_offset;
10096
10097
0
    if (obj == Py_None) {
10098
0
        *out = NULL;
10099
0
        return 0;
10100
0
    }
10101
0
    tp = state->expr_type;
10102
0
    isinstance = PyObject_IsInstance(obj, tp);
10103
0
    if (isinstance == -1) {
10104
0
        return 1;
10105
0
    }
10106
0
    if (!isinstance && field != NULL) {
10107
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'expr', got '%T'", field, obj);
10108
0
        return 1;
10109
0
    }
10110
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
10111
0
        return -1;
10112
0
    }
10113
0
    if (tmp == NULL) {
10114
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
10115
0
        return -1;
10116
0
    }
10117
0
    else {
10118
0
        int res;
10119
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10120
0
            goto failed;
10121
0
        }
10122
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
10123
0
        _Py_LeaveRecursiveCall();
10124
0
        if (res != 0) goto failed;
10125
0
        Py_CLEAR(tmp);
10126
0
    }
10127
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
10128
0
        return -1;
10129
0
    }
10130
0
    if (tmp == NULL) {
10131
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
10132
0
        return -1;
10133
0
    }
10134
0
    else {
10135
0
        int res;
10136
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10137
0
            goto failed;
10138
0
        }
10139
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
10140
0
        _Py_LeaveRecursiveCall();
10141
0
        if (res != 0) goto failed;
10142
0
        Py_CLEAR(tmp);
10143
0
    }
10144
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
10145
0
        return -1;
10146
0
    }
10147
0
    if (tmp == NULL || tmp == Py_None) {
10148
0
        Py_CLEAR(tmp);
10149
0
        end_lineno = lineno;
10150
0
    }
10151
0
    else {
10152
0
        int res;
10153
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10154
0
            goto failed;
10155
0
        }
10156
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
10157
0
        _Py_LeaveRecursiveCall();
10158
0
        if (res != 0) goto failed;
10159
0
        Py_CLEAR(tmp);
10160
0
    }
10161
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
10162
0
        return -1;
10163
0
    }
10164
0
    if (tmp == NULL || tmp == Py_None) {
10165
0
        Py_CLEAR(tmp);
10166
0
        end_col_offset = col_offset;
10167
0
    }
10168
0
    else {
10169
0
        int res;
10170
0
        if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
10171
0
            goto failed;
10172
0
        }
10173
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
10174
0
        _Py_LeaveRecursiveCall();
10175
0
        if (res != 0) goto failed;
10176
0
        Py_CLEAR(tmp);
10177
0
    }
10178
0
    tp = state->BoolOp_type;
10179
0
    isinstance = PyObject_IsInstance(obj, tp);
10180
0
    if (isinstance == -1) {
10181
0
        return -1;
10182
0
    }
10183
0
    if (isinstance) {
10184
0
        boolop_ty op;
10185
0
        asdl_expr_seq* values;
10186
10187
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10188
0
            return -1;
10189
0
        }
10190
0
        if (tmp == NULL) {
10191
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
10192
0
            return -1;
10193
0
        }
10194
0
        else {
10195
0
            int res;
10196
0
            if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
10197
0
                goto failed;
10198
0
            }
10199
0
            res = obj2ast_boolop(state, tmp, &op, "op", arena);
10200
0
            _Py_LeaveRecursiveCall();
10201
0
            if (res != 0) goto failed;
10202
0
            Py_CLEAR(tmp);
10203
0
        }
10204
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
10205
0
            return -1;
10206
0
        }
10207
0
        if (tmp == NULL) {
10208
0
            tmp = PyList_New(0);
10209
0
            if (tmp == NULL) {
10210
0
                return -1;
10211
0
            }
10212
0
        }
10213
0
        {
10214
0
            int res;
10215
0
            Py_ssize_t len;
10216
0
            Py_ssize_t i;
10217
0
            if (!PyList_Check(tmp)) {
10218
0
                PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %T", tmp);
10219
0
                goto failed;
10220
0
            }
10221
0
            len = PyList_GET_SIZE(tmp);
10222
0
            values = _Py_asdl_expr_seq_new(len, arena);
10223
0
            if (values == NULL) goto failed;
10224
0
            for (i = 0; i < len; i++) {
10225
0
                expr_ty val;
10226
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10227
0
                if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
10228
0
                    goto failed;
10229
0
                }
10230
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
10231
0
                _Py_LeaveRecursiveCall();
10232
0
                Py_DECREF(tmp2);
10233
0
                if (res != 0) goto failed;
10234
0
                if (len != PyList_GET_SIZE(tmp)) {
10235
0
                    PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
10236
0
                    goto failed;
10237
0
                }
10238
0
                asdl_seq_SET(values, i, val);
10239
0
            }
10240
0
            Py_CLEAR(tmp);
10241
0
        }
10242
0
        *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
10243
0
                             end_col_offset, arena);
10244
0
        if (*out == NULL) goto failed;
10245
0
        return 0;
10246
0
    }
10247
0
    tp = state->NamedExpr_type;
10248
0
    isinstance = PyObject_IsInstance(obj, tp);
10249
0
    if (isinstance == -1) {
10250
0
        return -1;
10251
0
    }
10252
0
    if (isinstance) {
10253
0
        expr_ty target;
10254
0
        expr_ty value;
10255
10256
0
        if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
10257
0
            return -1;
10258
0
        }
10259
0
        if (tmp == NULL) {
10260
0
            PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
10261
0
            return -1;
10262
0
        }
10263
0
        else {
10264
0
            int res;
10265
0
            if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
10266
0
                goto failed;
10267
0
            }
10268
0
            res = obj2ast_expr(state, tmp, &target, "target", arena);
10269
0
            _Py_LeaveRecursiveCall();
10270
0
            if (res != 0) goto failed;
10271
0
            Py_CLEAR(tmp);
10272
0
        }
10273
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10274
0
            return -1;
10275
0
        }
10276
0
        if (tmp == NULL) {
10277
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
10278
0
            return -1;
10279
0
        }
10280
0
        else {
10281
0
            int res;
10282
0
            if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
10283
0
                goto failed;
10284
0
            }
10285
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10286
0
            _Py_LeaveRecursiveCall();
10287
0
            if (res != 0) goto failed;
10288
0
            Py_CLEAR(tmp);
10289
0
        }
10290
0
        *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
10291
0
                                end_col_offset, arena);
10292
0
        if (*out == NULL) goto failed;
10293
0
        return 0;
10294
0
    }
10295
0
    tp = state->BinOp_type;
10296
0
    isinstance = PyObject_IsInstance(obj, tp);
10297
0
    if (isinstance == -1) {
10298
0
        return -1;
10299
0
    }
10300
0
    if (isinstance) {
10301
0
        expr_ty left;
10302
0
        operator_ty op;
10303
0
        expr_ty right;
10304
10305
0
        if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
10306
0
            return -1;
10307
0
        }
10308
0
        if (tmp == NULL) {
10309
0
            PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
10310
0
            return -1;
10311
0
        }
10312
0
        else {
10313
0
            int res;
10314
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10315
0
                goto failed;
10316
0
            }
10317
0
            res = obj2ast_expr(state, tmp, &left, "left", arena);
10318
0
            _Py_LeaveRecursiveCall();
10319
0
            if (res != 0) goto failed;
10320
0
            Py_CLEAR(tmp);
10321
0
        }
10322
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10323
0
            return -1;
10324
0
        }
10325
0
        if (tmp == NULL) {
10326
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
10327
0
            return -1;
10328
0
        }
10329
0
        else {
10330
0
            int res;
10331
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10332
0
                goto failed;
10333
0
            }
10334
0
            res = obj2ast_operator(state, tmp, &op, "op", arena);
10335
0
            _Py_LeaveRecursiveCall();
10336
0
            if (res != 0) goto failed;
10337
0
            Py_CLEAR(tmp);
10338
0
        }
10339
0
        if (PyObject_GetOptionalAttr(obj, state->right, &tmp) < 0) {
10340
0
            return -1;
10341
0
        }
10342
0
        if (tmp == NULL) {
10343
0
            PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
10344
0
            return -1;
10345
0
        }
10346
0
        else {
10347
0
            int res;
10348
0
            if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
10349
0
                goto failed;
10350
0
            }
10351
0
            res = obj2ast_expr(state, tmp, &right, "right", arena);
10352
0
            _Py_LeaveRecursiveCall();
10353
0
            if (res != 0) goto failed;
10354
0
            Py_CLEAR(tmp);
10355
0
        }
10356
0
        *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
10357
0
                            end_col_offset, arena);
10358
0
        if (*out == NULL) goto failed;
10359
0
        return 0;
10360
0
    }
10361
0
    tp = state->UnaryOp_type;
10362
0
    isinstance = PyObject_IsInstance(obj, tp);
10363
0
    if (isinstance == -1) {
10364
0
        return -1;
10365
0
    }
10366
0
    if (isinstance) {
10367
0
        unaryop_ty op;
10368
0
        expr_ty operand;
10369
10370
0
        if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
10371
0
            return -1;
10372
0
        }
10373
0
        if (tmp == NULL) {
10374
0
            PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
10375
0
            return -1;
10376
0
        }
10377
0
        else {
10378
0
            int res;
10379
0
            if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
10380
0
                goto failed;
10381
0
            }
10382
0
            res = obj2ast_unaryop(state, tmp, &op, "op", arena);
10383
0
            _Py_LeaveRecursiveCall();
10384
0
            if (res != 0) goto failed;
10385
0
            Py_CLEAR(tmp);
10386
0
        }
10387
0
        if (PyObject_GetOptionalAttr(obj, state->operand, &tmp) < 0) {
10388
0
            return -1;
10389
0
        }
10390
0
        if (tmp == NULL) {
10391
0
            PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
10392
0
            return -1;
10393
0
        }
10394
0
        else {
10395
0
            int res;
10396
0
            if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
10397
0
                goto failed;
10398
0
            }
10399
0
            res = obj2ast_expr(state, tmp, &operand, "operand", arena);
10400
0
            _Py_LeaveRecursiveCall();
10401
0
            if (res != 0) goto failed;
10402
0
            Py_CLEAR(tmp);
10403
0
        }
10404
0
        *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
10405
0
                              end_col_offset, arena);
10406
0
        if (*out == NULL) goto failed;
10407
0
        return 0;
10408
0
    }
10409
0
    tp = state->Lambda_type;
10410
0
    isinstance = PyObject_IsInstance(obj, tp);
10411
0
    if (isinstance == -1) {
10412
0
        return -1;
10413
0
    }
10414
0
    if (isinstance) {
10415
0
        arguments_ty args;
10416
0
        expr_ty body;
10417
10418
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
10419
0
            return -1;
10420
0
        }
10421
0
        if (tmp == NULL) {
10422
0
            PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
10423
0
            return -1;
10424
0
        }
10425
0
        else {
10426
0
            int res;
10427
0
            if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
10428
0
                goto failed;
10429
0
            }
10430
0
            res = obj2ast_arguments(state, tmp, &args, "args", arena);
10431
0
            _Py_LeaveRecursiveCall();
10432
0
            if (res != 0) goto failed;
10433
0
            Py_CLEAR(tmp);
10434
0
        }
10435
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10436
0
            return -1;
10437
0
        }
10438
0
        if (tmp == NULL) {
10439
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
10440
0
            return -1;
10441
0
        }
10442
0
        else {
10443
0
            int res;
10444
0
            if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
10445
0
                goto failed;
10446
0
            }
10447
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
10448
0
            _Py_LeaveRecursiveCall();
10449
0
            if (res != 0) goto failed;
10450
0
            Py_CLEAR(tmp);
10451
0
        }
10452
0
        *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
10453
0
                             end_col_offset, arena);
10454
0
        if (*out == NULL) goto failed;
10455
0
        return 0;
10456
0
    }
10457
0
    tp = state->IfExp_type;
10458
0
    isinstance = PyObject_IsInstance(obj, tp);
10459
0
    if (isinstance == -1) {
10460
0
        return -1;
10461
0
    }
10462
0
    if (isinstance) {
10463
0
        expr_ty test;
10464
0
        expr_ty body;
10465
0
        expr_ty orelse;
10466
10467
0
        if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
10468
0
            return -1;
10469
0
        }
10470
0
        if (tmp == NULL) {
10471
0
            PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
10472
0
            return -1;
10473
0
        }
10474
0
        else {
10475
0
            int res;
10476
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10477
0
                goto failed;
10478
0
            }
10479
0
            res = obj2ast_expr(state, tmp, &test, "test", arena);
10480
0
            _Py_LeaveRecursiveCall();
10481
0
            if (res != 0) goto failed;
10482
0
            Py_CLEAR(tmp);
10483
0
        }
10484
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10485
0
            return -1;
10486
0
        }
10487
0
        if (tmp == NULL) {
10488
0
            PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
10489
0
            return -1;
10490
0
        }
10491
0
        else {
10492
0
            int res;
10493
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10494
0
                goto failed;
10495
0
            }
10496
0
            res = obj2ast_expr(state, tmp, &body, "body", arena);
10497
0
            _Py_LeaveRecursiveCall();
10498
0
            if (res != 0) goto failed;
10499
0
            Py_CLEAR(tmp);
10500
0
        }
10501
0
        if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
10502
0
            return -1;
10503
0
        }
10504
0
        if (tmp == NULL) {
10505
0
            PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
10506
0
            return -1;
10507
0
        }
10508
0
        else {
10509
0
            int res;
10510
0
            if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
10511
0
                goto failed;
10512
0
            }
10513
0
            res = obj2ast_expr(state, tmp, &orelse, "orelse", arena);
10514
0
            _Py_LeaveRecursiveCall();
10515
0
            if (res != 0) goto failed;
10516
0
            Py_CLEAR(tmp);
10517
0
        }
10518
0
        *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
10519
0
                            end_col_offset, arena);
10520
0
        if (*out == NULL) goto failed;
10521
0
        return 0;
10522
0
    }
10523
0
    tp = state->Dict_type;
10524
0
    isinstance = PyObject_IsInstance(obj, tp);
10525
0
    if (isinstance == -1) {
10526
0
        return -1;
10527
0
    }
10528
0
    if (isinstance) {
10529
0
        asdl_expr_seq* keys;
10530
0
        asdl_expr_seq* values;
10531
10532
0
        if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
10533
0
            return -1;
10534
0
        }
10535
0
        if (tmp == NULL) {
10536
0
            tmp = PyList_New(0);
10537
0
            if (tmp == NULL) {
10538
0
                return -1;
10539
0
            }
10540
0
        }
10541
0
        {
10542
0
            int res;
10543
0
            Py_ssize_t len;
10544
0
            Py_ssize_t i;
10545
0
            if (!PyList_Check(tmp)) {
10546
0
                PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %T", tmp);
10547
0
                goto failed;
10548
0
            }
10549
0
            len = PyList_GET_SIZE(tmp);
10550
0
            keys = _Py_asdl_expr_seq_new(len, arena);
10551
0
            if (keys == NULL) goto failed;
10552
0
            for (i = 0; i < len; i++) {
10553
0
                expr_ty val;
10554
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10555
0
                if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
10556
0
                    goto failed;
10557
0
                }
10558
0
                res = obj2ast_expr(state, tmp2, &val, "keys", arena);
10559
0
                _Py_LeaveRecursiveCall();
10560
0
                Py_DECREF(tmp2);
10561
0
                if (res != 0) goto failed;
10562
0
                if (len != PyList_GET_SIZE(tmp)) {
10563
0
                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
10564
0
                    goto failed;
10565
0
                }
10566
0
                asdl_seq_SET(keys, i, val);
10567
0
            }
10568
0
            Py_CLEAR(tmp);
10569
0
        }
10570
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
10571
0
            return -1;
10572
0
        }
10573
0
        if (tmp == NULL) {
10574
0
            tmp = PyList_New(0);
10575
0
            if (tmp == NULL) {
10576
0
                return -1;
10577
0
            }
10578
0
        }
10579
0
        {
10580
0
            int res;
10581
0
            Py_ssize_t len;
10582
0
            Py_ssize_t i;
10583
0
            if (!PyList_Check(tmp)) {
10584
0
                PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %T", tmp);
10585
0
                goto failed;
10586
0
            }
10587
0
            len = PyList_GET_SIZE(tmp);
10588
0
            values = _Py_asdl_expr_seq_new(len, arena);
10589
0
            if (values == NULL) goto failed;
10590
0
            for (i = 0; i < len; i++) {
10591
0
                expr_ty val;
10592
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10593
0
                if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
10594
0
                    goto failed;
10595
0
                }
10596
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
10597
0
                _Py_LeaveRecursiveCall();
10598
0
                Py_DECREF(tmp2);
10599
0
                if (res != 0) goto failed;
10600
0
                if (len != PyList_GET_SIZE(tmp)) {
10601
0
                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
10602
0
                    goto failed;
10603
0
                }
10604
0
                asdl_seq_SET(values, i, val);
10605
0
            }
10606
0
            Py_CLEAR(tmp);
10607
0
        }
10608
0
        *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
10609
0
                           end_col_offset, arena);
10610
0
        if (*out == NULL) goto failed;
10611
0
        return 0;
10612
0
    }
10613
0
    tp = state->Set_type;
10614
0
    isinstance = PyObject_IsInstance(obj, tp);
10615
0
    if (isinstance == -1) {
10616
0
        return -1;
10617
0
    }
10618
0
    if (isinstance) {
10619
0
        asdl_expr_seq* elts;
10620
10621
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
10622
0
            return -1;
10623
0
        }
10624
0
        if (tmp == NULL) {
10625
0
            tmp = PyList_New(0);
10626
0
            if (tmp == NULL) {
10627
0
                return -1;
10628
0
            }
10629
0
        }
10630
0
        {
10631
0
            int res;
10632
0
            Py_ssize_t len;
10633
0
            Py_ssize_t i;
10634
0
            if (!PyList_Check(tmp)) {
10635
0
                PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %T", tmp);
10636
0
                goto failed;
10637
0
            }
10638
0
            len = PyList_GET_SIZE(tmp);
10639
0
            elts = _Py_asdl_expr_seq_new(len, arena);
10640
0
            if (elts == NULL) goto failed;
10641
0
            for (i = 0; i < len; i++) {
10642
0
                expr_ty val;
10643
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10644
0
                if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
10645
0
                    goto failed;
10646
0
                }
10647
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
10648
0
                _Py_LeaveRecursiveCall();
10649
0
                Py_DECREF(tmp2);
10650
0
                if (res != 0) goto failed;
10651
0
                if (len != PyList_GET_SIZE(tmp)) {
10652
0
                    PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
10653
0
                    goto failed;
10654
0
                }
10655
0
                asdl_seq_SET(elts, i, val);
10656
0
            }
10657
0
            Py_CLEAR(tmp);
10658
0
        }
10659
0
        *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
10660
0
                          arena);
10661
0
        if (*out == NULL) goto failed;
10662
0
        return 0;
10663
0
    }
10664
0
    tp = state->ListComp_type;
10665
0
    isinstance = PyObject_IsInstance(obj, tp);
10666
0
    if (isinstance == -1) {
10667
0
        return -1;
10668
0
    }
10669
0
    if (isinstance) {
10670
0
        expr_ty elt;
10671
0
        asdl_comprehension_seq* generators;
10672
10673
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10674
0
            return -1;
10675
0
        }
10676
0
        if (tmp == NULL) {
10677
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
10678
0
            return -1;
10679
0
        }
10680
0
        else {
10681
0
            int res;
10682
0
            if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
10683
0
                goto failed;
10684
0
            }
10685
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10686
0
            _Py_LeaveRecursiveCall();
10687
0
            if (res != 0) goto failed;
10688
0
            Py_CLEAR(tmp);
10689
0
        }
10690
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10691
0
            return -1;
10692
0
        }
10693
0
        if (tmp == NULL) {
10694
0
            tmp = PyList_New(0);
10695
0
            if (tmp == NULL) {
10696
0
                return -1;
10697
0
            }
10698
0
        }
10699
0
        {
10700
0
            int res;
10701
0
            Py_ssize_t len;
10702
0
            Py_ssize_t i;
10703
0
            if (!PyList_Check(tmp)) {
10704
0
                PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %T", tmp);
10705
0
                goto failed;
10706
0
            }
10707
0
            len = PyList_GET_SIZE(tmp);
10708
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10709
0
            if (generators == NULL) goto failed;
10710
0
            for (i = 0; i < len; i++) {
10711
0
                comprehension_ty val;
10712
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10713
0
                if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
10714
0
                    goto failed;
10715
0
                }
10716
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10717
0
                _Py_LeaveRecursiveCall();
10718
0
                Py_DECREF(tmp2);
10719
0
                if (res != 0) goto failed;
10720
0
                if (len != PyList_GET_SIZE(tmp)) {
10721
0
                    PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
10722
0
                    goto failed;
10723
0
                }
10724
0
                asdl_seq_SET(generators, i, val);
10725
0
            }
10726
0
            Py_CLEAR(tmp);
10727
0
        }
10728
0
        *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
10729
0
                               end_col_offset, arena);
10730
0
        if (*out == NULL) goto failed;
10731
0
        return 0;
10732
0
    }
10733
0
    tp = state->SetComp_type;
10734
0
    isinstance = PyObject_IsInstance(obj, tp);
10735
0
    if (isinstance == -1) {
10736
0
        return -1;
10737
0
    }
10738
0
    if (isinstance) {
10739
0
        expr_ty elt;
10740
0
        asdl_comprehension_seq* generators;
10741
10742
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10743
0
            return -1;
10744
0
        }
10745
0
        if (tmp == NULL) {
10746
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
10747
0
            return -1;
10748
0
        }
10749
0
        else {
10750
0
            int res;
10751
0
            if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
10752
0
                goto failed;
10753
0
            }
10754
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10755
0
            _Py_LeaveRecursiveCall();
10756
0
            if (res != 0) goto failed;
10757
0
            Py_CLEAR(tmp);
10758
0
        }
10759
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10760
0
            return -1;
10761
0
        }
10762
0
        if (tmp == NULL) {
10763
0
            tmp = PyList_New(0);
10764
0
            if (tmp == NULL) {
10765
0
                return -1;
10766
0
            }
10767
0
        }
10768
0
        {
10769
0
            int res;
10770
0
            Py_ssize_t len;
10771
0
            Py_ssize_t i;
10772
0
            if (!PyList_Check(tmp)) {
10773
0
                PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %T", tmp);
10774
0
                goto failed;
10775
0
            }
10776
0
            len = PyList_GET_SIZE(tmp);
10777
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10778
0
            if (generators == NULL) goto failed;
10779
0
            for (i = 0; i < len; i++) {
10780
0
                comprehension_ty val;
10781
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10782
0
                if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
10783
0
                    goto failed;
10784
0
                }
10785
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10786
0
                _Py_LeaveRecursiveCall();
10787
0
                Py_DECREF(tmp2);
10788
0
                if (res != 0) goto failed;
10789
0
                if (len != PyList_GET_SIZE(tmp)) {
10790
0
                    PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
10791
0
                    goto failed;
10792
0
                }
10793
0
                asdl_seq_SET(generators, i, val);
10794
0
            }
10795
0
            Py_CLEAR(tmp);
10796
0
        }
10797
0
        *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
10798
0
                              end_col_offset, arena);
10799
0
        if (*out == NULL) goto failed;
10800
0
        return 0;
10801
0
    }
10802
0
    tp = state->DictComp_type;
10803
0
    isinstance = PyObject_IsInstance(obj, tp);
10804
0
    if (isinstance == -1) {
10805
0
        return -1;
10806
0
    }
10807
0
    if (isinstance) {
10808
0
        expr_ty key;
10809
0
        expr_ty value;
10810
0
        asdl_comprehension_seq* generators;
10811
10812
0
        if (PyObject_GetOptionalAttr(obj, state->key, &tmp) < 0) {
10813
0
            return -1;
10814
0
        }
10815
0
        if (tmp == NULL) {
10816
0
            PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
10817
0
            return -1;
10818
0
        }
10819
0
        else {
10820
0
            int res;
10821
0
            if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10822
0
                goto failed;
10823
0
            }
10824
0
            res = obj2ast_expr(state, tmp, &key, "key", arena);
10825
0
            _Py_LeaveRecursiveCall();
10826
0
            if (res != 0) goto failed;
10827
0
            Py_CLEAR(tmp);
10828
0
        }
10829
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10830
0
            return -1;
10831
0
        }
10832
0
        if (tmp == NULL || tmp == Py_None) {
10833
0
            Py_CLEAR(tmp);
10834
0
            value = NULL;
10835
0
        }
10836
0
        else {
10837
0
            int res;
10838
0
            if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10839
0
                goto failed;
10840
0
            }
10841
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10842
0
            _Py_LeaveRecursiveCall();
10843
0
            if (res != 0) goto failed;
10844
0
            Py_CLEAR(tmp);
10845
0
        }
10846
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10847
0
            return -1;
10848
0
        }
10849
0
        if (tmp == NULL) {
10850
0
            tmp = PyList_New(0);
10851
0
            if (tmp == NULL) {
10852
0
                return -1;
10853
0
            }
10854
0
        }
10855
0
        {
10856
0
            int res;
10857
0
            Py_ssize_t len;
10858
0
            Py_ssize_t i;
10859
0
            if (!PyList_Check(tmp)) {
10860
0
                PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %T", tmp);
10861
0
                goto failed;
10862
0
            }
10863
0
            len = PyList_GET_SIZE(tmp);
10864
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10865
0
            if (generators == NULL) goto failed;
10866
0
            for (i = 0; i < len; i++) {
10867
0
                comprehension_ty val;
10868
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10869
0
                if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
10870
0
                    goto failed;
10871
0
                }
10872
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10873
0
                _Py_LeaveRecursiveCall();
10874
0
                Py_DECREF(tmp2);
10875
0
                if (res != 0) goto failed;
10876
0
                if (len != PyList_GET_SIZE(tmp)) {
10877
0
                    PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
10878
0
                    goto failed;
10879
0
                }
10880
0
                asdl_seq_SET(generators, i, val);
10881
0
            }
10882
0
            Py_CLEAR(tmp);
10883
0
        }
10884
0
        *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
10885
0
                               end_lineno, end_col_offset, arena);
10886
0
        if (*out == NULL) goto failed;
10887
0
        return 0;
10888
0
    }
10889
0
    tp = state->GeneratorExp_type;
10890
0
    isinstance = PyObject_IsInstance(obj, tp);
10891
0
    if (isinstance == -1) {
10892
0
        return -1;
10893
0
    }
10894
0
    if (isinstance) {
10895
0
        expr_ty elt;
10896
0
        asdl_comprehension_seq* generators;
10897
10898
0
        if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
10899
0
            return -1;
10900
0
        }
10901
0
        if (tmp == NULL) {
10902
0
            PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
10903
0
            return -1;
10904
0
        }
10905
0
        else {
10906
0
            int res;
10907
0
            if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
10908
0
                goto failed;
10909
0
            }
10910
0
            res = obj2ast_expr(state, tmp, &elt, "elt", arena);
10911
0
            _Py_LeaveRecursiveCall();
10912
0
            if (res != 0) goto failed;
10913
0
            Py_CLEAR(tmp);
10914
0
        }
10915
0
        if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
10916
0
            return -1;
10917
0
        }
10918
0
        if (tmp == NULL) {
10919
0
            tmp = PyList_New(0);
10920
0
            if (tmp == NULL) {
10921
0
                return -1;
10922
0
            }
10923
0
        }
10924
0
        {
10925
0
            int res;
10926
0
            Py_ssize_t len;
10927
0
            Py_ssize_t i;
10928
0
            if (!PyList_Check(tmp)) {
10929
0
                PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %T", tmp);
10930
0
                goto failed;
10931
0
            }
10932
0
            len = PyList_GET_SIZE(tmp);
10933
0
            generators = _Py_asdl_comprehension_seq_new(len, arena);
10934
0
            if (generators == NULL) goto failed;
10935
0
            for (i = 0; i < len; i++) {
10936
0
                comprehension_ty val;
10937
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10938
0
                if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
10939
0
                    goto failed;
10940
0
                }
10941
0
                res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
10942
0
                _Py_LeaveRecursiveCall();
10943
0
                Py_DECREF(tmp2);
10944
0
                if (res != 0) goto failed;
10945
0
                if (len != PyList_GET_SIZE(tmp)) {
10946
0
                    PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
10947
0
                    goto failed;
10948
0
                }
10949
0
                asdl_seq_SET(generators, i, val);
10950
0
            }
10951
0
            Py_CLEAR(tmp);
10952
0
        }
10953
0
        *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
10954
0
                                   end_lineno, end_col_offset, arena);
10955
0
        if (*out == NULL) goto failed;
10956
0
        return 0;
10957
0
    }
10958
0
    tp = state->Await_type;
10959
0
    isinstance = PyObject_IsInstance(obj, tp);
10960
0
    if (isinstance == -1) {
10961
0
        return -1;
10962
0
    }
10963
0
    if (isinstance) {
10964
0
        expr_ty value;
10965
10966
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10967
0
            return -1;
10968
0
        }
10969
0
        if (tmp == NULL) {
10970
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
10971
0
            return -1;
10972
0
        }
10973
0
        else {
10974
0
            int res;
10975
0
            if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
10976
0
                goto failed;
10977
0
            }
10978
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
10979
0
            _Py_LeaveRecursiveCall();
10980
0
            if (res != 0) goto failed;
10981
0
            Py_CLEAR(tmp);
10982
0
        }
10983
0
        *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
10984
0
                            end_col_offset, arena);
10985
0
        if (*out == NULL) goto failed;
10986
0
        return 0;
10987
0
    }
10988
0
    tp = state->Yield_type;
10989
0
    isinstance = PyObject_IsInstance(obj, tp);
10990
0
    if (isinstance == -1) {
10991
0
        return -1;
10992
0
    }
10993
0
    if (isinstance) {
10994
0
        expr_ty value;
10995
10996
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
10997
0
            return -1;
10998
0
        }
10999
0
        if (tmp == NULL || tmp == Py_None) {
11000
0
            Py_CLEAR(tmp);
11001
0
            value = NULL;
11002
0
        }
11003
0
        else {
11004
0
            int res;
11005
0
            if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
11006
0
                goto failed;
11007
0
            }
11008
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11009
0
            _Py_LeaveRecursiveCall();
11010
0
            if (res != 0) goto failed;
11011
0
            Py_CLEAR(tmp);
11012
0
        }
11013
0
        *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
11014
0
                            end_col_offset, arena);
11015
0
        if (*out == NULL) goto failed;
11016
0
        return 0;
11017
0
    }
11018
0
    tp = state->YieldFrom_type;
11019
0
    isinstance = PyObject_IsInstance(obj, tp);
11020
0
    if (isinstance == -1) {
11021
0
        return -1;
11022
0
    }
11023
0
    if (isinstance) {
11024
0
        expr_ty value;
11025
11026
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11027
0
            return -1;
11028
0
        }
11029
0
        if (tmp == NULL) {
11030
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
11031
0
            return -1;
11032
0
        }
11033
0
        else {
11034
0
            int res;
11035
0
            if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
11036
0
                goto failed;
11037
0
            }
11038
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11039
0
            _Py_LeaveRecursiveCall();
11040
0
            if (res != 0) goto failed;
11041
0
            Py_CLEAR(tmp);
11042
0
        }
11043
0
        *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
11044
0
                                end_col_offset, arena);
11045
0
        if (*out == NULL) goto failed;
11046
0
        return 0;
11047
0
    }
11048
0
    tp = state->Compare_type;
11049
0
    isinstance = PyObject_IsInstance(obj, tp);
11050
0
    if (isinstance == -1) {
11051
0
        return -1;
11052
0
    }
11053
0
    if (isinstance) {
11054
0
        expr_ty left;
11055
0
        asdl_int_seq* ops;
11056
0
        asdl_expr_seq* comparators;
11057
11058
0
        if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
11059
0
            return -1;
11060
0
        }
11061
0
        if (tmp == NULL) {
11062
0
            PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
11063
0
            return -1;
11064
0
        }
11065
0
        else {
11066
0
            int res;
11067
0
            if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11068
0
                goto failed;
11069
0
            }
11070
0
            res = obj2ast_expr(state, tmp, &left, "left", arena);
11071
0
            _Py_LeaveRecursiveCall();
11072
0
            if (res != 0) goto failed;
11073
0
            Py_CLEAR(tmp);
11074
0
        }
11075
0
        if (PyObject_GetOptionalAttr(obj, state->ops, &tmp) < 0) {
11076
0
            return -1;
11077
0
        }
11078
0
        if (tmp == NULL) {
11079
0
            tmp = PyList_New(0);
11080
0
            if (tmp == NULL) {
11081
0
                return -1;
11082
0
            }
11083
0
        }
11084
0
        {
11085
0
            int res;
11086
0
            Py_ssize_t len;
11087
0
            Py_ssize_t i;
11088
0
            if (!PyList_Check(tmp)) {
11089
0
                PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %T", tmp);
11090
0
                goto failed;
11091
0
            }
11092
0
            len = PyList_GET_SIZE(tmp);
11093
0
            ops = _Py_asdl_int_seq_new(len, arena);
11094
0
            if (ops == NULL) goto failed;
11095
0
            for (i = 0; i < len; i++) {
11096
0
                cmpop_ty val;
11097
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11098
0
                if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11099
0
                    goto failed;
11100
0
                }
11101
0
                res = obj2ast_cmpop(state, tmp2, &val, "ops", arena);
11102
0
                _Py_LeaveRecursiveCall();
11103
0
                Py_DECREF(tmp2);
11104
0
                if (res != 0) goto failed;
11105
0
                if (len != PyList_GET_SIZE(tmp)) {
11106
0
                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
11107
0
                    goto failed;
11108
0
                }
11109
0
                asdl_seq_SET(ops, i, val);
11110
0
            }
11111
0
            Py_CLEAR(tmp);
11112
0
        }
11113
0
        if (PyObject_GetOptionalAttr(obj, state->comparators, &tmp) < 0) {
11114
0
            return -1;
11115
0
        }
11116
0
        if (tmp == NULL) {
11117
0
            tmp = PyList_New(0);
11118
0
            if (tmp == NULL) {
11119
0
                return -1;
11120
0
            }
11121
0
        }
11122
0
        {
11123
0
            int res;
11124
0
            Py_ssize_t len;
11125
0
            Py_ssize_t i;
11126
0
            if (!PyList_Check(tmp)) {
11127
0
                PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %T", tmp);
11128
0
                goto failed;
11129
0
            }
11130
0
            len = PyList_GET_SIZE(tmp);
11131
0
            comparators = _Py_asdl_expr_seq_new(len, arena);
11132
0
            if (comparators == NULL) goto failed;
11133
0
            for (i = 0; i < len; i++) {
11134
0
                expr_ty val;
11135
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11136
0
                if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
11137
0
                    goto failed;
11138
0
                }
11139
0
                res = obj2ast_expr(state, tmp2, &val, "comparators", arena);
11140
0
                _Py_LeaveRecursiveCall();
11141
0
                Py_DECREF(tmp2);
11142
0
                if (res != 0) goto failed;
11143
0
                if (len != PyList_GET_SIZE(tmp)) {
11144
0
                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
11145
0
                    goto failed;
11146
0
                }
11147
0
                asdl_seq_SET(comparators, i, val);
11148
0
            }
11149
0
            Py_CLEAR(tmp);
11150
0
        }
11151
0
        *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
11152
0
                              end_lineno, end_col_offset, arena);
11153
0
        if (*out == NULL) goto failed;
11154
0
        return 0;
11155
0
    }
11156
0
    tp = state->Call_type;
11157
0
    isinstance = PyObject_IsInstance(obj, tp);
11158
0
    if (isinstance == -1) {
11159
0
        return -1;
11160
0
    }
11161
0
    if (isinstance) {
11162
0
        expr_ty func;
11163
0
        asdl_expr_seq* args;
11164
0
        asdl_keyword_seq* keywords;
11165
11166
0
        if (PyObject_GetOptionalAttr(obj, state->func, &tmp) < 0) {
11167
0
            return -1;
11168
0
        }
11169
0
        if (tmp == NULL) {
11170
0
            PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
11171
0
            return -1;
11172
0
        }
11173
0
        else {
11174
0
            int res;
11175
0
            if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11176
0
                goto failed;
11177
0
            }
11178
0
            res = obj2ast_expr(state, tmp, &func, "func", arena);
11179
0
            _Py_LeaveRecursiveCall();
11180
0
            if (res != 0) goto failed;
11181
0
            Py_CLEAR(tmp);
11182
0
        }
11183
0
        if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
11184
0
            return -1;
11185
0
        }
11186
0
        if (tmp == NULL) {
11187
0
            tmp = PyList_New(0);
11188
0
            if (tmp == NULL) {
11189
0
                return -1;
11190
0
            }
11191
0
        }
11192
0
        {
11193
0
            int res;
11194
0
            Py_ssize_t len;
11195
0
            Py_ssize_t i;
11196
0
            if (!PyList_Check(tmp)) {
11197
0
                PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %T", tmp);
11198
0
                goto failed;
11199
0
            }
11200
0
            len = PyList_GET_SIZE(tmp);
11201
0
            args = _Py_asdl_expr_seq_new(len, arena);
11202
0
            if (args == NULL) goto failed;
11203
0
            for (i = 0; i < len; i++) {
11204
0
                expr_ty val;
11205
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11206
0
                if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11207
0
                    goto failed;
11208
0
                }
11209
0
                res = obj2ast_expr(state, tmp2, &val, "args", arena);
11210
0
                _Py_LeaveRecursiveCall();
11211
0
                Py_DECREF(tmp2);
11212
0
                if (res != 0) goto failed;
11213
0
                if (len != PyList_GET_SIZE(tmp)) {
11214
0
                    PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
11215
0
                    goto failed;
11216
0
                }
11217
0
                asdl_seq_SET(args, i, val);
11218
0
            }
11219
0
            Py_CLEAR(tmp);
11220
0
        }
11221
0
        if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
11222
0
            return -1;
11223
0
        }
11224
0
        if (tmp == NULL) {
11225
0
            tmp = PyList_New(0);
11226
0
            if (tmp == NULL) {
11227
0
                return -1;
11228
0
            }
11229
0
        }
11230
0
        {
11231
0
            int res;
11232
0
            Py_ssize_t len;
11233
0
            Py_ssize_t i;
11234
0
            if (!PyList_Check(tmp)) {
11235
0
                PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %T", tmp);
11236
0
                goto failed;
11237
0
            }
11238
0
            len = PyList_GET_SIZE(tmp);
11239
0
            keywords = _Py_asdl_keyword_seq_new(len, arena);
11240
0
            if (keywords == NULL) goto failed;
11241
0
            for (i = 0; i < len; i++) {
11242
0
                keyword_ty val;
11243
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11244
0
                if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
11245
0
                    goto failed;
11246
0
                }
11247
0
                res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
11248
0
                _Py_LeaveRecursiveCall();
11249
0
                Py_DECREF(tmp2);
11250
0
                if (res != 0) goto failed;
11251
0
                if (len != PyList_GET_SIZE(tmp)) {
11252
0
                    PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
11253
0
                    goto failed;
11254
0
                }
11255
0
                asdl_seq_SET(keywords, i, val);
11256
0
            }
11257
0
            Py_CLEAR(tmp);
11258
0
        }
11259
0
        *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
11260
0
                           end_lineno, end_col_offset, arena);
11261
0
        if (*out == NULL) goto failed;
11262
0
        return 0;
11263
0
    }
11264
0
    tp = state->FormattedValue_type;
11265
0
    isinstance = PyObject_IsInstance(obj, tp);
11266
0
    if (isinstance == -1) {
11267
0
        return -1;
11268
0
    }
11269
0
    if (isinstance) {
11270
0
        expr_ty value;
11271
0
        int conversion;
11272
0
        expr_ty format_spec;
11273
11274
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11275
0
            return -1;
11276
0
        }
11277
0
        if (tmp == NULL) {
11278
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
11279
0
            return -1;
11280
0
        }
11281
0
        else {
11282
0
            int res;
11283
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11284
0
                goto failed;
11285
0
            }
11286
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11287
0
            _Py_LeaveRecursiveCall();
11288
0
            if (res != 0) goto failed;
11289
0
            Py_CLEAR(tmp);
11290
0
        }
11291
0
        if (PyObject_GetOptionalAttr(obj, state->conversion, &tmp) < 0) {
11292
0
            return -1;
11293
0
        }
11294
0
        if (tmp == NULL) {
11295
0
            PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
11296
0
            return -1;
11297
0
        }
11298
0
        else {
11299
0
            int res;
11300
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11301
0
                goto failed;
11302
0
            }
11303
0
            res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
11304
0
            _Py_LeaveRecursiveCall();
11305
0
            if (res != 0) goto failed;
11306
0
            Py_CLEAR(tmp);
11307
0
        }
11308
0
        if (PyObject_GetOptionalAttr(obj, state->format_spec, &tmp) < 0) {
11309
0
            return -1;
11310
0
        }
11311
0
        if (tmp == NULL || tmp == Py_None) {
11312
0
            Py_CLEAR(tmp);
11313
0
            format_spec = NULL;
11314
0
        }
11315
0
        else {
11316
0
            int res;
11317
0
            if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
11318
0
                goto failed;
11319
0
            }
11320
0
            res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
11321
0
            _Py_LeaveRecursiveCall();
11322
0
            if (res != 0) goto failed;
11323
0
            Py_CLEAR(tmp);
11324
0
        }
11325
0
        *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
11326
0
                                     col_offset, end_lineno, end_col_offset,
11327
0
                                     arena);
11328
0
        if (*out == NULL) goto failed;
11329
0
        return 0;
11330
0
    }
11331
0
    tp = state->Interpolation_type;
11332
0
    isinstance = PyObject_IsInstance(obj, tp);
11333
0
    if (isinstance == -1) {
11334
0
        return -1;
11335
0
    }
11336
0
    if (isinstance) {
11337
0
        expr_ty value;
11338
0
        constant str;
11339
0
        int conversion;
11340
0
        expr_ty format_spec;
11341
11342
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11343
0
            return -1;
11344
0
        }
11345
0
        if (tmp == NULL) {
11346
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Interpolation");
11347
0
            return -1;
11348
0
        }
11349
0
        else {
11350
0
            int res;
11351
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11352
0
                goto failed;
11353
0
            }
11354
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11355
0
            _Py_LeaveRecursiveCall();
11356
0
            if (res != 0) goto failed;
11357
0
            Py_CLEAR(tmp);
11358
0
        }
11359
0
        if (PyObject_GetOptionalAttr(obj, state->str, &tmp) < 0) {
11360
0
            return -1;
11361
0
        }
11362
0
        if (tmp == NULL) {
11363
0
            PyErr_SetString(PyExc_TypeError, "required field \"str\" missing from Interpolation");
11364
0
            return -1;
11365
0
        }
11366
0
        else {
11367
0
            int res;
11368
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11369
0
                goto failed;
11370
0
            }
11371
0
            res = obj2ast_constant(state, tmp, &str, "str", arena);
11372
0
            _Py_LeaveRecursiveCall();
11373
0
            if (res != 0) goto failed;
11374
0
            Py_CLEAR(tmp);
11375
0
        }
11376
0
        if (PyObject_GetOptionalAttr(obj, state->conversion, &tmp) < 0) {
11377
0
            return -1;
11378
0
        }
11379
0
        if (tmp == NULL) {
11380
0
            PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from Interpolation");
11381
0
            return -1;
11382
0
        }
11383
0
        else {
11384
0
            int res;
11385
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11386
0
                goto failed;
11387
0
            }
11388
0
            res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
11389
0
            _Py_LeaveRecursiveCall();
11390
0
            if (res != 0) goto failed;
11391
0
            Py_CLEAR(tmp);
11392
0
        }
11393
0
        if (PyObject_GetOptionalAttr(obj, state->format_spec, &tmp) < 0) {
11394
0
            return -1;
11395
0
        }
11396
0
        if (tmp == NULL || tmp == Py_None) {
11397
0
            Py_CLEAR(tmp);
11398
0
            format_spec = NULL;
11399
0
        }
11400
0
        else {
11401
0
            int res;
11402
0
            if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
11403
0
                goto failed;
11404
0
            }
11405
0
            res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
11406
0
            _Py_LeaveRecursiveCall();
11407
0
            if (res != 0) goto failed;
11408
0
            Py_CLEAR(tmp);
11409
0
        }
11410
0
        *out = _PyAST_Interpolation(value, str, conversion, format_spec,
11411
0
                                    lineno, col_offset, end_lineno,
11412
0
                                    end_col_offset, arena);
11413
0
        if (*out == NULL) goto failed;
11414
0
        return 0;
11415
0
    }
11416
0
    tp = state->JoinedStr_type;
11417
0
    isinstance = PyObject_IsInstance(obj, tp);
11418
0
    if (isinstance == -1) {
11419
0
        return -1;
11420
0
    }
11421
0
    if (isinstance) {
11422
0
        asdl_expr_seq* values;
11423
11424
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
11425
0
            return -1;
11426
0
        }
11427
0
        if (tmp == NULL) {
11428
0
            tmp = PyList_New(0);
11429
0
            if (tmp == NULL) {
11430
0
                return -1;
11431
0
            }
11432
0
        }
11433
0
        {
11434
0
            int res;
11435
0
            Py_ssize_t len;
11436
0
            Py_ssize_t i;
11437
0
            if (!PyList_Check(tmp)) {
11438
0
                PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %T", tmp);
11439
0
                goto failed;
11440
0
            }
11441
0
            len = PyList_GET_SIZE(tmp);
11442
0
            values = _Py_asdl_expr_seq_new(len, arena);
11443
0
            if (values == NULL) goto failed;
11444
0
            for (i = 0; i < len; i++) {
11445
0
                expr_ty val;
11446
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11447
0
                if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
11448
0
                    goto failed;
11449
0
                }
11450
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
11451
0
                _Py_LeaveRecursiveCall();
11452
0
                Py_DECREF(tmp2);
11453
0
                if (res != 0) goto failed;
11454
0
                if (len != PyList_GET_SIZE(tmp)) {
11455
0
                    PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
11456
0
                    goto failed;
11457
0
                }
11458
0
                asdl_seq_SET(values, i, val);
11459
0
            }
11460
0
            Py_CLEAR(tmp);
11461
0
        }
11462
0
        *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
11463
0
                                end_col_offset, arena);
11464
0
        if (*out == NULL) goto failed;
11465
0
        return 0;
11466
0
    }
11467
0
    tp = state->TemplateStr_type;
11468
0
    isinstance = PyObject_IsInstance(obj, tp);
11469
0
    if (isinstance == -1) {
11470
0
        return -1;
11471
0
    }
11472
0
    if (isinstance) {
11473
0
        asdl_expr_seq* values;
11474
11475
0
        if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
11476
0
            return -1;
11477
0
        }
11478
0
        if (tmp == NULL) {
11479
0
            tmp = PyList_New(0);
11480
0
            if (tmp == NULL) {
11481
0
                return -1;
11482
0
            }
11483
0
        }
11484
0
        {
11485
0
            int res;
11486
0
            Py_ssize_t len;
11487
0
            Py_ssize_t i;
11488
0
            if (!PyList_Check(tmp)) {
11489
0
                PyErr_Format(PyExc_TypeError, "TemplateStr field \"values\" must be a list, not a %T", tmp);
11490
0
                goto failed;
11491
0
            }
11492
0
            len = PyList_GET_SIZE(tmp);
11493
0
            values = _Py_asdl_expr_seq_new(len, arena);
11494
0
            if (values == NULL) goto failed;
11495
0
            for (i = 0; i < len; i++) {
11496
0
                expr_ty val;
11497
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11498
0
                if (_Py_EnterRecursiveCall(" while traversing 'TemplateStr' node")) {
11499
0
                    goto failed;
11500
0
                }
11501
0
                res = obj2ast_expr(state, tmp2, &val, "values", arena);
11502
0
                _Py_LeaveRecursiveCall();
11503
0
                Py_DECREF(tmp2);
11504
0
                if (res != 0) goto failed;
11505
0
                if (len != PyList_GET_SIZE(tmp)) {
11506
0
                    PyErr_SetString(PyExc_RuntimeError, "TemplateStr field \"values\" changed size during iteration");
11507
0
                    goto failed;
11508
0
                }
11509
0
                asdl_seq_SET(values, i, val);
11510
0
            }
11511
0
            Py_CLEAR(tmp);
11512
0
        }
11513
0
        *out = _PyAST_TemplateStr(values, lineno, col_offset, end_lineno,
11514
0
                                  end_col_offset, arena);
11515
0
        if (*out == NULL) goto failed;
11516
0
        return 0;
11517
0
    }
11518
0
    tp = state->Constant_type;
11519
0
    isinstance = PyObject_IsInstance(obj, tp);
11520
0
    if (isinstance == -1) {
11521
0
        return -1;
11522
0
    }
11523
0
    if (isinstance) {
11524
0
        constant value;
11525
0
        string kind;
11526
11527
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11528
0
            return -1;
11529
0
        }
11530
0
        if (tmp == NULL) {
11531
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
11532
0
            return -1;
11533
0
        }
11534
0
        else {
11535
0
            int res;
11536
0
            if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
11537
0
                goto failed;
11538
0
            }
11539
0
            res = obj2ast_constant(state, tmp, &value, "value", arena);
11540
0
            _Py_LeaveRecursiveCall();
11541
0
            if (res != 0) goto failed;
11542
0
            Py_CLEAR(tmp);
11543
0
        }
11544
0
        if (PyObject_GetOptionalAttr(obj, state->kind, &tmp) < 0) {
11545
0
            return -1;
11546
0
        }
11547
0
        if (tmp == NULL || tmp == Py_None) {
11548
0
            Py_CLEAR(tmp);
11549
0
            kind = NULL;
11550
0
        }
11551
0
        else {
11552
0
            int res;
11553
0
            if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
11554
0
                goto failed;
11555
0
            }
11556
0
            res = obj2ast_string(state, tmp, &kind, "kind", arena);
11557
0
            _Py_LeaveRecursiveCall();
11558
0
            if (res != 0) goto failed;
11559
0
            Py_CLEAR(tmp);
11560
0
        }
11561
0
        *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
11562
0
                               end_col_offset, arena);
11563
0
        if (*out == NULL) goto failed;
11564
0
        return 0;
11565
0
    }
11566
0
    tp = state->Attribute_type;
11567
0
    isinstance = PyObject_IsInstance(obj, tp);
11568
0
    if (isinstance == -1) {
11569
0
        return -1;
11570
0
    }
11571
0
    if (isinstance) {
11572
0
        expr_ty value;
11573
0
        identifier attr;
11574
0
        expr_context_ty ctx;
11575
11576
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11577
0
            return -1;
11578
0
        }
11579
0
        if (tmp == NULL) {
11580
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
11581
0
            return -1;
11582
0
        }
11583
0
        else {
11584
0
            int res;
11585
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11586
0
                goto failed;
11587
0
            }
11588
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11589
0
            _Py_LeaveRecursiveCall();
11590
0
            if (res != 0) goto failed;
11591
0
            Py_CLEAR(tmp);
11592
0
        }
11593
0
        if (PyObject_GetOptionalAttr(obj, state->attr, &tmp) < 0) {
11594
0
            return -1;
11595
0
        }
11596
0
        if (tmp == NULL) {
11597
0
            PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
11598
0
            return -1;
11599
0
        }
11600
0
        else {
11601
0
            int res;
11602
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11603
0
                goto failed;
11604
0
            }
11605
0
            res = obj2ast_identifier(state, tmp, &attr, "attr", arena);
11606
0
            _Py_LeaveRecursiveCall();
11607
0
            if (res != 0) goto failed;
11608
0
            Py_CLEAR(tmp);
11609
0
        }
11610
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11611
0
            return -1;
11612
0
        }
11613
0
        if (tmp == NULL) {
11614
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
11615
0
            return -1;
11616
0
        }
11617
0
        else {
11618
0
            int res;
11619
0
            if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
11620
0
                goto failed;
11621
0
            }
11622
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11623
0
            _Py_LeaveRecursiveCall();
11624
0
            if (res != 0) goto failed;
11625
0
            Py_CLEAR(tmp);
11626
0
        }
11627
0
        *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
11628
0
                                end_lineno, end_col_offset, arena);
11629
0
        if (*out == NULL) goto failed;
11630
0
        return 0;
11631
0
    }
11632
0
    tp = state->Subscript_type;
11633
0
    isinstance = PyObject_IsInstance(obj, tp);
11634
0
    if (isinstance == -1) {
11635
0
        return -1;
11636
0
    }
11637
0
    if (isinstance) {
11638
0
        expr_ty value;
11639
0
        expr_ty slice;
11640
0
        expr_context_ty ctx;
11641
11642
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11643
0
            return -1;
11644
0
        }
11645
0
        if (tmp == NULL) {
11646
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
11647
0
            return -1;
11648
0
        }
11649
0
        else {
11650
0
            int res;
11651
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11652
0
                goto failed;
11653
0
            }
11654
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11655
0
            _Py_LeaveRecursiveCall();
11656
0
            if (res != 0) goto failed;
11657
0
            Py_CLEAR(tmp);
11658
0
        }
11659
0
        if (PyObject_GetOptionalAttr(obj, state->slice, &tmp) < 0) {
11660
0
            return -1;
11661
0
        }
11662
0
        if (tmp == NULL) {
11663
0
            PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
11664
0
            return -1;
11665
0
        }
11666
0
        else {
11667
0
            int res;
11668
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11669
0
                goto failed;
11670
0
            }
11671
0
            res = obj2ast_expr(state, tmp, &slice, "slice", arena);
11672
0
            _Py_LeaveRecursiveCall();
11673
0
            if (res != 0) goto failed;
11674
0
            Py_CLEAR(tmp);
11675
0
        }
11676
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11677
0
            return -1;
11678
0
        }
11679
0
        if (tmp == NULL) {
11680
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
11681
0
            return -1;
11682
0
        }
11683
0
        else {
11684
0
            int res;
11685
0
            if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
11686
0
                goto failed;
11687
0
            }
11688
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11689
0
            _Py_LeaveRecursiveCall();
11690
0
            if (res != 0) goto failed;
11691
0
            Py_CLEAR(tmp);
11692
0
        }
11693
0
        *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
11694
0
                                end_lineno, end_col_offset, arena);
11695
0
        if (*out == NULL) goto failed;
11696
0
        return 0;
11697
0
    }
11698
0
    tp = state->Starred_type;
11699
0
    isinstance = PyObject_IsInstance(obj, tp);
11700
0
    if (isinstance == -1) {
11701
0
        return -1;
11702
0
    }
11703
0
    if (isinstance) {
11704
0
        expr_ty value;
11705
0
        expr_context_ty ctx;
11706
11707
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11708
0
            return -1;
11709
0
        }
11710
0
        if (tmp == NULL) {
11711
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
11712
0
            return -1;
11713
0
        }
11714
0
        else {
11715
0
            int res;
11716
0
            if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
11717
0
                goto failed;
11718
0
            }
11719
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
11720
0
            _Py_LeaveRecursiveCall();
11721
0
            if (res != 0) goto failed;
11722
0
            Py_CLEAR(tmp);
11723
0
        }
11724
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11725
0
            return -1;
11726
0
        }
11727
0
        if (tmp == NULL) {
11728
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
11729
0
            return -1;
11730
0
        }
11731
0
        else {
11732
0
            int res;
11733
0
            if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
11734
0
                goto failed;
11735
0
            }
11736
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11737
0
            _Py_LeaveRecursiveCall();
11738
0
            if (res != 0) goto failed;
11739
0
            Py_CLEAR(tmp);
11740
0
        }
11741
0
        *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
11742
0
                              end_col_offset, arena);
11743
0
        if (*out == NULL) goto failed;
11744
0
        return 0;
11745
0
    }
11746
0
    tp = state->Name_type;
11747
0
    isinstance = PyObject_IsInstance(obj, tp);
11748
0
    if (isinstance == -1) {
11749
0
        return -1;
11750
0
    }
11751
0
    if (isinstance) {
11752
0
        identifier id;
11753
0
        expr_context_ty ctx;
11754
11755
0
        if (PyObject_GetOptionalAttr(obj, state->id, &tmp) < 0) {
11756
0
            return -1;
11757
0
        }
11758
0
        if (tmp == NULL) {
11759
0
            PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
11760
0
            return -1;
11761
0
        }
11762
0
        else {
11763
0
            int res;
11764
0
            if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
11765
0
                goto failed;
11766
0
            }
11767
0
            res = obj2ast_identifier(state, tmp, &id, "id", arena);
11768
0
            _Py_LeaveRecursiveCall();
11769
0
            if (res != 0) goto failed;
11770
0
            Py_CLEAR(tmp);
11771
0
        }
11772
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11773
0
            return -1;
11774
0
        }
11775
0
        if (tmp == NULL) {
11776
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
11777
0
            return -1;
11778
0
        }
11779
0
        else {
11780
0
            int res;
11781
0
            if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
11782
0
                goto failed;
11783
0
            }
11784
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11785
0
            _Py_LeaveRecursiveCall();
11786
0
            if (res != 0) goto failed;
11787
0
            Py_CLEAR(tmp);
11788
0
        }
11789
0
        *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
11790
0
                           end_col_offset, arena);
11791
0
        if (*out == NULL) goto failed;
11792
0
        return 0;
11793
0
    }
11794
0
    tp = state->List_type;
11795
0
    isinstance = PyObject_IsInstance(obj, tp);
11796
0
    if (isinstance == -1) {
11797
0
        return -1;
11798
0
    }
11799
0
    if (isinstance) {
11800
0
        asdl_expr_seq* elts;
11801
0
        expr_context_ty ctx;
11802
11803
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
11804
0
            return -1;
11805
0
        }
11806
0
        if (tmp == NULL) {
11807
0
            tmp = PyList_New(0);
11808
0
            if (tmp == NULL) {
11809
0
                return -1;
11810
0
            }
11811
0
        }
11812
0
        {
11813
0
            int res;
11814
0
            Py_ssize_t len;
11815
0
            Py_ssize_t i;
11816
0
            if (!PyList_Check(tmp)) {
11817
0
                PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %T", tmp);
11818
0
                goto failed;
11819
0
            }
11820
0
            len = PyList_GET_SIZE(tmp);
11821
0
            elts = _Py_asdl_expr_seq_new(len, arena);
11822
0
            if (elts == NULL) goto failed;
11823
0
            for (i = 0; i < len; i++) {
11824
0
                expr_ty val;
11825
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11826
0
                if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
11827
0
                    goto failed;
11828
0
                }
11829
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
11830
0
                _Py_LeaveRecursiveCall();
11831
0
                Py_DECREF(tmp2);
11832
0
                if (res != 0) goto failed;
11833
0
                if (len != PyList_GET_SIZE(tmp)) {
11834
0
                    PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
11835
0
                    goto failed;
11836
0
                }
11837
0
                asdl_seq_SET(elts, i, val);
11838
0
            }
11839
0
            Py_CLEAR(tmp);
11840
0
        }
11841
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11842
0
            return -1;
11843
0
        }
11844
0
        if (tmp == NULL) {
11845
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
11846
0
            return -1;
11847
0
        }
11848
0
        else {
11849
0
            int res;
11850
0
            if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
11851
0
                goto failed;
11852
0
            }
11853
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11854
0
            _Py_LeaveRecursiveCall();
11855
0
            if (res != 0) goto failed;
11856
0
            Py_CLEAR(tmp);
11857
0
        }
11858
0
        *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
11859
0
                           end_col_offset, arena);
11860
0
        if (*out == NULL) goto failed;
11861
0
        return 0;
11862
0
    }
11863
0
    tp = state->Tuple_type;
11864
0
    isinstance = PyObject_IsInstance(obj, tp);
11865
0
    if (isinstance == -1) {
11866
0
        return -1;
11867
0
    }
11868
0
    if (isinstance) {
11869
0
        asdl_expr_seq* elts;
11870
0
        expr_context_ty ctx;
11871
11872
0
        if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
11873
0
            return -1;
11874
0
        }
11875
0
        if (tmp == NULL) {
11876
0
            tmp = PyList_New(0);
11877
0
            if (tmp == NULL) {
11878
0
                return -1;
11879
0
            }
11880
0
        }
11881
0
        {
11882
0
            int res;
11883
0
            Py_ssize_t len;
11884
0
            Py_ssize_t i;
11885
0
            if (!PyList_Check(tmp)) {
11886
0
                PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %T", tmp);
11887
0
                goto failed;
11888
0
            }
11889
0
            len = PyList_GET_SIZE(tmp);
11890
0
            elts = _Py_asdl_expr_seq_new(len, arena);
11891
0
            if (elts == NULL) goto failed;
11892
0
            for (i = 0; i < len; i++) {
11893
0
                expr_ty val;
11894
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11895
0
                if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
11896
0
                    goto failed;
11897
0
                }
11898
0
                res = obj2ast_expr(state, tmp2, &val, "elts", arena);
11899
0
                _Py_LeaveRecursiveCall();
11900
0
                Py_DECREF(tmp2);
11901
0
                if (res != 0) goto failed;
11902
0
                if (len != PyList_GET_SIZE(tmp)) {
11903
0
                    PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
11904
0
                    goto failed;
11905
0
                }
11906
0
                asdl_seq_SET(elts, i, val);
11907
0
            }
11908
0
            Py_CLEAR(tmp);
11909
0
        }
11910
0
        if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
11911
0
            return -1;
11912
0
        }
11913
0
        if (tmp == NULL) {
11914
0
            PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
11915
0
            return -1;
11916
0
        }
11917
0
        else {
11918
0
            int res;
11919
0
            if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
11920
0
                goto failed;
11921
0
            }
11922
0
            res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
11923
0
            _Py_LeaveRecursiveCall();
11924
0
            if (res != 0) goto failed;
11925
0
            Py_CLEAR(tmp);
11926
0
        }
11927
0
        *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
11928
0
                            end_col_offset, arena);
11929
0
        if (*out == NULL) goto failed;
11930
0
        return 0;
11931
0
    }
11932
0
    tp = state->Slice_type;
11933
0
    isinstance = PyObject_IsInstance(obj, tp);
11934
0
    if (isinstance == -1) {
11935
0
        return -1;
11936
0
    }
11937
0
    if (isinstance) {
11938
0
        expr_ty lower;
11939
0
        expr_ty upper;
11940
0
        expr_ty step;
11941
11942
0
        if (PyObject_GetOptionalAttr(obj, state->lower, &tmp) < 0) {
11943
0
            return -1;
11944
0
        }
11945
0
        if (tmp == NULL || tmp == Py_None) {
11946
0
            Py_CLEAR(tmp);
11947
0
            lower = NULL;
11948
0
        }
11949
0
        else {
11950
0
            int res;
11951
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11952
0
                goto failed;
11953
0
            }
11954
0
            res = obj2ast_expr(state, tmp, &lower, "lower", arena);
11955
0
            _Py_LeaveRecursiveCall();
11956
0
            if (res != 0) goto failed;
11957
0
            Py_CLEAR(tmp);
11958
0
        }
11959
0
        if (PyObject_GetOptionalAttr(obj, state->upper, &tmp) < 0) {
11960
0
            return -1;
11961
0
        }
11962
0
        if (tmp == NULL || tmp == Py_None) {
11963
0
            Py_CLEAR(tmp);
11964
0
            upper = NULL;
11965
0
        }
11966
0
        else {
11967
0
            int res;
11968
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11969
0
                goto failed;
11970
0
            }
11971
0
            res = obj2ast_expr(state, tmp, &upper, "upper", arena);
11972
0
            _Py_LeaveRecursiveCall();
11973
0
            if (res != 0) goto failed;
11974
0
            Py_CLEAR(tmp);
11975
0
        }
11976
0
        if (PyObject_GetOptionalAttr(obj, state->step, &tmp) < 0) {
11977
0
            return -1;
11978
0
        }
11979
0
        if (tmp == NULL || tmp == Py_None) {
11980
0
            Py_CLEAR(tmp);
11981
0
            step = NULL;
11982
0
        }
11983
0
        else {
11984
0
            int res;
11985
0
            if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
11986
0
                goto failed;
11987
0
            }
11988
0
            res = obj2ast_expr(state, tmp, &step, "step", arena);
11989
0
            _Py_LeaveRecursiveCall();
11990
0
            if (res != 0) goto failed;
11991
0
            Py_CLEAR(tmp);
11992
0
        }
11993
0
        *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
11994
0
                            end_col_offset, arena);
11995
0
        if (*out == NULL) goto failed;
11996
0
        return 0;
11997
0
    }
11998
11999
0
    PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
12000
0
    failed:
12001
0
    Py_XDECREF(tmp);
12002
0
    return -1;
12003
0
}
12004
12005
int
12006
obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
12007
                     out, const char* field, PyArena* arena)
12008
0
{
12009
0
    int isinstance;
12010
12011
0
    isinstance = PyObject_IsInstance(obj, state->Load_type);
12012
0
    if (isinstance == -1) {
12013
0
        return -1;
12014
0
    }
12015
0
    if (isinstance) {
12016
0
        *out = Load;
12017
0
        return 0;
12018
0
    }
12019
0
    isinstance = PyObject_IsInstance(obj, state->Store_type);
12020
0
    if (isinstance == -1) {
12021
0
        return -1;
12022
0
    }
12023
0
    if (isinstance) {
12024
0
        *out = Store;
12025
0
        return 0;
12026
0
    }
12027
0
    isinstance = PyObject_IsInstance(obj, state->Del_type);
12028
0
    if (isinstance == -1) {
12029
0
        return -1;
12030
0
    }
12031
0
    if (isinstance) {
12032
0
        *out = Del;
12033
0
        return 0;
12034
0
    }
12035
12036
0
    PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
12037
0
    return -1;
12038
0
}
12039
12040
int
12041
obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, const
12042
               char* field, PyArena* arena)
12043
0
{
12044
0
    int isinstance;
12045
12046
0
    isinstance = PyObject_IsInstance(obj, state->And_type);
12047
0
    if (isinstance == -1) {
12048
0
        return -1;
12049
0
    }
12050
0
    if (isinstance) {
12051
0
        *out = And;
12052
0
        return 0;
12053
0
    }
12054
0
    isinstance = PyObject_IsInstance(obj, state->Or_type);
12055
0
    if (isinstance == -1) {
12056
0
        return -1;
12057
0
    }
12058
0
    if (isinstance) {
12059
0
        *out = Or;
12060
0
        return 0;
12061
0
    }
12062
12063
0
    PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
12064
0
    return -1;
12065
0
}
12066
12067
int
12068
obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
12069
                 const char* field, PyArena* arena)
12070
0
{
12071
0
    int isinstance;
12072
12073
0
    isinstance = PyObject_IsInstance(obj, state->Add_type);
12074
0
    if (isinstance == -1) {
12075
0
        return -1;
12076
0
    }
12077
0
    if (isinstance) {
12078
0
        *out = Add;
12079
0
        return 0;
12080
0
    }
12081
0
    isinstance = PyObject_IsInstance(obj, state->Sub_type);
12082
0
    if (isinstance == -1) {
12083
0
        return -1;
12084
0
    }
12085
0
    if (isinstance) {
12086
0
        *out = Sub;
12087
0
        return 0;
12088
0
    }
12089
0
    isinstance = PyObject_IsInstance(obj, state->Mult_type);
12090
0
    if (isinstance == -1) {
12091
0
        return -1;
12092
0
    }
12093
0
    if (isinstance) {
12094
0
        *out = Mult;
12095
0
        return 0;
12096
0
    }
12097
0
    isinstance = PyObject_IsInstance(obj, state->MatMult_type);
12098
0
    if (isinstance == -1) {
12099
0
        return -1;
12100
0
    }
12101
0
    if (isinstance) {
12102
0
        *out = MatMult;
12103
0
        return 0;
12104
0
    }
12105
0
    isinstance = PyObject_IsInstance(obj, state->Div_type);
12106
0
    if (isinstance == -1) {
12107
0
        return -1;
12108
0
    }
12109
0
    if (isinstance) {
12110
0
        *out = Div;
12111
0
        return 0;
12112
0
    }
12113
0
    isinstance = PyObject_IsInstance(obj, state->Mod_type);
12114
0
    if (isinstance == -1) {
12115
0
        return -1;
12116
0
    }
12117
0
    if (isinstance) {
12118
0
        *out = Mod;
12119
0
        return 0;
12120
0
    }
12121
0
    isinstance = PyObject_IsInstance(obj, state->Pow_type);
12122
0
    if (isinstance == -1) {
12123
0
        return -1;
12124
0
    }
12125
0
    if (isinstance) {
12126
0
        *out = Pow;
12127
0
        return 0;
12128
0
    }
12129
0
    isinstance = PyObject_IsInstance(obj, state->LShift_type);
12130
0
    if (isinstance == -1) {
12131
0
        return -1;
12132
0
    }
12133
0
    if (isinstance) {
12134
0
        *out = LShift;
12135
0
        return 0;
12136
0
    }
12137
0
    isinstance = PyObject_IsInstance(obj, state->RShift_type);
12138
0
    if (isinstance == -1) {
12139
0
        return -1;
12140
0
    }
12141
0
    if (isinstance) {
12142
0
        *out = RShift;
12143
0
        return 0;
12144
0
    }
12145
0
    isinstance = PyObject_IsInstance(obj, state->BitOr_type);
12146
0
    if (isinstance == -1) {
12147
0
        return -1;
12148
0
    }
12149
0
    if (isinstance) {
12150
0
        *out = BitOr;
12151
0
        return 0;
12152
0
    }
12153
0
    isinstance = PyObject_IsInstance(obj, state->BitXor_type);
12154
0
    if (isinstance == -1) {
12155
0
        return -1;
12156
0
    }
12157
0
    if (isinstance) {
12158
0
        *out = BitXor;
12159
0
        return 0;
12160
0
    }
12161
0
    isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
12162
0
    if (isinstance == -1) {
12163
0
        return -1;
12164
0
    }
12165
0
    if (isinstance) {
12166
0
        *out = BitAnd;
12167
0
        return 0;
12168
0
    }
12169
0
    isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
12170
0
    if (isinstance == -1) {
12171
0
        return -1;
12172
0
    }
12173
0
    if (isinstance) {
12174
0
        *out = FloorDiv;
12175
0
        return 0;
12176
0
    }
12177
12178
0
    PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
12179
0
    return -1;
12180
0
}
12181
12182
int
12183
obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out, const
12184
                char* field, PyArena* arena)
12185
0
{
12186
0
    int isinstance;
12187
12188
0
    isinstance = PyObject_IsInstance(obj, state->Invert_type);
12189
0
    if (isinstance == -1) {
12190
0
        return -1;
12191
0
    }
12192
0
    if (isinstance) {
12193
0
        *out = Invert;
12194
0
        return 0;
12195
0
    }
12196
0
    isinstance = PyObject_IsInstance(obj, state->Not_type);
12197
0
    if (isinstance == -1) {
12198
0
        return -1;
12199
0
    }
12200
0
    if (isinstance) {
12201
0
        *out = Not;
12202
0
        return 0;
12203
0
    }
12204
0
    isinstance = PyObject_IsInstance(obj, state->UAdd_type);
12205
0
    if (isinstance == -1) {
12206
0
        return -1;
12207
0
    }
12208
0
    if (isinstance) {
12209
0
        *out = UAdd;
12210
0
        return 0;
12211
0
    }
12212
0
    isinstance = PyObject_IsInstance(obj, state->USub_type);
12213
0
    if (isinstance == -1) {
12214
0
        return -1;
12215
0
    }
12216
0
    if (isinstance) {
12217
0
        *out = USub;
12218
0
        return 0;
12219
0
    }
12220
12221
0
    PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
12222
0
    return -1;
12223
0
}
12224
12225
int
12226
obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, const
12227
              char* field, PyArena* arena)
12228
0
{
12229
0
    int isinstance;
12230
12231
0
    isinstance = PyObject_IsInstance(obj, state->Eq_type);
12232
0
    if (isinstance == -1) {
12233
0
        return -1;
12234
0
    }
12235
0
    if (isinstance) {
12236
0
        *out = Eq;
12237
0
        return 0;
12238
0
    }
12239
0
    isinstance = PyObject_IsInstance(obj, state->NotEq_type);
12240
0
    if (isinstance == -1) {
12241
0
        return -1;
12242
0
    }
12243
0
    if (isinstance) {
12244
0
        *out = NotEq;
12245
0
        return 0;
12246
0
    }
12247
0
    isinstance = PyObject_IsInstance(obj, state->Lt_type);
12248
0
    if (isinstance == -1) {
12249
0
        return -1;
12250
0
    }
12251
0
    if (isinstance) {
12252
0
        *out = Lt;
12253
0
        return 0;
12254
0
    }
12255
0
    isinstance = PyObject_IsInstance(obj, state->LtE_type);
12256
0
    if (isinstance == -1) {
12257
0
        return -1;
12258
0
    }
12259
0
    if (isinstance) {
12260
0
        *out = LtE;
12261
0
        return 0;
12262
0
    }
12263
0
    isinstance = PyObject_IsInstance(obj, state->Gt_type);
12264
0
    if (isinstance == -1) {
12265
0
        return -1;
12266
0
    }
12267
0
    if (isinstance) {
12268
0
        *out = Gt;
12269
0
        return 0;
12270
0
    }
12271
0
    isinstance = PyObject_IsInstance(obj, state->GtE_type);
12272
0
    if (isinstance == -1) {
12273
0
        return -1;
12274
0
    }
12275
0
    if (isinstance) {
12276
0
        *out = GtE;
12277
0
        return 0;
12278
0
    }
12279
0
    isinstance = PyObject_IsInstance(obj, state->Is_type);
12280
0
    if (isinstance == -1) {
12281
0
        return -1;
12282
0
    }
12283
0
    if (isinstance) {
12284
0
        *out = Is;
12285
0
        return 0;
12286
0
    }
12287
0
    isinstance = PyObject_IsInstance(obj, state->IsNot_type);
12288
0
    if (isinstance == -1) {
12289
0
        return -1;
12290
0
    }
12291
0
    if (isinstance) {
12292
0
        *out = IsNot;
12293
0
        return 0;
12294
0
    }
12295
0
    isinstance = PyObject_IsInstance(obj, state->In_type);
12296
0
    if (isinstance == -1) {
12297
0
        return -1;
12298
0
    }
12299
0
    if (isinstance) {
12300
0
        *out = In;
12301
0
        return 0;
12302
0
    }
12303
0
    isinstance = PyObject_IsInstance(obj, state->NotIn_type);
12304
0
    if (isinstance == -1) {
12305
0
        return -1;
12306
0
    }
12307
0
    if (isinstance) {
12308
0
        *out = NotIn;
12309
0
        return 0;
12310
0
    }
12311
12312
0
    PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
12313
0
    return -1;
12314
0
}
12315
12316
int
12317
obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
12318
                      out, const char* field, PyArena* arena)
12319
0
{
12320
0
    PyObject* tmp = NULL;
12321
0
    expr_ty target;
12322
0
    expr_ty iter;
12323
0
    asdl_expr_seq* ifs;
12324
0
    int is_async;
12325
12326
0
    if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
12327
0
        return -1;
12328
0
    }
12329
0
    if (tmp == NULL) {
12330
0
        PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
12331
0
        return -1;
12332
0
    }
12333
0
    else {
12334
0
        int res;
12335
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12336
0
            goto failed;
12337
0
        }
12338
0
        res = obj2ast_expr(state, tmp, &target, "target", arena);
12339
0
        _Py_LeaveRecursiveCall();
12340
0
        if (res != 0) goto failed;
12341
0
        Py_CLEAR(tmp);
12342
0
    }
12343
0
    if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
12344
0
        return -1;
12345
0
    }
12346
0
    if (tmp == NULL) {
12347
0
        PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
12348
0
        return -1;
12349
0
    }
12350
0
    else {
12351
0
        int res;
12352
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12353
0
            goto failed;
12354
0
        }
12355
0
        res = obj2ast_expr(state, tmp, &iter, "iter", arena);
12356
0
        _Py_LeaveRecursiveCall();
12357
0
        if (res != 0) goto failed;
12358
0
        Py_CLEAR(tmp);
12359
0
    }
12360
0
    if (PyObject_GetOptionalAttr(obj, state->ifs, &tmp) < 0) {
12361
0
        return -1;
12362
0
    }
12363
0
    if (tmp == NULL) {
12364
0
        tmp = PyList_New(0);
12365
0
        if (tmp == NULL) {
12366
0
            return -1;
12367
0
        }
12368
0
    }
12369
0
    {
12370
0
        int res;
12371
0
        Py_ssize_t len;
12372
0
        Py_ssize_t i;
12373
0
        if (!PyList_Check(tmp)) {
12374
0
            PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %T", tmp);
12375
0
            goto failed;
12376
0
        }
12377
0
        len = PyList_GET_SIZE(tmp);
12378
0
        ifs = _Py_asdl_expr_seq_new(len, arena);
12379
0
        if (ifs == NULL) goto failed;
12380
0
        for (i = 0; i < len; i++) {
12381
0
            expr_ty val;
12382
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12383
0
            if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12384
0
                goto failed;
12385
0
            }
12386
0
            res = obj2ast_expr(state, tmp2, &val, "ifs", arena);
12387
0
            _Py_LeaveRecursiveCall();
12388
0
            Py_DECREF(tmp2);
12389
0
            if (res != 0) goto failed;
12390
0
            if (len != PyList_GET_SIZE(tmp)) {
12391
0
                PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
12392
0
                goto failed;
12393
0
            }
12394
0
            asdl_seq_SET(ifs, i, val);
12395
0
        }
12396
0
        Py_CLEAR(tmp);
12397
0
    }
12398
0
    if (PyObject_GetOptionalAttr(obj, state->is_async, &tmp) < 0) {
12399
0
        return -1;
12400
0
    }
12401
0
    if (tmp == NULL) {
12402
0
        PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
12403
0
        return -1;
12404
0
    }
12405
0
    else {
12406
0
        int res;
12407
0
        if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
12408
0
            goto failed;
12409
0
        }
12410
0
        res = obj2ast_int(state, tmp, &is_async, "is_async", arena);
12411
0
        _Py_LeaveRecursiveCall();
12412
0
        if (res != 0) goto failed;
12413
0
        Py_CLEAR(tmp);
12414
0
    }
12415
0
    *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
12416
0
    if (*out == NULL) goto failed;
12417
0
    return 0;
12418
0
failed:
12419
0
    Py_XDECREF(tmp);
12420
0
    return -1;
12421
0
}
12422
12423
int
12424
obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
12425
                      out, const char* field, PyArena* arena)
12426
0
{
12427
0
    int isinstance;
12428
12429
0
    PyObject *tmp = NULL;
12430
0
    PyObject *tp;
12431
0
    int lineno;
12432
0
    int col_offset;
12433
0
    int end_lineno;
12434
0
    int end_col_offset;
12435
12436
0
    if (obj == Py_None) {
12437
0
        *out = NULL;
12438
0
        return 0;
12439
0
    }
12440
0
    tp = state->excepthandler_type;
12441
0
    isinstance = PyObject_IsInstance(obj, tp);
12442
0
    if (isinstance == -1) {
12443
0
        return 1;
12444
0
    }
12445
0
    if (!isinstance && field != NULL) {
12446
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'excepthandler', got '%T'", field, obj);
12447
0
        return 1;
12448
0
    }
12449
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
12450
0
        return -1;
12451
0
    }
12452
0
    if (tmp == NULL) {
12453
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
12454
0
        return -1;
12455
0
    }
12456
0
    else {
12457
0
        int res;
12458
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12459
0
            goto failed;
12460
0
        }
12461
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
12462
0
        _Py_LeaveRecursiveCall();
12463
0
        if (res != 0) goto failed;
12464
0
        Py_CLEAR(tmp);
12465
0
    }
12466
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
12467
0
        return -1;
12468
0
    }
12469
0
    if (tmp == NULL) {
12470
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
12471
0
        return -1;
12472
0
    }
12473
0
    else {
12474
0
        int res;
12475
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12476
0
            goto failed;
12477
0
        }
12478
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
12479
0
        _Py_LeaveRecursiveCall();
12480
0
        if (res != 0) goto failed;
12481
0
        Py_CLEAR(tmp);
12482
0
    }
12483
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
12484
0
        return -1;
12485
0
    }
12486
0
    if (tmp == NULL || tmp == Py_None) {
12487
0
        Py_CLEAR(tmp);
12488
0
        end_lineno = lineno;
12489
0
    }
12490
0
    else {
12491
0
        int res;
12492
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12493
0
            goto failed;
12494
0
        }
12495
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
12496
0
        _Py_LeaveRecursiveCall();
12497
0
        if (res != 0) goto failed;
12498
0
        Py_CLEAR(tmp);
12499
0
    }
12500
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
12501
0
        return -1;
12502
0
    }
12503
0
    if (tmp == NULL || tmp == Py_None) {
12504
0
        Py_CLEAR(tmp);
12505
0
        end_col_offset = col_offset;
12506
0
    }
12507
0
    else {
12508
0
        int res;
12509
0
        if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
12510
0
            goto failed;
12511
0
        }
12512
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
12513
0
        _Py_LeaveRecursiveCall();
12514
0
        if (res != 0) goto failed;
12515
0
        Py_CLEAR(tmp);
12516
0
    }
12517
0
    tp = state->ExceptHandler_type;
12518
0
    isinstance = PyObject_IsInstance(obj, tp);
12519
0
    if (isinstance == -1) {
12520
0
        return -1;
12521
0
    }
12522
0
    if (isinstance) {
12523
0
        expr_ty type;
12524
0
        identifier name;
12525
0
        asdl_stmt_seq* body;
12526
12527
0
        if (PyObject_GetOptionalAttr(obj, state->type, &tmp) < 0) {
12528
0
            return -1;
12529
0
        }
12530
0
        if (tmp == NULL || tmp == Py_None) {
12531
0
            Py_CLEAR(tmp);
12532
0
            type = NULL;
12533
0
        }
12534
0
        else {
12535
0
            int res;
12536
0
            if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12537
0
                goto failed;
12538
0
            }
12539
0
            res = obj2ast_expr(state, tmp, &type, "type", arena);
12540
0
            _Py_LeaveRecursiveCall();
12541
0
            if (res != 0) goto failed;
12542
0
            Py_CLEAR(tmp);
12543
0
        }
12544
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
12545
0
            return -1;
12546
0
        }
12547
0
        if (tmp == NULL || tmp == Py_None) {
12548
0
            Py_CLEAR(tmp);
12549
0
            name = NULL;
12550
0
        }
12551
0
        else {
12552
0
            int res;
12553
0
            if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12554
0
                goto failed;
12555
0
            }
12556
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
12557
0
            _Py_LeaveRecursiveCall();
12558
0
            if (res != 0) goto failed;
12559
0
            Py_CLEAR(tmp);
12560
0
        }
12561
0
        if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12562
0
            return -1;
12563
0
        }
12564
0
        if (tmp == NULL) {
12565
0
            tmp = PyList_New(0);
12566
0
            if (tmp == NULL) {
12567
0
                return -1;
12568
0
            }
12569
0
        }
12570
0
        {
12571
0
            int res;
12572
0
            Py_ssize_t len;
12573
0
            Py_ssize_t i;
12574
0
            if (!PyList_Check(tmp)) {
12575
0
                PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %T", tmp);
12576
0
                goto failed;
12577
0
            }
12578
0
            len = PyList_GET_SIZE(tmp);
12579
0
            body = _Py_asdl_stmt_seq_new(len, arena);
12580
0
            if (body == NULL) goto failed;
12581
0
            for (i = 0; i < len; i++) {
12582
0
                stmt_ty val;
12583
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12584
0
                if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
12585
0
                    goto failed;
12586
0
                }
12587
0
                res = obj2ast_stmt(state, tmp2, &val, "body", arena);
12588
0
                _Py_LeaveRecursiveCall();
12589
0
                Py_DECREF(tmp2);
12590
0
                if (res != 0) goto failed;
12591
0
                if (len != PyList_GET_SIZE(tmp)) {
12592
0
                    PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
12593
0
                    goto failed;
12594
0
                }
12595
0
                asdl_seq_SET(body, i, val);
12596
0
            }
12597
0
            Py_CLEAR(tmp);
12598
0
        }
12599
0
        *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
12600
0
                                    end_lineno, end_col_offset, arena);
12601
0
        if (*out == NULL) goto failed;
12602
0
        return 0;
12603
0
    }
12604
12605
0
    PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
12606
0
    failed:
12607
0
    Py_XDECREF(tmp);
12608
0
    return -1;
12609
0
}
12610
12611
int
12612
obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
12613
                  const char* field, PyArena* arena)
12614
0
{
12615
0
    PyObject* tmp = NULL;
12616
0
    asdl_arg_seq* posonlyargs;
12617
0
    asdl_arg_seq* args;
12618
0
    arg_ty vararg;
12619
0
    asdl_arg_seq* kwonlyargs;
12620
0
    asdl_expr_seq* kw_defaults;
12621
0
    arg_ty kwarg;
12622
0
    asdl_expr_seq* defaults;
12623
12624
0
    if (PyObject_GetOptionalAttr(obj, state->posonlyargs, &tmp) < 0) {
12625
0
        return -1;
12626
0
    }
12627
0
    if (tmp == NULL) {
12628
0
        tmp = PyList_New(0);
12629
0
        if (tmp == NULL) {
12630
0
            return -1;
12631
0
        }
12632
0
    }
12633
0
    {
12634
0
        int res;
12635
0
        Py_ssize_t len;
12636
0
        Py_ssize_t i;
12637
0
        if (!PyList_Check(tmp)) {
12638
0
            PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %T", tmp);
12639
0
            goto failed;
12640
0
        }
12641
0
        len = PyList_GET_SIZE(tmp);
12642
0
        posonlyargs = _Py_asdl_arg_seq_new(len, arena);
12643
0
        if (posonlyargs == NULL) goto failed;
12644
0
        for (i = 0; i < len; i++) {
12645
0
            arg_ty val;
12646
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12647
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12648
0
                goto failed;
12649
0
            }
12650
0
            res = obj2ast_arg(state, tmp2, &val, "posonlyargs", arena);
12651
0
            _Py_LeaveRecursiveCall();
12652
0
            Py_DECREF(tmp2);
12653
0
            if (res != 0) goto failed;
12654
0
            if (len != PyList_GET_SIZE(tmp)) {
12655
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
12656
0
                goto failed;
12657
0
            }
12658
0
            asdl_seq_SET(posonlyargs, i, val);
12659
0
        }
12660
0
        Py_CLEAR(tmp);
12661
0
    }
12662
0
    if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
12663
0
        return -1;
12664
0
    }
12665
0
    if (tmp == NULL) {
12666
0
        tmp = PyList_New(0);
12667
0
        if (tmp == NULL) {
12668
0
            return -1;
12669
0
        }
12670
0
    }
12671
0
    {
12672
0
        int res;
12673
0
        Py_ssize_t len;
12674
0
        Py_ssize_t i;
12675
0
        if (!PyList_Check(tmp)) {
12676
0
            PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %T", tmp);
12677
0
            goto failed;
12678
0
        }
12679
0
        len = PyList_GET_SIZE(tmp);
12680
0
        args = _Py_asdl_arg_seq_new(len, arena);
12681
0
        if (args == NULL) goto failed;
12682
0
        for (i = 0; i < len; i++) {
12683
0
            arg_ty val;
12684
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12685
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12686
0
                goto failed;
12687
0
            }
12688
0
            res = obj2ast_arg(state, tmp2, &val, "args", arena);
12689
0
            _Py_LeaveRecursiveCall();
12690
0
            Py_DECREF(tmp2);
12691
0
            if (res != 0) goto failed;
12692
0
            if (len != PyList_GET_SIZE(tmp)) {
12693
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
12694
0
                goto failed;
12695
0
            }
12696
0
            asdl_seq_SET(args, i, val);
12697
0
        }
12698
0
        Py_CLEAR(tmp);
12699
0
    }
12700
0
    if (PyObject_GetOptionalAttr(obj, state->vararg, &tmp) < 0) {
12701
0
        return -1;
12702
0
    }
12703
0
    if (tmp == NULL || tmp == Py_None) {
12704
0
        Py_CLEAR(tmp);
12705
0
        vararg = NULL;
12706
0
    }
12707
0
    else {
12708
0
        int res;
12709
0
        if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12710
0
            goto failed;
12711
0
        }
12712
0
        res = obj2ast_arg(state, tmp, &vararg, "vararg", arena);
12713
0
        _Py_LeaveRecursiveCall();
12714
0
        if (res != 0) goto failed;
12715
0
        Py_CLEAR(tmp);
12716
0
    }
12717
0
    if (PyObject_GetOptionalAttr(obj, state->kwonlyargs, &tmp) < 0) {
12718
0
        return -1;
12719
0
    }
12720
0
    if (tmp == NULL) {
12721
0
        tmp = PyList_New(0);
12722
0
        if (tmp == NULL) {
12723
0
            return -1;
12724
0
        }
12725
0
    }
12726
0
    {
12727
0
        int res;
12728
0
        Py_ssize_t len;
12729
0
        Py_ssize_t i;
12730
0
        if (!PyList_Check(tmp)) {
12731
0
            PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %T", tmp);
12732
0
            goto failed;
12733
0
        }
12734
0
        len = PyList_GET_SIZE(tmp);
12735
0
        kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
12736
0
        if (kwonlyargs == NULL) goto failed;
12737
0
        for (i = 0; i < len; i++) {
12738
0
            arg_ty val;
12739
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12740
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12741
0
                goto failed;
12742
0
            }
12743
0
            res = obj2ast_arg(state, tmp2, &val, "kwonlyargs", arena);
12744
0
            _Py_LeaveRecursiveCall();
12745
0
            Py_DECREF(tmp2);
12746
0
            if (res != 0) goto failed;
12747
0
            if (len != PyList_GET_SIZE(tmp)) {
12748
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
12749
0
                goto failed;
12750
0
            }
12751
0
            asdl_seq_SET(kwonlyargs, i, val);
12752
0
        }
12753
0
        Py_CLEAR(tmp);
12754
0
    }
12755
0
    if (PyObject_GetOptionalAttr(obj, state->kw_defaults, &tmp) < 0) {
12756
0
        return -1;
12757
0
    }
12758
0
    if (tmp == NULL) {
12759
0
        tmp = PyList_New(0);
12760
0
        if (tmp == NULL) {
12761
0
            return -1;
12762
0
        }
12763
0
    }
12764
0
    {
12765
0
        int res;
12766
0
        Py_ssize_t len;
12767
0
        Py_ssize_t i;
12768
0
        if (!PyList_Check(tmp)) {
12769
0
            PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %T", tmp);
12770
0
            goto failed;
12771
0
        }
12772
0
        len = PyList_GET_SIZE(tmp);
12773
0
        kw_defaults = _Py_asdl_expr_seq_new(len, arena);
12774
0
        if (kw_defaults == NULL) goto failed;
12775
0
        for (i = 0; i < len; i++) {
12776
0
            expr_ty val;
12777
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12778
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12779
0
                goto failed;
12780
0
            }
12781
0
            res = obj2ast_expr(state, tmp2, &val, "kw_defaults", arena);
12782
0
            _Py_LeaveRecursiveCall();
12783
0
            Py_DECREF(tmp2);
12784
0
            if (res != 0) goto failed;
12785
0
            if (len != PyList_GET_SIZE(tmp)) {
12786
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
12787
0
                goto failed;
12788
0
            }
12789
0
            asdl_seq_SET(kw_defaults, i, val);
12790
0
        }
12791
0
        Py_CLEAR(tmp);
12792
0
    }
12793
0
    if (PyObject_GetOptionalAttr(obj, state->kwarg, &tmp) < 0) {
12794
0
        return -1;
12795
0
    }
12796
0
    if (tmp == NULL || tmp == Py_None) {
12797
0
        Py_CLEAR(tmp);
12798
0
        kwarg = NULL;
12799
0
    }
12800
0
    else {
12801
0
        int res;
12802
0
        if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12803
0
            goto failed;
12804
0
        }
12805
0
        res = obj2ast_arg(state, tmp, &kwarg, "kwarg", arena);
12806
0
        _Py_LeaveRecursiveCall();
12807
0
        if (res != 0) goto failed;
12808
0
        Py_CLEAR(tmp);
12809
0
    }
12810
0
    if (PyObject_GetOptionalAttr(obj, state->defaults, &tmp) < 0) {
12811
0
        return -1;
12812
0
    }
12813
0
    if (tmp == NULL) {
12814
0
        tmp = PyList_New(0);
12815
0
        if (tmp == NULL) {
12816
0
            return -1;
12817
0
        }
12818
0
    }
12819
0
    {
12820
0
        int res;
12821
0
        Py_ssize_t len;
12822
0
        Py_ssize_t i;
12823
0
        if (!PyList_Check(tmp)) {
12824
0
            PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %T", tmp);
12825
0
            goto failed;
12826
0
        }
12827
0
        len = PyList_GET_SIZE(tmp);
12828
0
        defaults = _Py_asdl_expr_seq_new(len, arena);
12829
0
        if (defaults == NULL) goto failed;
12830
0
        for (i = 0; i < len; i++) {
12831
0
            expr_ty val;
12832
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12833
0
            if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
12834
0
                goto failed;
12835
0
            }
12836
0
            res = obj2ast_expr(state, tmp2, &val, "defaults", arena);
12837
0
            _Py_LeaveRecursiveCall();
12838
0
            Py_DECREF(tmp2);
12839
0
            if (res != 0) goto failed;
12840
0
            if (len != PyList_GET_SIZE(tmp)) {
12841
0
                PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
12842
0
                goto failed;
12843
0
            }
12844
0
            asdl_seq_SET(defaults, i, val);
12845
0
        }
12846
0
        Py_CLEAR(tmp);
12847
0
    }
12848
0
    *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
12849
0
                            kwarg, defaults, arena);
12850
0
    if (*out == NULL) goto failed;
12851
0
    return 0;
12852
0
failed:
12853
0
    Py_XDECREF(tmp);
12854
0
    return -1;
12855
0
}
12856
12857
int
12858
obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, const char*
12859
            field, PyArena* arena)
12860
0
{
12861
0
    PyObject* tmp = NULL;
12862
0
    identifier arg;
12863
0
    expr_ty annotation;
12864
0
    string type_comment;
12865
0
    int lineno;
12866
0
    int col_offset;
12867
0
    int end_lineno;
12868
0
    int end_col_offset;
12869
12870
0
    if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
12871
0
        return -1;
12872
0
    }
12873
0
    if (tmp == NULL) {
12874
0
        PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
12875
0
        return -1;
12876
0
    }
12877
0
    else {
12878
0
        int res;
12879
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12880
0
            goto failed;
12881
0
        }
12882
0
        res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
12883
0
        _Py_LeaveRecursiveCall();
12884
0
        if (res != 0) goto failed;
12885
0
        Py_CLEAR(tmp);
12886
0
    }
12887
0
    if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
12888
0
        return -1;
12889
0
    }
12890
0
    if (tmp == NULL || tmp == Py_None) {
12891
0
        Py_CLEAR(tmp);
12892
0
        annotation = NULL;
12893
0
    }
12894
0
    else {
12895
0
        int res;
12896
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12897
0
            goto failed;
12898
0
        }
12899
0
        res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
12900
0
        _Py_LeaveRecursiveCall();
12901
0
        if (res != 0) goto failed;
12902
0
        Py_CLEAR(tmp);
12903
0
    }
12904
0
    if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
12905
0
        return -1;
12906
0
    }
12907
0
    if (tmp == NULL || tmp == Py_None) {
12908
0
        Py_CLEAR(tmp);
12909
0
        type_comment = NULL;
12910
0
    }
12911
0
    else {
12912
0
        int res;
12913
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12914
0
            goto failed;
12915
0
        }
12916
0
        res = obj2ast_string(state, tmp, &type_comment, "type_comment", arena);
12917
0
        _Py_LeaveRecursiveCall();
12918
0
        if (res != 0) goto failed;
12919
0
        Py_CLEAR(tmp);
12920
0
    }
12921
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
12922
0
        return -1;
12923
0
    }
12924
0
    if (tmp == NULL) {
12925
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
12926
0
        return -1;
12927
0
    }
12928
0
    else {
12929
0
        int res;
12930
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12931
0
            goto failed;
12932
0
        }
12933
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
12934
0
        _Py_LeaveRecursiveCall();
12935
0
        if (res != 0) goto failed;
12936
0
        Py_CLEAR(tmp);
12937
0
    }
12938
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
12939
0
        return -1;
12940
0
    }
12941
0
    if (tmp == NULL) {
12942
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
12943
0
        return -1;
12944
0
    }
12945
0
    else {
12946
0
        int res;
12947
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12948
0
            goto failed;
12949
0
        }
12950
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
12951
0
        _Py_LeaveRecursiveCall();
12952
0
        if (res != 0) goto failed;
12953
0
        Py_CLEAR(tmp);
12954
0
    }
12955
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
12956
0
        return -1;
12957
0
    }
12958
0
    if (tmp == NULL || tmp == Py_None) {
12959
0
        Py_CLEAR(tmp);
12960
0
        end_lineno = lineno;
12961
0
    }
12962
0
    else {
12963
0
        int res;
12964
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12965
0
            goto failed;
12966
0
        }
12967
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
12968
0
        _Py_LeaveRecursiveCall();
12969
0
        if (res != 0) goto failed;
12970
0
        Py_CLEAR(tmp);
12971
0
    }
12972
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
12973
0
        return -1;
12974
0
    }
12975
0
    if (tmp == NULL || tmp == Py_None) {
12976
0
        Py_CLEAR(tmp);
12977
0
        end_col_offset = col_offset;
12978
0
    }
12979
0
    else {
12980
0
        int res;
12981
0
        if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
12982
0
            goto failed;
12983
0
        }
12984
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
12985
0
        _Py_LeaveRecursiveCall();
12986
0
        if (res != 0) goto failed;
12987
0
        Py_CLEAR(tmp);
12988
0
    }
12989
0
    *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
12990
0
                      end_lineno, end_col_offset, arena);
12991
0
    if (*out == NULL) goto failed;
12992
0
    return 0;
12993
0
failed:
12994
0
    Py_XDECREF(tmp);
12995
0
    return -1;
12996
0
}
12997
12998
int
12999
obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out, const
13000
                char* field, PyArena* arena)
13001
0
{
13002
0
    PyObject* tmp = NULL;
13003
0
    identifier arg;
13004
0
    expr_ty value;
13005
0
    int lineno;
13006
0
    int col_offset;
13007
0
    int end_lineno;
13008
0
    int end_col_offset;
13009
13010
0
    if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
13011
0
        return -1;
13012
0
    }
13013
0
    if (tmp == NULL || tmp == Py_None) {
13014
0
        Py_CLEAR(tmp);
13015
0
        arg = NULL;
13016
0
    }
13017
0
    else {
13018
0
        int res;
13019
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13020
0
            goto failed;
13021
0
        }
13022
0
        res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
13023
0
        _Py_LeaveRecursiveCall();
13024
0
        if (res != 0) goto failed;
13025
0
        Py_CLEAR(tmp);
13026
0
    }
13027
0
    if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13028
0
        return -1;
13029
0
    }
13030
0
    if (tmp == NULL) {
13031
0
        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
13032
0
        return -1;
13033
0
    }
13034
0
    else {
13035
0
        int res;
13036
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13037
0
            goto failed;
13038
0
        }
13039
0
        res = obj2ast_expr(state, tmp, &value, "value", arena);
13040
0
        _Py_LeaveRecursiveCall();
13041
0
        if (res != 0) goto failed;
13042
0
        Py_CLEAR(tmp);
13043
0
    }
13044
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13045
0
        return -1;
13046
0
    }
13047
0
    if (tmp == NULL) {
13048
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
13049
0
        return -1;
13050
0
    }
13051
0
    else {
13052
0
        int res;
13053
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13054
0
            goto failed;
13055
0
        }
13056
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13057
0
        _Py_LeaveRecursiveCall();
13058
0
        if (res != 0) goto failed;
13059
0
        Py_CLEAR(tmp);
13060
0
    }
13061
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13062
0
        return -1;
13063
0
    }
13064
0
    if (tmp == NULL) {
13065
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
13066
0
        return -1;
13067
0
    }
13068
0
    else {
13069
0
        int res;
13070
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13071
0
            goto failed;
13072
0
        }
13073
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13074
0
        _Py_LeaveRecursiveCall();
13075
0
        if (res != 0) goto failed;
13076
0
        Py_CLEAR(tmp);
13077
0
    }
13078
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13079
0
        return -1;
13080
0
    }
13081
0
    if (tmp == NULL || tmp == Py_None) {
13082
0
        Py_CLEAR(tmp);
13083
0
        end_lineno = lineno;
13084
0
    }
13085
0
    else {
13086
0
        int res;
13087
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13088
0
            goto failed;
13089
0
        }
13090
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13091
0
        _Py_LeaveRecursiveCall();
13092
0
        if (res != 0) goto failed;
13093
0
        Py_CLEAR(tmp);
13094
0
    }
13095
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13096
0
        return -1;
13097
0
    }
13098
0
    if (tmp == NULL || tmp == Py_None) {
13099
0
        Py_CLEAR(tmp);
13100
0
        end_col_offset = col_offset;
13101
0
    }
13102
0
    else {
13103
0
        int res;
13104
0
        if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
13105
0
            goto failed;
13106
0
        }
13107
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13108
0
        _Py_LeaveRecursiveCall();
13109
0
        if (res != 0) goto failed;
13110
0
        Py_CLEAR(tmp);
13111
0
    }
13112
0
    *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
13113
0
                          end_col_offset, arena);
13114
0
    if (*out == NULL) goto failed;
13115
0
    return 0;
13116
0
failed:
13117
0
    Py_XDECREF(tmp);
13118
0
    return -1;
13119
0
}
13120
13121
int
13122
obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, const
13123
              char* field, PyArena* arena)
13124
0
{
13125
0
    PyObject* tmp = NULL;
13126
0
    identifier name;
13127
0
    identifier asname;
13128
0
    int lineno;
13129
0
    int col_offset;
13130
0
    int end_lineno;
13131
0
    int end_col_offset;
13132
13133
0
    if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13134
0
        return -1;
13135
0
    }
13136
0
    if (tmp == NULL) {
13137
0
        PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
13138
0
        return -1;
13139
0
    }
13140
0
    else {
13141
0
        int res;
13142
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13143
0
            goto failed;
13144
0
        }
13145
0
        res = obj2ast_identifier(state, tmp, &name, "name", arena);
13146
0
        _Py_LeaveRecursiveCall();
13147
0
        if (res != 0) goto failed;
13148
0
        Py_CLEAR(tmp);
13149
0
    }
13150
0
    if (PyObject_GetOptionalAttr(obj, state->asname, &tmp) < 0) {
13151
0
        return -1;
13152
0
    }
13153
0
    if (tmp == NULL || tmp == Py_None) {
13154
0
        Py_CLEAR(tmp);
13155
0
        asname = NULL;
13156
0
    }
13157
0
    else {
13158
0
        int res;
13159
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13160
0
            goto failed;
13161
0
        }
13162
0
        res = obj2ast_identifier(state, tmp, &asname, "asname", arena);
13163
0
        _Py_LeaveRecursiveCall();
13164
0
        if (res != 0) goto failed;
13165
0
        Py_CLEAR(tmp);
13166
0
    }
13167
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13168
0
        return -1;
13169
0
    }
13170
0
    if (tmp == NULL) {
13171
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
13172
0
        return -1;
13173
0
    }
13174
0
    else {
13175
0
        int res;
13176
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13177
0
            goto failed;
13178
0
        }
13179
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13180
0
        _Py_LeaveRecursiveCall();
13181
0
        if (res != 0) goto failed;
13182
0
        Py_CLEAR(tmp);
13183
0
    }
13184
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13185
0
        return -1;
13186
0
    }
13187
0
    if (tmp == NULL) {
13188
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
13189
0
        return -1;
13190
0
    }
13191
0
    else {
13192
0
        int res;
13193
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13194
0
            goto failed;
13195
0
        }
13196
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13197
0
        _Py_LeaveRecursiveCall();
13198
0
        if (res != 0) goto failed;
13199
0
        Py_CLEAR(tmp);
13200
0
    }
13201
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13202
0
        return -1;
13203
0
    }
13204
0
    if (tmp == NULL || tmp == Py_None) {
13205
0
        Py_CLEAR(tmp);
13206
0
        end_lineno = lineno;
13207
0
    }
13208
0
    else {
13209
0
        int res;
13210
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13211
0
            goto failed;
13212
0
        }
13213
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13214
0
        _Py_LeaveRecursiveCall();
13215
0
        if (res != 0) goto failed;
13216
0
        Py_CLEAR(tmp);
13217
0
    }
13218
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13219
0
        return -1;
13220
0
    }
13221
0
    if (tmp == NULL || tmp == Py_None) {
13222
0
        Py_CLEAR(tmp);
13223
0
        end_col_offset = col_offset;
13224
0
    }
13225
0
    else {
13226
0
        int res;
13227
0
        if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
13228
0
            goto failed;
13229
0
        }
13230
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13231
0
        _Py_LeaveRecursiveCall();
13232
0
        if (res != 0) goto failed;
13233
0
        Py_CLEAR(tmp);
13234
0
    }
13235
0
    *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
13236
0
                        end_col_offset, arena);
13237
0
    if (*out == NULL) goto failed;
13238
0
    return 0;
13239
0
failed:
13240
0
    Py_XDECREF(tmp);
13241
0
    return -1;
13242
0
}
13243
13244
int
13245
obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
13246
                 const char* field, PyArena* arena)
13247
0
{
13248
0
    PyObject* tmp = NULL;
13249
0
    expr_ty context_expr;
13250
0
    expr_ty optional_vars;
13251
13252
0
    if (PyObject_GetOptionalAttr(obj, state->context_expr, &tmp) < 0) {
13253
0
        return -1;
13254
0
    }
13255
0
    if (tmp == NULL) {
13256
0
        PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
13257
0
        return -1;
13258
0
    }
13259
0
    else {
13260
0
        int res;
13261
0
        if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
13262
0
            goto failed;
13263
0
        }
13264
0
        res = obj2ast_expr(state, tmp, &context_expr, "context_expr", arena);
13265
0
        _Py_LeaveRecursiveCall();
13266
0
        if (res != 0) goto failed;
13267
0
        Py_CLEAR(tmp);
13268
0
    }
13269
0
    if (PyObject_GetOptionalAttr(obj, state->optional_vars, &tmp) < 0) {
13270
0
        return -1;
13271
0
    }
13272
0
    if (tmp == NULL || tmp == Py_None) {
13273
0
        Py_CLEAR(tmp);
13274
0
        optional_vars = NULL;
13275
0
    }
13276
0
    else {
13277
0
        int res;
13278
0
        if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
13279
0
            goto failed;
13280
0
        }
13281
0
        res = obj2ast_expr(state, tmp, &optional_vars, "optional_vars", arena);
13282
0
        _Py_LeaveRecursiveCall();
13283
0
        if (res != 0) goto failed;
13284
0
        Py_CLEAR(tmp);
13285
0
    }
13286
0
    *out = _PyAST_withitem(context_expr, optional_vars, arena);
13287
0
    if (*out == NULL) goto failed;
13288
0
    return 0;
13289
0
failed:
13290
0
    Py_XDECREF(tmp);
13291
0
    return -1;
13292
0
}
13293
13294
int
13295
obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
13296
                   const char* field, PyArena* arena)
13297
0
{
13298
0
    PyObject* tmp = NULL;
13299
0
    pattern_ty pattern;
13300
0
    expr_ty guard;
13301
0
    asdl_stmt_seq* body;
13302
13303
0
    if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
13304
0
        return -1;
13305
0
    }
13306
0
    if (tmp == NULL) {
13307
0
        PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
13308
0
        return -1;
13309
0
    }
13310
0
    else {
13311
0
        int res;
13312
0
        if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13313
0
            goto failed;
13314
0
        }
13315
0
        res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
13316
0
        _Py_LeaveRecursiveCall();
13317
0
        if (res != 0) goto failed;
13318
0
        Py_CLEAR(tmp);
13319
0
    }
13320
0
    if (PyObject_GetOptionalAttr(obj, state->guard, &tmp) < 0) {
13321
0
        return -1;
13322
0
    }
13323
0
    if (tmp == NULL || tmp == Py_None) {
13324
0
        Py_CLEAR(tmp);
13325
0
        guard = NULL;
13326
0
    }
13327
0
    else {
13328
0
        int res;
13329
0
        if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13330
0
            goto failed;
13331
0
        }
13332
0
        res = obj2ast_expr(state, tmp, &guard, "guard", arena);
13333
0
        _Py_LeaveRecursiveCall();
13334
0
        if (res != 0) goto failed;
13335
0
        Py_CLEAR(tmp);
13336
0
    }
13337
0
    if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
13338
0
        return -1;
13339
0
    }
13340
0
    if (tmp == NULL) {
13341
0
        tmp = PyList_New(0);
13342
0
        if (tmp == NULL) {
13343
0
            return -1;
13344
0
        }
13345
0
    }
13346
0
    {
13347
0
        int res;
13348
0
        Py_ssize_t len;
13349
0
        Py_ssize_t i;
13350
0
        if (!PyList_Check(tmp)) {
13351
0
            PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %T", tmp);
13352
0
            goto failed;
13353
0
        }
13354
0
        len = PyList_GET_SIZE(tmp);
13355
0
        body = _Py_asdl_stmt_seq_new(len, arena);
13356
0
        if (body == NULL) goto failed;
13357
0
        for (i = 0; i < len; i++) {
13358
0
            stmt_ty val;
13359
0
            PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13360
0
            if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
13361
0
                goto failed;
13362
0
            }
13363
0
            res = obj2ast_stmt(state, tmp2, &val, "body", arena);
13364
0
            _Py_LeaveRecursiveCall();
13365
0
            Py_DECREF(tmp2);
13366
0
            if (res != 0) goto failed;
13367
0
            if (len != PyList_GET_SIZE(tmp)) {
13368
0
                PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
13369
0
                goto failed;
13370
0
            }
13371
0
            asdl_seq_SET(body, i, val);
13372
0
        }
13373
0
        Py_CLEAR(tmp);
13374
0
    }
13375
0
    *out = _PyAST_match_case(pattern, guard, body, arena);
13376
0
    if (*out == NULL) goto failed;
13377
0
    return 0;
13378
0
failed:
13379
0
    Py_XDECREF(tmp);
13380
0
    return -1;
13381
0
}
13382
13383
int
13384
obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out, const
13385
                char* field, PyArena* arena)
13386
0
{
13387
0
    int isinstance;
13388
13389
0
    PyObject *tmp = NULL;
13390
0
    PyObject *tp;
13391
0
    int lineno;
13392
0
    int col_offset;
13393
0
    int end_lineno;
13394
0
    int end_col_offset;
13395
13396
0
    if (obj == Py_None) {
13397
0
        *out = NULL;
13398
0
        return 0;
13399
0
    }
13400
0
    tp = state->pattern_type;
13401
0
    isinstance = PyObject_IsInstance(obj, tp);
13402
0
    if (isinstance == -1) {
13403
0
        return 1;
13404
0
    }
13405
0
    if (!isinstance && field != NULL) {
13406
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'pattern', got '%T'", field, obj);
13407
0
        return 1;
13408
0
    }
13409
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13410
0
        return -1;
13411
0
    }
13412
0
    if (tmp == NULL) {
13413
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
13414
0
        return -1;
13415
0
    }
13416
0
    else {
13417
0
        int res;
13418
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13419
0
            goto failed;
13420
0
        }
13421
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
13422
0
        _Py_LeaveRecursiveCall();
13423
0
        if (res != 0) goto failed;
13424
0
        Py_CLEAR(tmp);
13425
0
    }
13426
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13427
0
        return -1;
13428
0
    }
13429
0
    if (tmp == NULL) {
13430
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
13431
0
        return -1;
13432
0
    }
13433
0
    else {
13434
0
        int res;
13435
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13436
0
            goto failed;
13437
0
        }
13438
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
13439
0
        _Py_LeaveRecursiveCall();
13440
0
        if (res != 0) goto failed;
13441
0
        Py_CLEAR(tmp);
13442
0
    }
13443
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13444
0
        return -1;
13445
0
    }
13446
0
    if (tmp == NULL) {
13447
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
13448
0
        return -1;
13449
0
    }
13450
0
    else {
13451
0
        int res;
13452
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13453
0
            goto failed;
13454
0
        }
13455
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
13456
0
        _Py_LeaveRecursiveCall();
13457
0
        if (res != 0) goto failed;
13458
0
        Py_CLEAR(tmp);
13459
0
    }
13460
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13461
0
        return -1;
13462
0
    }
13463
0
    if (tmp == NULL) {
13464
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
13465
0
        return -1;
13466
0
    }
13467
0
    else {
13468
0
        int res;
13469
0
        if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
13470
0
            goto failed;
13471
0
        }
13472
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
13473
0
        _Py_LeaveRecursiveCall();
13474
0
        if (res != 0) goto failed;
13475
0
        Py_CLEAR(tmp);
13476
0
    }
13477
0
    tp = state->MatchValue_type;
13478
0
    isinstance = PyObject_IsInstance(obj, tp);
13479
0
    if (isinstance == -1) {
13480
0
        return -1;
13481
0
    }
13482
0
    if (isinstance) {
13483
0
        expr_ty value;
13484
13485
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13486
0
            return -1;
13487
0
        }
13488
0
        if (tmp == NULL) {
13489
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
13490
0
            return -1;
13491
0
        }
13492
0
        else {
13493
0
            int res;
13494
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
13495
0
                goto failed;
13496
0
            }
13497
0
            res = obj2ast_expr(state, tmp, &value, "value", arena);
13498
0
            _Py_LeaveRecursiveCall();
13499
0
            if (res != 0) goto failed;
13500
0
            Py_CLEAR(tmp);
13501
0
        }
13502
0
        *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
13503
0
                                 end_col_offset, arena);
13504
0
        if (*out == NULL) goto failed;
13505
0
        return 0;
13506
0
    }
13507
0
    tp = state->MatchSingleton_type;
13508
0
    isinstance = PyObject_IsInstance(obj, tp);
13509
0
    if (isinstance == -1) {
13510
0
        return -1;
13511
0
    }
13512
0
    if (isinstance) {
13513
0
        constant value;
13514
13515
0
        if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13516
0
            return -1;
13517
0
        }
13518
0
        if (tmp == NULL) {
13519
0
            PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
13520
0
            return -1;
13521
0
        }
13522
0
        else {
13523
0
            int res;
13524
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
13525
0
                goto failed;
13526
0
            }
13527
0
            res = obj2ast_constant(state, tmp, &value, "value", arena);
13528
0
            _Py_LeaveRecursiveCall();
13529
0
            if (res != 0) goto failed;
13530
0
            Py_CLEAR(tmp);
13531
0
        }
13532
0
        *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
13533
0
                                     end_col_offset, arena);
13534
0
        if (*out == NULL) goto failed;
13535
0
        return 0;
13536
0
    }
13537
0
    tp = state->MatchSequence_type;
13538
0
    isinstance = PyObject_IsInstance(obj, tp);
13539
0
    if (isinstance == -1) {
13540
0
        return -1;
13541
0
    }
13542
0
    if (isinstance) {
13543
0
        asdl_pattern_seq* patterns;
13544
13545
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13546
0
            return -1;
13547
0
        }
13548
0
        if (tmp == NULL) {
13549
0
            tmp = PyList_New(0);
13550
0
            if (tmp == NULL) {
13551
0
                return -1;
13552
0
            }
13553
0
        }
13554
0
        {
13555
0
            int res;
13556
0
            Py_ssize_t len;
13557
0
            Py_ssize_t i;
13558
0
            if (!PyList_Check(tmp)) {
13559
0
                PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %T", tmp);
13560
0
                goto failed;
13561
0
            }
13562
0
            len = PyList_GET_SIZE(tmp);
13563
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13564
0
            if (patterns == NULL) goto failed;
13565
0
            for (i = 0; i < len; i++) {
13566
0
                pattern_ty val;
13567
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13568
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
13569
0
                    goto failed;
13570
0
                }
13571
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13572
0
                _Py_LeaveRecursiveCall();
13573
0
                Py_DECREF(tmp2);
13574
0
                if (res != 0) goto failed;
13575
0
                if (len != PyList_GET_SIZE(tmp)) {
13576
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
13577
0
                    goto failed;
13578
0
                }
13579
0
                asdl_seq_SET(patterns, i, val);
13580
0
            }
13581
0
            Py_CLEAR(tmp);
13582
0
        }
13583
0
        *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
13584
0
                                    end_col_offset, arena);
13585
0
        if (*out == NULL) goto failed;
13586
0
        return 0;
13587
0
    }
13588
0
    tp = state->MatchMapping_type;
13589
0
    isinstance = PyObject_IsInstance(obj, tp);
13590
0
    if (isinstance == -1) {
13591
0
        return -1;
13592
0
    }
13593
0
    if (isinstance) {
13594
0
        asdl_expr_seq* keys;
13595
0
        asdl_pattern_seq* patterns;
13596
0
        identifier rest;
13597
13598
0
        if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
13599
0
            return -1;
13600
0
        }
13601
0
        if (tmp == NULL) {
13602
0
            tmp = PyList_New(0);
13603
0
            if (tmp == NULL) {
13604
0
                return -1;
13605
0
            }
13606
0
        }
13607
0
        {
13608
0
            int res;
13609
0
            Py_ssize_t len;
13610
0
            Py_ssize_t i;
13611
0
            if (!PyList_Check(tmp)) {
13612
0
                PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %T", tmp);
13613
0
                goto failed;
13614
0
            }
13615
0
            len = PyList_GET_SIZE(tmp);
13616
0
            keys = _Py_asdl_expr_seq_new(len, arena);
13617
0
            if (keys == NULL) goto failed;
13618
0
            for (i = 0; i < len; i++) {
13619
0
                expr_ty val;
13620
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13621
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13622
0
                    goto failed;
13623
0
                }
13624
0
                res = obj2ast_expr(state, tmp2, &val, "keys", arena);
13625
0
                _Py_LeaveRecursiveCall();
13626
0
                Py_DECREF(tmp2);
13627
0
                if (res != 0) goto failed;
13628
0
                if (len != PyList_GET_SIZE(tmp)) {
13629
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
13630
0
                    goto failed;
13631
0
                }
13632
0
                asdl_seq_SET(keys, i, val);
13633
0
            }
13634
0
            Py_CLEAR(tmp);
13635
0
        }
13636
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13637
0
            return -1;
13638
0
        }
13639
0
        if (tmp == NULL) {
13640
0
            tmp = PyList_New(0);
13641
0
            if (tmp == NULL) {
13642
0
                return -1;
13643
0
            }
13644
0
        }
13645
0
        {
13646
0
            int res;
13647
0
            Py_ssize_t len;
13648
0
            Py_ssize_t i;
13649
0
            if (!PyList_Check(tmp)) {
13650
0
                PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %T", tmp);
13651
0
                goto failed;
13652
0
            }
13653
0
            len = PyList_GET_SIZE(tmp);
13654
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13655
0
            if (patterns == NULL) goto failed;
13656
0
            for (i = 0; i < len; i++) {
13657
0
                pattern_ty val;
13658
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13659
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13660
0
                    goto failed;
13661
0
                }
13662
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13663
0
                _Py_LeaveRecursiveCall();
13664
0
                Py_DECREF(tmp2);
13665
0
                if (res != 0) goto failed;
13666
0
                if (len != PyList_GET_SIZE(tmp)) {
13667
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
13668
0
                    goto failed;
13669
0
                }
13670
0
                asdl_seq_SET(patterns, i, val);
13671
0
            }
13672
0
            Py_CLEAR(tmp);
13673
0
        }
13674
0
        if (PyObject_GetOptionalAttr(obj, state->rest, &tmp) < 0) {
13675
0
            return -1;
13676
0
        }
13677
0
        if (tmp == NULL || tmp == Py_None) {
13678
0
            Py_CLEAR(tmp);
13679
0
            rest = NULL;
13680
0
        }
13681
0
        else {
13682
0
            int res;
13683
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
13684
0
                goto failed;
13685
0
            }
13686
0
            res = obj2ast_identifier(state, tmp, &rest, "rest", arena);
13687
0
            _Py_LeaveRecursiveCall();
13688
0
            if (res != 0) goto failed;
13689
0
            Py_CLEAR(tmp);
13690
0
        }
13691
0
        *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
13692
0
                                   end_lineno, end_col_offset, arena);
13693
0
        if (*out == NULL) goto failed;
13694
0
        return 0;
13695
0
    }
13696
0
    tp = state->MatchClass_type;
13697
0
    isinstance = PyObject_IsInstance(obj, tp);
13698
0
    if (isinstance == -1) {
13699
0
        return -1;
13700
0
    }
13701
0
    if (isinstance) {
13702
0
        expr_ty cls;
13703
0
        asdl_pattern_seq* patterns;
13704
0
        asdl_identifier_seq* kwd_attrs;
13705
0
        asdl_pattern_seq* kwd_patterns;
13706
13707
0
        if (PyObject_GetOptionalAttr(obj, state->cls, &tmp) < 0) {
13708
0
            return -1;
13709
0
        }
13710
0
        if (tmp == NULL) {
13711
0
            PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
13712
0
            return -1;
13713
0
        }
13714
0
        else {
13715
0
            int res;
13716
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13717
0
                goto failed;
13718
0
            }
13719
0
            res = obj2ast_expr(state, tmp, &cls, "cls", arena);
13720
0
            _Py_LeaveRecursiveCall();
13721
0
            if (res != 0) goto failed;
13722
0
            Py_CLEAR(tmp);
13723
0
        }
13724
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13725
0
            return -1;
13726
0
        }
13727
0
        if (tmp == NULL) {
13728
0
            tmp = PyList_New(0);
13729
0
            if (tmp == NULL) {
13730
0
                return -1;
13731
0
            }
13732
0
        }
13733
0
        {
13734
0
            int res;
13735
0
            Py_ssize_t len;
13736
0
            Py_ssize_t i;
13737
0
            if (!PyList_Check(tmp)) {
13738
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %T", tmp);
13739
0
                goto failed;
13740
0
            }
13741
0
            len = PyList_GET_SIZE(tmp);
13742
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13743
0
            if (patterns == NULL) goto failed;
13744
0
            for (i = 0; i < len; i++) {
13745
0
                pattern_ty val;
13746
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13747
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13748
0
                    goto failed;
13749
0
                }
13750
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13751
0
                _Py_LeaveRecursiveCall();
13752
0
                Py_DECREF(tmp2);
13753
0
                if (res != 0) goto failed;
13754
0
                if (len != PyList_GET_SIZE(tmp)) {
13755
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
13756
0
                    goto failed;
13757
0
                }
13758
0
                asdl_seq_SET(patterns, i, val);
13759
0
            }
13760
0
            Py_CLEAR(tmp);
13761
0
        }
13762
0
        if (PyObject_GetOptionalAttr(obj, state->kwd_attrs, &tmp) < 0) {
13763
0
            return -1;
13764
0
        }
13765
0
        if (tmp == NULL) {
13766
0
            tmp = PyList_New(0);
13767
0
            if (tmp == NULL) {
13768
0
                return -1;
13769
0
            }
13770
0
        }
13771
0
        {
13772
0
            int res;
13773
0
            Py_ssize_t len;
13774
0
            Py_ssize_t i;
13775
0
            if (!PyList_Check(tmp)) {
13776
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %T", tmp);
13777
0
                goto failed;
13778
0
            }
13779
0
            len = PyList_GET_SIZE(tmp);
13780
0
            kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
13781
0
            if (kwd_attrs == NULL) goto failed;
13782
0
            for (i = 0; i < len; i++) {
13783
0
                identifier val;
13784
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13785
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13786
0
                    goto failed;
13787
0
                }
13788
0
                res = obj2ast_identifier(state, tmp2, &val, "kwd_attrs", arena);
13789
0
                _Py_LeaveRecursiveCall();
13790
0
                Py_DECREF(tmp2);
13791
0
                if (res != 0) goto failed;
13792
0
                if (len != PyList_GET_SIZE(tmp)) {
13793
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
13794
0
                    goto failed;
13795
0
                }
13796
0
                asdl_seq_SET(kwd_attrs, i, val);
13797
0
            }
13798
0
            Py_CLEAR(tmp);
13799
0
        }
13800
0
        if (PyObject_GetOptionalAttr(obj, state->kwd_patterns, &tmp) < 0) {
13801
0
            return -1;
13802
0
        }
13803
0
        if (tmp == NULL) {
13804
0
            tmp = PyList_New(0);
13805
0
            if (tmp == NULL) {
13806
0
                return -1;
13807
0
            }
13808
0
        }
13809
0
        {
13810
0
            int res;
13811
0
            Py_ssize_t len;
13812
0
            Py_ssize_t i;
13813
0
            if (!PyList_Check(tmp)) {
13814
0
                PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %T", tmp);
13815
0
                goto failed;
13816
0
            }
13817
0
            len = PyList_GET_SIZE(tmp);
13818
0
            kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
13819
0
            if (kwd_patterns == NULL) goto failed;
13820
0
            for (i = 0; i < len; i++) {
13821
0
                pattern_ty val;
13822
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13823
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
13824
0
                    goto failed;
13825
0
                }
13826
0
                res = obj2ast_pattern(state, tmp2, &val, "kwd_patterns", arena);
13827
0
                _Py_LeaveRecursiveCall();
13828
0
                Py_DECREF(tmp2);
13829
0
                if (res != 0) goto failed;
13830
0
                if (len != PyList_GET_SIZE(tmp)) {
13831
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
13832
0
                    goto failed;
13833
0
                }
13834
0
                asdl_seq_SET(kwd_patterns, i, val);
13835
0
            }
13836
0
            Py_CLEAR(tmp);
13837
0
        }
13838
0
        *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
13839
0
                                 lineno, col_offset, end_lineno,
13840
0
                                 end_col_offset, arena);
13841
0
        if (*out == NULL) goto failed;
13842
0
        return 0;
13843
0
    }
13844
0
    tp = state->MatchStar_type;
13845
0
    isinstance = PyObject_IsInstance(obj, tp);
13846
0
    if (isinstance == -1) {
13847
0
        return -1;
13848
0
    }
13849
0
    if (isinstance) {
13850
0
        identifier name;
13851
13852
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13853
0
            return -1;
13854
0
        }
13855
0
        if (tmp == NULL || tmp == Py_None) {
13856
0
            Py_CLEAR(tmp);
13857
0
            name = NULL;
13858
0
        }
13859
0
        else {
13860
0
            int res;
13861
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
13862
0
                goto failed;
13863
0
            }
13864
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
13865
0
            _Py_LeaveRecursiveCall();
13866
0
            if (res != 0) goto failed;
13867
0
            Py_CLEAR(tmp);
13868
0
        }
13869
0
        *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
13870
0
                                end_col_offset, arena);
13871
0
        if (*out == NULL) goto failed;
13872
0
        return 0;
13873
0
    }
13874
0
    tp = state->MatchAs_type;
13875
0
    isinstance = PyObject_IsInstance(obj, tp);
13876
0
    if (isinstance == -1) {
13877
0
        return -1;
13878
0
    }
13879
0
    if (isinstance) {
13880
0
        pattern_ty pattern;
13881
0
        identifier name;
13882
13883
0
        if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
13884
0
            return -1;
13885
0
        }
13886
0
        if (tmp == NULL || tmp == Py_None) {
13887
0
            Py_CLEAR(tmp);
13888
0
            pattern = NULL;
13889
0
        }
13890
0
        else {
13891
0
            int res;
13892
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
13893
0
                goto failed;
13894
0
            }
13895
0
            res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
13896
0
            _Py_LeaveRecursiveCall();
13897
0
            if (res != 0) goto failed;
13898
0
            Py_CLEAR(tmp);
13899
0
        }
13900
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
13901
0
            return -1;
13902
0
        }
13903
0
        if (tmp == NULL || tmp == Py_None) {
13904
0
            Py_CLEAR(tmp);
13905
0
            name = NULL;
13906
0
        }
13907
0
        else {
13908
0
            int res;
13909
0
            if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
13910
0
                goto failed;
13911
0
            }
13912
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
13913
0
            _Py_LeaveRecursiveCall();
13914
0
            if (res != 0) goto failed;
13915
0
            Py_CLEAR(tmp);
13916
0
        }
13917
0
        *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
13918
0
                              end_col_offset, arena);
13919
0
        if (*out == NULL) goto failed;
13920
0
        return 0;
13921
0
    }
13922
0
    tp = state->MatchOr_type;
13923
0
    isinstance = PyObject_IsInstance(obj, tp);
13924
0
    if (isinstance == -1) {
13925
0
        return -1;
13926
0
    }
13927
0
    if (isinstance) {
13928
0
        asdl_pattern_seq* patterns;
13929
13930
0
        if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
13931
0
            return -1;
13932
0
        }
13933
0
        if (tmp == NULL) {
13934
0
            tmp = PyList_New(0);
13935
0
            if (tmp == NULL) {
13936
0
                return -1;
13937
0
            }
13938
0
        }
13939
0
        {
13940
0
            int res;
13941
0
            Py_ssize_t len;
13942
0
            Py_ssize_t i;
13943
0
            if (!PyList_Check(tmp)) {
13944
0
                PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %T", tmp);
13945
0
                goto failed;
13946
0
            }
13947
0
            len = PyList_GET_SIZE(tmp);
13948
0
            patterns = _Py_asdl_pattern_seq_new(len, arena);
13949
0
            if (patterns == NULL) goto failed;
13950
0
            for (i = 0; i < len; i++) {
13951
0
                pattern_ty val;
13952
0
                PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13953
0
                if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
13954
0
                    goto failed;
13955
0
                }
13956
0
                res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
13957
0
                _Py_LeaveRecursiveCall();
13958
0
                Py_DECREF(tmp2);
13959
0
                if (res != 0) goto failed;
13960
0
                if (len != PyList_GET_SIZE(tmp)) {
13961
0
                    PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
13962
0
                    goto failed;
13963
0
                }
13964
0
                asdl_seq_SET(patterns, i, val);
13965
0
            }
13966
0
            Py_CLEAR(tmp);
13967
0
        }
13968
0
        *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
13969
0
                              end_col_offset, arena);
13970
0
        if (*out == NULL) goto failed;
13971
0
        return 0;
13972
0
    }
13973
13974
0
    PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
13975
0
    failed:
13976
0
    Py_XDECREF(tmp);
13977
0
    return -1;
13978
0
}
13979
13980
int
13981
obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
13982
                    out, const char* field, PyArena* arena)
13983
0
{
13984
0
    int isinstance;
13985
13986
0
    PyObject *tmp = NULL;
13987
0
    PyObject *tp;
13988
13989
0
    if (obj == Py_None) {
13990
0
        *out = NULL;
13991
0
        return 0;
13992
0
    }
13993
0
    tp = state->type_ignore_type;
13994
0
    isinstance = PyObject_IsInstance(obj, tp);
13995
0
    if (isinstance == -1) {
13996
0
        return 1;
13997
0
    }
13998
0
    if (!isinstance && field != NULL) {
13999
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_ignore', got '%T'", field, obj);
14000
0
        return 1;
14001
0
    }
14002
0
    tp = state->TypeIgnore_type;
14003
0
    isinstance = PyObject_IsInstance(obj, tp);
14004
0
    if (isinstance == -1) {
14005
0
        return -1;
14006
0
    }
14007
0
    if (isinstance) {
14008
0
        int lineno;
14009
0
        string tag;
14010
14011
0
        if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
14012
0
            return -1;
14013
0
        }
14014
0
        if (tmp == NULL) {
14015
0
            PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
14016
0
            return -1;
14017
0
        }
14018
0
        else {
14019
0
            int res;
14020
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
14021
0
                goto failed;
14022
0
            }
14023
0
            res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
14024
0
            _Py_LeaveRecursiveCall();
14025
0
            if (res != 0) goto failed;
14026
0
            Py_CLEAR(tmp);
14027
0
        }
14028
0
        if (PyObject_GetOptionalAttr(obj, state->tag, &tmp) < 0) {
14029
0
            return -1;
14030
0
        }
14031
0
        if (tmp == NULL) {
14032
0
            PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
14033
0
            return -1;
14034
0
        }
14035
0
        else {
14036
0
            int res;
14037
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
14038
0
                goto failed;
14039
0
            }
14040
0
            res = obj2ast_string(state, tmp, &tag, "tag", arena);
14041
0
            _Py_LeaveRecursiveCall();
14042
0
            if (res != 0) goto failed;
14043
0
            Py_CLEAR(tmp);
14044
0
        }
14045
0
        *out = _PyAST_TypeIgnore(lineno, tag, arena);
14046
0
        if (*out == NULL) goto failed;
14047
0
        return 0;
14048
0
    }
14049
14050
0
    PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
14051
0
    failed:
14052
0
    Py_XDECREF(tmp);
14053
0
    return -1;
14054
0
}
14055
14056
int
14057
obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
14058
                   const char* field, PyArena* arena)
14059
0
{
14060
0
    int isinstance;
14061
14062
0
    PyObject *tmp = NULL;
14063
0
    PyObject *tp;
14064
0
    int lineno;
14065
0
    int col_offset;
14066
0
    int end_lineno;
14067
0
    int end_col_offset;
14068
14069
0
    if (obj == Py_None) {
14070
0
        *out = NULL;
14071
0
        return 0;
14072
0
    }
14073
0
    tp = state->type_param_type;
14074
0
    isinstance = PyObject_IsInstance(obj, tp);
14075
0
    if (isinstance == -1) {
14076
0
        return 1;
14077
0
    }
14078
0
    if (!isinstance && field != NULL) {
14079
0
        PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_param', got '%T'", field, obj);
14080
0
        return 1;
14081
0
    }
14082
0
    if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
14083
0
        return -1;
14084
0
    }
14085
0
    if (tmp == NULL) {
14086
0
        PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
14087
0
        return -1;
14088
0
    }
14089
0
    else {
14090
0
        int res;
14091
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14092
0
            goto failed;
14093
0
        }
14094
0
        res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
14095
0
        _Py_LeaveRecursiveCall();
14096
0
        if (res != 0) goto failed;
14097
0
        Py_CLEAR(tmp);
14098
0
    }
14099
0
    if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
14100
0
        return -1;
14101
0
    }
14102
0
    if (tmp == NULL) {
14103
0
        PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
14104
0
        return -1;
14105
0
    }
14106
0
    else {
14107
0
        int res;
14108
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14109
0
            goto failed;
14110
0
        }
14111
0
        res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
14112
0
        _Py_LeaveRecursiveCall();
14113
0
        if (res != 0) goto failed;
14114
0
        Py_CLEAR(tmp);
14115
0
    }
14116
0
    if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
14117
0
        return -1;
14118
0
    }
14119
0
    if (tmp == NULL) {
14120
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
14121
0
        return -1;
14122
0
    }
14123
0
    else {
14124
0
        int res;
14125
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14126
0
            goto failed;
14127
0
        }
14128
0
        res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
14129
0
        _Py_LeaveRecursiveCall();
14130
0
        if (res != 0) goto failed;
14131
0
        Py_CLEAR(tmp);
14132
0
    }
14133
0
    if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
14134
0
        return -1;
14135
0
    }
14136
0
    if (tmp == NULL) {
14137
0
        PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
14138
0
        return -1;
14139
0
    }
14140
0
    else {
14141
0
        int res;
14142
0
        if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
14143
0
            goto failed;
14144
0
        }
14145
0
        res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
14146
0
        _Py_LeaveRecursiveCall();
14147
0
        if (res != 0) goto failed;
14148
0
        Py_CLEAR(tmp);
14149
0
    }
14150
0
    tp = state->TypeVar_type;
14151
0
    isinstance = PyObject_IsInstance(obj, tp);
14152
0
    if (isinstance == -1) {
14153
0
        return -1;
14154
0
    }
14155
0
    if (isinstance) {
14156
0
        identifier name;
14157
0
        expr_ty bound;
14158
0
        expr_ty default_value;
14159
14160
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14161
0
            return -1;
14162
0
        }
14163
0
        if (tmp == NULL) {
14164
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
14165
0
            return -1;
14166
0
        }
14167
0
        else {
14168
0
            int res;
14169
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14170
0
                goto failed;
14171
0
            }
14172
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14173
0
            _Py_LeaveRecursiveCall();
14174
0
            if (res != 0) goto failed;
14175
0
            Py_CLEAR(tmp);
14176
0
        }
14177
0
        if (PyObject_GetOptionalAttr(obj, state->bound, &tmp) < 0) {
14178
0
            return -1;
14179
0
        }
14180
0
        if (tmp == NULL || tmp == Py_None) {
14181
0
            Py_CLEAR(tmp);
14182
0
            bound = NULL;
14183
0
        }
14184
0
        else {
14185
0
            int res;
14186
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14187
0
                goto failed;
14188
0
            }
14189
0
            res = obj2ast_expr(state, tmp, &bound, "bound", arena);
14190
0
            _Py_LeaveRecursiveCall();
14191
0
            if (res != 0) goto failed;
14192
0
            Py_CLEAR(tmp);
14193
0
        }
14194
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14195
0
            return -1;
14196
0
        }
14197
0
        if (tmp == NULL || tmp == Py_None) {
14198
0
            Py_CLEAR(tmp);
14199
0
            default_value = NULL;
14200
0
        }
14201
0
        else {
14202
0
            int res;
14203
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
14204
0
                goto failed;
14205
0
            }
14206
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14207
0
                               arena);
14208
0
            _Py_LeaveRecursiveCall();
14209
0
            if (res != 0) goto failed;
14210
0
            Py_CLEAR(tmp);
14211
0
        }
14212
0
        *out = _PyAST_TypeVar(name, bound, default_value, lineno, col_offset,
14213
0
                              end_lineno, end_col_offset, arena);
14214
0
        if (*out == NULL) goto failed;
14215
0
        return 0;
14216
0
    }
14217
0
    tp = state->ParamSpec_type;
14218
0
    isinstance = PyObject_IsInstance(obj, tp);
14219
0
    if (isinstance == -1) {
14220
0
        return -1;
14221
0
    }
14222
0
    if (isinstance) {
14223
0
        identifier name;
14224
0
        expr_ty default_value;
14225
14226
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14227
0
            return -1;
14228
0
        }
14229
0
        if (tmp == NULL) {
14230
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
14231
0
            return -1;
14232
0
        }
14233
0
        else {
14234
0
            int res;
14235
0
            if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
14236
0
                goto failed;
14237
0
            }
14238
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14239
0
            _Py_LeaveRecursiveCall();
14240
0
            if (res != 0) goto failed;
14241
0
            Py_CLEAR(tmp);
14242
0
        }
14243
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14244
0
            return -1;
14245
0
        }
14246
0
        if (tmp == NULL || tmp == Py_None) {
14247
0
            Py_CLEAR(tmp);
14248
0
            default_value = NULL;
14249
0
        }
14250
0
        else {
14251
0
            int res;
14252
0
            if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
14253
0
                goto failed;
14254
0
            }
14255
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14256
0
                               arena);
14257
0
            _Py_LeaveRecursiveCall();
14258
0
            if (res != 0) goto failed;
14259
0
            Py_CLEAR(tmp);
14260
0
        }
14261
0
        *out = _PyAST_ParamSpec(name, default_value, lineno, col_offset,
14262
0
                                end_lineno, end_col_offset, arena);
14263
0
        if (*out == NULL) goto failed;
14264
0
        return 0;
14265
0
    }
14266
0
    tp = state->TypeVarTuple_type;
14267
0
    isinstance = PyObject_IsInstance(obj, tp);
14268
0
    if (isinstance == -1) {
14269
0
        return -1;
14270
0
    }
14271
0
    if (isinstance) {
14272
0
        identifier name;
14273
0
        expr_ty default_value;
14274
14275
0
        if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
14276
0
            return -1;
14277
0
        }
14278
0
        if (tmp == NULL) {
14279
0
            PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
14280
0
            return -1;
14281
0
        }
14282
0
        else {
14283
0
            int res;
14284
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
14285
0
                goto failed;
14286
0
            }
14287
0
            res = obj2ast_identifier(state, tmp, &name, "name", arena);
14288
0
            _Py_LeaveRecursiveCall();
14289
0
            if (res != 0) goto failed;
14290
0
            Py_CLEAR(tmp);
14291
0
        }
14292
0
        if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
14293
0
            return -1;
14294
0
        }
14295
0
        if (tmp == NULL || tmp == Py_None) {
14296
0
            Py_CLEAR(tmp);
14297
0
            default_value = NULL;
14298
0
        }
14299
0
        else {
14300
0
            int res;
14301
0
            if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
14302
0
                goto failed;
14303
0
            }
14304
0
            res = obj2ast_expr(state, tmp, &default_value, "default_value",
14305
0
                               arena);
14306
0
            _Py_LeaveRecursiveCall();
14307
0
            if (res != 0) goto failed;
14308
0
            Py_CLEAR(tmp);
14309
0
        }
14310
0
        *out = _PyAST_TypeVarTuple(name, default_value, lineno, col_offset,
14311
0
                                   end_lineno, end_col_offset, arena);
14312
0
        if (*out == NULL) goto failed;
14313
0
        return 0;
14314
0
    }
14315
14316
0
    PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
14317
0
    failed:
14318
0
    Py_XDECREF(tmp);
14319
0
    return -1;
14320
0
}
14321
14322
14323
/* Helper for checking if a node class is abstract in the tests. */
14324
static PyObject *
14325
0
ast_is_abstract(PyObject *Py_UNUSED(module), PyObject *cls) {
14326
0
    struct ast_state *state = get_ast_state();
14327
0
    if (state == NULL) {
14328
0
        return NULL;
14329
0
    }
14330
0
    int contains = PySet_Contains(state->abstract_types, cls);
14331
0
    if (contains == -1) {
14332
0
        return NULL;
14333
0
    }
14334
0
    else if (contains == 1) {
14335
0
        Py_RETURN_TRUE;
14336
0
    }
14337
0
    Py_RETURN_FALSE;
14338
0
}
14339
14340
static struct PyMethodDef astmodule_methods[] = {
14341
    {"_is_abstract", ast_is_abstract, METH_O, NULL},
14342
    {NULL}  /* Sentinel */
14343
};
14344
14345
static int
14346
astmodule_exec(PyObject *m)
14347
1
{
14348
1
    struct ast_state *state = get_ast_state();
14349
1
    if (state == NULL) {
14350
0
        return -1;
14351
0
    }
14352
1
    if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
14353
0
        return -1;
14354
0
    }
14355
1
    if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
14356
0
        return -1;
14357
0
    }
14358
1
    if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
14359
0
        return -1;
14360
0
    }
14361
1
    if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
14362
0
        return -1;
14363
0
    }
14364
1
    if (PyModule_AddIntMacro(m, PyCF_OPTIMIZED_AST) < 0) {
14365
0
        return -1;
14366
0
    }
14367
1
    if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
14368
0
        return -1;
14369
0
    }
14370
1
    if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
14371
0
        return -1;
14372
0
    }
14373
1
    if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
14374
0
        return -1;
14375
0
    }
14376
1
    if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
14377
0
        return -1;
14378
0
    }
14379
1
    if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
14380
0
        {
14381
0
        return -1;
14382
0
    }
14383
1
    if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
14384
0
        return -1;
14385
0
    }
14386
1
    if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
14387
0
        return -1;
14388
0
    }
14389
1
    if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
14390
1
        state->AsyncFunctionDef_type) < 0) {
14391
0
        return -1;
14392
0
    }
14393
1
    if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
14394
0
        return -1;
14395
0
    }
14396
1
    if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
14397
0
        return -1;
14398
0
    }
14399
1
    if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
14400
0
        return -1;
14401
0
    }
14402
1
    if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
14403
0
        return -1;
14404
0
    }
14405
1
    if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
14406
0
        return -1;
14407
0
    }
14408
1
    if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
14409
0
        return -1;
14410
0
    }
14411
1
    if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
14412
0
        return -1;
14413
0
    }
14414
1
    if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
14415
0
        return -1;
14416
0
    }
14417
1
    if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
14418
0
        return -1;
14419
0
    }
14420
1
    if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
14421
0
        return -1;
14422
0
    }
14423
1
    if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
14424
0
        return -1;
14425
0
    }
14426
1
    if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
14427
0
        return -1;
14428
0
    }
14429
1
    if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
14430
0
        return -1;
14431
0
    }
14432
1
    if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
14433
0
        return -1;
14434
0
    }
14435
1
    if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
14436
0
        return -1;
14437
0
    }
14438
1
    if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
14439
0
        return -1;
14440
0
    }
14441
1
    if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
14442
0
        return -1;
14443
0
    }
14444
1
    if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
14445
0
        return -1;
14446
0
    }
14447
1
    if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
14448
0
        return -1;
14449
0
    }
14450
1
    if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
14451
0
        return -1;
14452
0
    }
14453
1
    if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
14454
0
        return -1;
14455
0
    }
14456
1
    if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
14457
0
        return -1;
14458
0
    }
14459
1
    if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
14460
0
        return -1;
14461
0
    }
14462
1
    if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
14463
0
        return -1;
14464
0
    }
14465
1
    if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
14466
0
        return -1;
14467
0
    }
14468
1
    if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
14469
0
        return -1;
14470
0
    }
14471
1
    if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
14472
0
        return -1;
14473
0
    }
14474
1
    if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
14475
0
        return -1;
14476
0
    }
14477
1
    if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
14478
0
        return -1;
14479
0
    }
14480
1
    if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
14481
0
        return -1;
14482
0
    }
14483
1
    if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
14484
0
        return -1;
14485
0
    }
14486
1
    if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
14487
0
        return -1;
14488
0
    }
14489
1
    if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
14490
0
        return -1;
14491
0
    }
14492
1
    if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
14493
0
        return -1;
14494
0
    }
14495
1
    if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
14496
0
        return -1;
14497
0
    }
14498
1
    if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
14499
0
        return -1;
14500
0
    }
14501
1
    if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
14502
0
        return -1;
14503
0
    }
14504
1
    if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
14505
0
        return -1;
14506
0
    }
14507
1
    if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
14508
0
        {
14509
0
        return -1;
14510
0
    }
14511
1
    if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
14512
0
        return -1;
14513
0
    }
14514
1
    if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
14515
0
        return -1;
14516
0
    }
14517
1
    if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
14518
0
        return -1;
14519
0
    }
14520
1
    if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
14521
0
        return -1;
14522
0
    }
14523
1
    if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
14524
0
        return -1;
14525
0
    }
14526
1
    if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
14527
1
        < 0) {
14528
0
        return -1;
14529
0
    }
14530
1
    if (PyModule_AddObjectRef(m, "Interpolation", state->Interpolation_type) <
14531
1
        0) {
14532
0
        return -1;
14533
0
    }
14534
1
    if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
14535
0
        return -1;
14536
0
    }
14537
1
    if (PyModule_AddObjectRef(m, "TemplateStr", state->TemplateStr_type) < 0) {
14538
0
        return -1;
14539
0
    }
14540
1
    if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
14541
0
        return -1;
14542
0
    }
14543
1
    if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
14544
0
        return -1;
14545
0
    }
14546
1
    if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
14547
0
        return -1;
14548
0
    }
14549
1
    if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
14550
0
        return -1;
14551
0
    }
14552
1
    if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
14553
0
        return -1;
14554
0
    }
14555
1
    if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
14556
0
        return -1;
14557
0
    }
14558
1
    if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
14559
0
        return -1;
14560
0
    }
14561
1
    if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
14562
0
        return -1;
14563
0
    }
14564
1
    if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
14565
0
        {
14566
0
        return -1;
14567
0
    }
14568
1
    if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
14569
0
        return -1;
14570
0
    }
14571
1
    if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
14572
0
        return -1;
14573
0
    }
14574
1
    if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
14575
0
        return -1;
14576
0
    }
14577
1
    if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
14578
0
        return -1;
14579
0
    }
14580
1
    if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
14581
0
        return -1;
14582
0
    }
14583
1
    if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
14584
0
        return -1;
14585
0
    }
14586
1
    if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
14587
0
        return -1;
14588
0
    }
14589
1
    if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
14590
0
        return -1;
14591
0
    }
14592
1
    if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
14593
0
        return -1;
14594
0
    }
14595
1
    if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
14596
0
        return -1;
14597
0
    }
14598
1
    if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
14599
0
        return -1;
14600
0
    }
14601
1
    if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
14602
0
        return -1;
14603
0
    }
14604
1
    if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
14605
0
        return -1;
14606
0
    }
14607
1
    if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
14608
0
        return -1;
14609
0
    }
14610
1
    if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
14611
0
        return -1;
14612
0
    }
14613
1
    if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
14614
0
        return -1;
14615
0
    }
14616
1
    if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
14617
0
        return -1;
14618
0
    }
14619
1
    if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
14620
0
        return -1;
14621
0
    }
14622
1
    if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
14623
0
        return -1;
14624
0
    }
14625
1
    if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
14626
0
        return -1;
14627
0
    }
14628
1
    if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
14629
0
        return -1;
14630
0
    }
14631
1
    if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
14632
0
        return -1;
14633
0
    }
14634
1
    if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
14635
0
        return -1;
14636
0
    }
14637
1
    if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
14638
0
        return -1;
14639
0
    }
14640
1
    if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
14641
0
        return -1;
14642
0
    }
14643
1
    if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
14644
0
        return -1;
14645
0
    }
14646
1
    if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
14647
0
        return -1;
14648
0
    }
14649
1
    if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
14650
0
        return -1;
14651
0
    }
14652
1
    if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
14653
0
        return -1;
14654
0
    }
14655
1
    if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
14656
0
        return -1;
14657
0
    }
14658
1
    if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
14659
0
        return -1;
14660
0
    }
14661
1
    if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
14662
0
        return -1;
14663
0
    }
14664
1
    if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
14665
0
        return -1;
14666
0
    }
14667
1
    if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
14668
0
        return -1;
14669
0
    }
14670
1
    if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
14671
0
        return -1;
14672
0
    }
14673
1
    if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
14674
0
        return -1;
14675
0
    }
14676
1
    if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
14677
1
        0) {
14678
0
        return -1;
14679
0
    }
14680
1
    if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
14681
1
        0) {
14682
0
        return -1;
14683
0
    }
14684
1
    if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
14685
1
        0) {
14686
0
        return -1;
14687
0
    }
14688
1
    if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
14689
0
        return -1;
14690
0
    }
14691
1
    if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
14692
0
        return -1;
14693
0
    }
14694
1
    if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
14695
0
        return -1;
14696
0
    }
14697
1
    if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
14698
0
        return -1;
14699
0
    }
14700
1
    if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
14701
0
        return -1;
14702
0
    }
14703
1
    if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
14704
0
        return -1;
14705
0
    }
14706
1
    if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
14707
0
        return -1;
14708
0
    }
14709
1
    if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
14710
0
        return -1;
14711
0
    }
14712
1
    if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
14713
1
        < 0) {
14714
0
        return -1;
14715
0
    }
14716
1
    if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
14717
1
        0) {
14718
0
        return -1;
14719
0
    }
14720
1
    if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
14721
0
        {
14722
0
        return -1;
14723
0
    }
14724
1
    if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
14725
0
        return -1;
14726
0
    }
14727
1
    if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
14728
0
        return -1;
14729
0
    }
14730
1
    if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
14731
0
        return -1;
14732
0
    }
14733
1
    if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
14734
0
        return -1;
14735
0
    }
14736
1
    if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
14737
0
        return -1;
14738
0
    }
14739
1
    if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
14740
0
        return -1;
14741
0
    }
14742
1
    if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
14743
0
        return -1;
14744
0
    }
14745
1
    if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
14746
0
        return -1;
14747
0
    }
14748
1
    if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
14749
0
        return -1;
14750
0
    }
14751
1
    if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
14752
0
        {
14753
0
        return -1;
14754
0
    }
14755
1
    return 0;
14756
1
}
14757
14758
static PyModuleDef_Slot astmodule_slots[] = {
14759
    _Py_ABI_SLOT,
14760
    {Py_mod_exec, astmodule_exec},
14761
    {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
14762
    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
14763
    {0, NULL}
14764
};
14765
14766
static struct PyModuleDef _astmodule = {
14767
    PyModuleDef_HEAD_INIT,
14768
    .m_name = "_ast",
14769
    // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
14770
    .m_size = 0,
14771
    .m_methods = astmodule_methods,
14772
    .m_slots = astmodule_slots
14773
};
14774
14775
PyMODINIT_FUNC
14776
PyInit__ast(void)
14777
1
{
14778
1
    return PyModuleDef_Init(&_astmodule);
14779
1
}
14780
14781
14782
PyObject* PyAST_mod2obj(mod_ty t)
14783
1.95k
{
14784
1.95k
    struct ast_state *state = get_ast_state();
14785
1.95k
    if (state == NULL) {
14786
0
        return NULL;
14787
0
    }
14788
1.95k
    PyObject *result = ast2obj_mod(state, t);
14789
14790
1.95k
    return result;
14791
1.95k
}
14792
14793
/* mode is 0 for "exec", 1 for "eval", 2 for "single" and 3 for "func_type"
14794
   input */
14795
int PyAst_CheckMode(PyObject *ast, int mode)
14796
0
{
14797
0
    const char * const req_name[] = {"Module", "Expression", "Interactive",
14798
0
                                     "FunctionType"};
14799
14800
0
    struct ast_state *state = get_ast_state();
14801
0
    if (state == NULL) {
14802
0
        return -1;
14803
0
    }
14804
14805
0
    PyObject *req_type[4];
14806
0
    req_type[0] = state->Module_type;
14807
0
    req_type[1] = state->Expression_type;
14808
0
    req_type[2] = state->Interactive_type;
14809
0
    req_type[3] = state->FunctionType_type;
14810
14811
0
    assert(0 <= mode && mode <= 3);
14812
0
    int isinstance = PyObject_IsInstance(ast, req_type[mode]);
14813
0
    if (isinstance == -1) {
14814
0
        return -1;
14815
0
    }
14816
0
    if (!isinstance) {
14817
0
        PyErr_Format(PyExc_TypeError, "expected %s node, got %T",
14818
0
                     req_name[mode], ast);
14819
0
        return -1;
14820
0
    }
14821
0
    return 0;
14822
0
}
14823
14824
mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
14825
0
{
14826
0
    if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
14827
0
        return NULL;
14828
0
    }
14829
14830
0
    struct ast_state *state = get_ast_state();
14831
0
    if (state == NULL) {
14832
0
        return NULL;
14833
0
    }
14834
14835
0
    if (PyAst_CheckMode(ast, mode) < 0) {
14836
0
        return NULL;
14837
0
    }
14838
14839
0
    mod_ty res = NULL;
14840
0
    if (obj2ast_mod(state, ast, &res, NULL, arena) != 0)
14841
0
        return NULL;
14842
0
    else
14843
0
        return res;
14844
0
}
14845
14846
int PyAST_Check(PyObject* obj)
14847
33
{
14848
33
    struct ast_state *state = get_ast_state();
14849
33
    if (state == NULL) {
14850
0
        return -1;
14851
0
    }
14852
33
    return PyObject_IsInstance(obj, state->AST_type);
14853
33
}
14854
14855