Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Python/Python-ast.c
12 views
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_interp.h" // _PyInterpreterState.ast
8
#include "pycore_pystate.h" // _PyInterpreterState_GET()
9
#include "structmember.h"
10
#include <stddef.h>
11
12
// Forward declaration
13
static int init_types(struct ast_state *state);
14
15
static struct ast_state*
16
get_ast_state(void)
17
{
18
PyInterpreterState *interp = _PyInterpreterState_GET();
19
struct ast_state *state = &interp->ast;
20
if (!init_types(state)) {
21
return NULL;
22
}
23
return state;
24
}
25
26
void _PyAST_Fini(PyInterpreterState *interp)
27
{
28
struct ast_state *state = &interp->ast;
29
30
Py_CLEAR(state->AST_type);
31
Py_CLEAR(state->Add_singleton);
32
Py_CLEAR(state->Add_type);
33
Py_CLEAR(state->And_singleton);
34
Py_CLEAR(state->And_type);
35
Py_CLEAR(state->AnnAssign_type);
36
Py_CLEAR(state->Assert_type);
37
Py_CLEAR(state->Assign_type);
38
Py_CLEAR(state->AsyncFor_type);
39
Py_CLEAR(state->AsyncFunctionDef_type);
40
Py_CLEAR(state->AsyncWith_type);
41
Py_CLEAR(state->Attribute_type);
42
Py_CLEAR(state->AugAssign_type);
43
Py_CLEAR(state->Await_type);
44
Py_CLEAR(state->BinOp_type);
45
Py_CLEAR(state->BitAnd_singleton);
46
Py_CLEAR(state->BitAnd_type);
47
Py_CLEAR(state->BitOr_singleton);
48
Py_CLEAR(state->BitOr_type);
49
Py_CLEAR(state->BitXor_singleton);
50
Py_CLEAR(state->BitXor_type);
51
Py_CLEAR(state->BoolOp_type);
52
Py_CLEAR(state->Break_type);
53
Py_CLEAR(state->Call_type);
54
Py_CLEAR(state->ClassDef_type);
55
Py_CLEAR(state->Compare_type);
56
Py_CLEAR(state->Constant_type);
57
Py_CLEAR(state->Continue_type);
58
Py_CLEAR(state->Del_singleton);
59
Py_CLEAR(state->Del_type);
60
Py_CLEAR(state->Delete_type);
61
Py_CLEAR(state->DictComp_type);
62
Py_CLEAR(state->Dict_type);
63
Py_CLEAR(state->Div_singleton);
64
Py_CLEAR(state->Div_type);
65
Py_CLEAR(state->Eq_singleton);
66
Py_CLEAR(state->Eq_type);
67
Py_CLEAR(state->ExceptHandler_type);
68
Py_CLEAR(state->Expr_type);
69
Py_CLEAR(state->Expression_type);
70
Py_CLEAR(state->FloorDiv_singleton);
71
Py_CLEAR(state->FloorDiv_type);
72
Py_CLEAR(state->For_type);
73
Py_CLEAR(state->FormattedValue_type);
74
Py_CLEAR(state->FunctionDef_type);
75
Py_CLEAR(state->FunctionType_type);
76
Py_CLEAR(state->GeneratorExp_type);
77
Py_CLEAR(state->Global_type);
78
Py_CLEAR(state->GtE_singleton);
79
Py_CLEAR(state->GtE_type);
80
Py_CLEAR(state->Gt_singleton);
81
Py_CLEAR(state->Gt_type);
82
Py_CLEAR(state->IfExp_type);
83
Py_CLEAR(state->If_type);
84
Py_CLEAR(state->ImportFrom_type);
85
Py_CLEAR(state->Import_type);
86
Py_CLEAR(state->In_singleton);
87
Py_CLEAR(state->In_type);
88
Py_CLEAR(state->Interactive_type);
89
Py_CLEAR(state->Invert_singleton);
90
Py_CLEAR(state->Invert_type);
91
Py_CLEAR(state->IsNot_singleton);
92
Py_CLEAR(state->IsNot_type);
93
Py_CLEAR(state->Is_singleton);
94
Py_CLEAR(state->Is_type);
95
Py_CLEAR(state->JoinedStr_type);
96
Py_CLEAR(state->LShift_singleton);
97
Py_CLEAR(state->LShift_type);
98
Py_CLEAR(state->Lambda_type);
99
Py_CLEAR(state->ListComp_type);
100
Py_CLEAR(state->List_type);
101
Py_CLEAR(state->Load_singleton);
102
Py_CLEAR(state->Load_type);
103
Py_CLEAR(state->LtE_singleton);
104
Py_CLEAR(state->LtE_type);
105
Py_CLEAR(state->Lt_singleton);
106
Py_CLEAR(state->Lt_type);
107
Py_CLEAR(state->MatMult_singleton);
108
Py_CLEAR(state->MatMult_type);
109
Py_CLEAR(state->MatchAs_type);
110
Py_CLEAR(state->MatchClass_type);
111
Py_CLEAR(state->MatchMapping_type);
112
Py_CLEAR(state->MatchOr_type);
113
Py_CLEAR(state->MatchSequence_type);
114
Py_CLEAR(state->MatchSingleton_type);
115
Py_CLEAR(state->MatchStar_type);
116
Py_CLEAR(state->MatchValue_type);
117
Py_CLEAR(state->Match_type);
118
Py_CLEAR(state->Mod_singleton);
119
Py_CLEAR(state->Mod_type);
120
Py_CLEAR(state->Module_type);
121
Py_CLEAR(state->Mult_singleton);
122
Py_CLEAR(state->Mult_type);
123
Py_CLEAR(state->Name_type);
124
Py_CLEAR(state->NamedExpr_type);
125
Py_CLEAR(state->Nonlocal_type);
126
Py_CLEAR(state->NotEq_singleton);
127
Py_CLEAR(state->NotEq_type);
128
Py_CLEAR(state->NotIn_singleton);
129
Py_CLEAR(state->NotIn_type);
130
Py_CLEAR(state->Not_singleton);
131
Py_CLEAR(state->Not_type);
132
Py_CLEAR(state->Or_singleton);
133
Py_CLEAR(state->Or_type);
134
Py_CLEAR(state->ParamSpec_type);
135
Py_CLEAR(state->Pass_type);
136
Py_CLEAR(state->Pow_singleton);
137
Py_CLEAR(state->Pow_type);
138
Py_CLEAR(state->RShift_singleton);
139
Py_CLEAR(state->RShift_type);
140
Py_CLEAR(state->Raise_type);
141
Py_CLEAR(state->Return_type);
142
Py_CLEAR(state->SetComp_type);
143
Py_CLEAR(state->Set_type);
144
Py_CLEAR(state->Slice_type);
145
Py_CLEAR(state->Starred_type);
146
Py_CLEAR(state->Store_singleton);
147
Py_CLEAR(state->Store_type);
148
Py_CLEAR(state->Sub_singleton);
149
Py_CLEAR(state->Sub_type);
150
Py_CLEAR(state->Subscript_type);
151
Py_CLEAR(state->TryStar_type);
152
Py_CLEAR(state->Try_type);
153
Py_CLEAR(state->Tuple_type);
154
Py_CLEAR(state->TypeAlias_type);
155
Py_CLEAR(state->TypeIgnore_type);
156
Py_CLEAR(state->TypeVarTuple_type);
157
Py_CLEAR(state->TypeVar_type);
158
Py_CLEAR(state->UAdd_singleton);
159
Py_CLEAR(state->UAdd_type);
160
Py_CLEAR(state->USub_singleton);
161
Py_CLEAR(state->USub_type);
162
Py_CLEAR(state->UnaryOp_type);
163
Py_CLEAR(state->While_type);
164
Py_CLEAR(state->With_type);
165
Py_CLEAR(state->YieldFrom_type);
166
Py_CLEAR(state->Yield_type);
167
Py_CLEAR(state->__dict__);
168
Py_CLEAR(state->__doc__);
169
Py_CLEAR(state->__match_args__);
170
Py_CLEAR(state->__module__);
171
Py_CLEAR(state->_attributes);
172
Py_CLEAR(state->_fields);
173
Py_CLEAR(state->alias_type);
174
Py_CLEAR(state->annotation);
175
Py_CLEAR(state->arg);
176
Py_CLEAR(state->arg_type);
177
Py_CLEAR(state->args);
178
Py_CLEAR(state->argtypes);
179
Py_CLEAR(state->arguments_type);
180
Py_CLEAR(state->asname);
181
Py_CLEAR(state->ast);
182
Py_CLEAR(state->attr);
183
Py_CLEAR(state->bases);
184
Py_CLEAR(state->body);
185
Py_CLEAR(state->boolop_type);
186
Py_CLEAR(state->bound);
187
Py_CLEAR(state->cases);
188
Py_CLEAR(state->cause);
189
Py_CLEAR(state->cls);
190
Py_CLEAR(state->cmpop_type);
191
Py_CLEAR(state->col_offset);
192
Py_CLEAR(state->comparators);
193
Py_CLEAR(state->comprehension_type);
194
Py_CLEAR(state->context_expr);
195
Py_CLEAR(state->conversion);
196
Py_CLEAR(state->ctx);
197
Py_CLEAR(state->decorator_list);
198
Py_CLEAR(state->defaults);
199
Py_CLEAR(state->elt);
200
Py_CLEAR(state->elts);
201
Py_CLEAR(state->end_col_offset);
202
Py_CLEAR(state->end_lineno);
203
Py_CLEAR(state->exc);
204
Py_CLEAR(state->excepthandler_type);
205
Py_CLEAR(state->expr_context_type);
206
Py_CLEAR(state->expr_type);
207
Py_CLEAR(state->finalbody);
208
Py_CLEAR(state->format_spec);
209
Py_CLEAR(state->func);
210
Py_CLEAR(state->generators);
211
Py_CLEAR(state->guard);
212
Py_CLEAR(state->handlers);
213
Py_CLEAR(state->id);
214
Py_CLEAR(state->ifs);
215
Py_CLEAR(state->is_async);
216
Py_CLEAR(state->items);
217
Py_CLEAR(state->iter);
218
Py_CLEAR(state->key);
219
Py_CLEAR(state->keys);
220
Py_CLEAR(state->keyword_type);
221
Py_CLEAR(state->keywords);
222
Py_CLEAR(state->kind);
223
Py_CLEAR(state->kw_defaults);
224
Py_CLEAR(state->kwarg);
225
Py_CLEAR(state->kwd_attrs);
226
Py_CLEAR(state->kwd_patterns);
227
Py_CLEAR(state->kwonlyargs);
228
Py_CLEAR(state->left);
229
Py_CLEAR(state->level);
230
Py_CLEAR(state->lineno);
231
Py_CLEAR(state->lower);
232
Py_CLEAR(state->match_case_type);
233
Py_CLEAR(state->mod_type);
234
Py_CLEAR(state->module);
235
Py_CLEAR(state->msg);
236
Py_CLEAR(state->name);
237
Py_CLEAR(state->names);
238
Py_CLEAR(state->op);
239
Py_CLEAR(state->operand);
240
Py_CLEAR(state->operator_type);
241
Py_CLEAR(state->ops);
242
Py_CLEAR(state->optional_vars);
243
Py_CLEAR(state->orelse);
244
Py_CLEAR(state->pattern);
245
Py_CLEAR(state->pattern_type);
246
Py_CLEAR(state->patterns);
247
Py_CLEAR(state->posonlyargs);
248
Py_CLEAR(state->rest);
249
Py_CLEAR(state->returns);
250
Py_CLEAR(state->right);
251
Py_CLEAR(state->simple);
252
Py_CLEAR(state->slice);
253
Py_CLEAR(state->step);
254
Py_CLEAR(state->stmt_type);
255
Py_CLEAR(state->subject);
256
Py_CLEAR(state->tag);
257
Py_CLEAR(state->target);
258
Py_CLEAR(state->targets);
259
Py_CLEAR(state->test);
260
Py_CLEAR(state->type);
261
Py_CLEAR(state->type_comment);
262
Py_CLEAR(state->type_ignore_type);
263
Py_CLEAR(state->type_ignores);
264
Py_CLEAR(state->type_param_type);
265
Py_CLEAR(state->type_params);
266
Py_CLEAR(state->unaryop_type);
267
Py_CLEAR(state->upper);
268
Py_CLEAR(state->value);
269
Py_CLEAR(state->values);
270
Py_CLEAR(state->vararg);
271
Py_CLEAR(state->withitem_type);
272
273
Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf));
274
275
#if !defined(NDEBUG)
276
state->initialized = -1;
277
#else
278
state->initialized = 0;
279
#endif
280
}
281
282
static int init_identifiers(struct ast_state *state)
283
{
284
if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
285
if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
286
if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return 0;
287
if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
288
if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
289
if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
290
if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
291
if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
292
if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
293
if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
294
if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
295
if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
296
if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
297
if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
298
if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
299
if ((state->bound = PyUnicode_InternFromString("bound")) == NULL) return 0;
300
if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return 0;
301
if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
302
if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return 0;
303
if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
304
if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
305
if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
306
if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
307
if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
308
if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
309
if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
310
if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
311
if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
312
if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
313
if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
314
if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
315
if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
316
if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
317
if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
318
if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
319
if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return 0;
320
if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
321
if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
322
if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
323
if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
324
if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
325
if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
326
if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
327
if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
328
if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
329
if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
330
if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
331
if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
332
if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return 0;
333
if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return 0;
334
if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
335
if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
336
if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
337
if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
338
if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
339
if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
340
if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
341
if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
342
if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
343
if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
344
if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
345
if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
346
if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
347
if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
348
if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return 0;
349
if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return 0;
350
if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
351
if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return 0;
352
if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
353
if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
354
if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
355
if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
356
if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
357
if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return 0;
358
if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
359
if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
360
if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
361
if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
362
if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
363
if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
364
if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
365
if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return 0;
366
if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
367
if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
368
if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
369
if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
370
return 1;
371
};
372
373
GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
374
GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
375
GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
376
GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
377
GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
378
GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
379
GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
380
GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
381
GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
382
GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
383
GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
384
GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
385
GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
386
GENERATE_ASDL_SEQ_CONSTRUCTOR(type_param, type_param_ty)
387
388
static PyObject* ast2obj_mod(struct ast_state *state, void*);
389
static const char * const Module_fields[]={
390
"body",
391
"type_ignores",
392
};
393
static const char * const Interactive_fields[]={
394
"body",
395
};
396
static const char * const Expression_fields[]={
397
"body",
398
};
399
static const char * const FunctionType_fields[]={
400
"argtypes",
401
"returns",
402
};
403
static const char * const stmt_attributes[] = {
404
"lineno",
405
"col_offset",
406
"end_lineno",
407
"end_col_offset",
408
};
409
static PyObject* ast2obj_stmt(struct ast_state *state, void*);
410
static const char * const FunctionDef_fields[]={
411
"name",
412
"args",
413
"body",
414
"decorator_list",
415
"returns",
416
"type_comment",
417
"type_params",
418
};
419
static const char * const AsyncFunctionDef_fields[]={
420
"name",
421
"args",
422
"body",
423
"decorator_list",
424
"returns",
425
"type_comment",
426
"type_params",
427
};
428
static const char * const ClassDef_fields[]={
429
"name",
430
"bases",
431
"keywords",
432
"body",
433
"decorator_list",
434
"type_params",
435
};
436
static const char * const Return_fields[]={
437
"value",
438
};
439
static const char * const Delete_fields[]={
440
"targets",
441
};
442
static const char * const Assign_fields[]={
443
"targets",
444
"value",
445
"type_comment",
446
};
447
static const char * const TypeAlias_fields[]={
448
"name",
449
"type_params",
450
"value",
451
};
452
static const char * const AugAssign_fields[]={
453
"target",
454
"op",
455
"value",
456
};
457
static const char * const AnnAssign_fields[]={
458
"target",
459
"annotation",
460
"value",
461
"simple",
462
};
463
static const char * const For_fields[]={
464
"target",
465
"iter",
466
"body",
467
"orelse",
468
"type_comment",
469
};
470
static const char * const AsyncFor_fields[]={
471
"target",
472
"iter",
473
"body",
474
"orelse",
475
"type_comment",
476
};
477
static const char * const While_fields[]={
478
"test",
479
"body",
480
"orelse",
481
};
482
static const char * const If_fields[]={
483
"test",
484
"body",
485
"orelse",
486
};
487
static const char * const With_fields[]={
488
"items",
489
"body",
490
"type_comment",
491
};
492
static const char * const AsyncWith_fields[]={
493
"items",
494
"body",
495
"type_comment",
496
};
497
static const char * const Match_fields[]={
498
"subject",
499
"cases",
500
};
501
static const char * const Raise_fields[]={
502
"exc",
503
"cause",
504
};
505
static const char * const Try_fields[]={
506
"body",
507
"handlers",
508
"orelse",
509
"finalbody",
510
};
511
static const char * const TryStar_fields[]={
512
"body",
513
"handlers",
514
"orelse",
515
"finalbody",
516
};
517
static const char * const Assert_fields[]={
518
"test",
519
"msg",
520
};
521
static const char * const Import_fields[]={
522
"names",
523
};
524
static const char * const ImportFrom_fields[]={
525
"module",
526
"names",
527
"level",
528
};
529
static const char * const Global_fields[]={
530
"names",
531
};
532
static const char * const Nonlocal_fields[]={
533
"names",
534
};
535
static const char * const Expr_fields[]={
536
"value",
537
};
538
static const char * const expr_attributes[] = {
539
"lineno",
540
"col_offset",
541
"end_lineno",
542
"end_col_offset",
543
};
544
static PyObject* ast2obj_expr(struct ast_state *state, void*);
545
static const char * const BoolOp_fields[]={
546
"op",
547
"values",
548
};
549
static const char * const NamedExpr_fields[]={
550
"target",
551
"value",
552
};
553
static const char * const BinOp_fields[]={
554
"left",
555
"op",
556
"right",
557
};
558
static const char * const UnaryOp_fields[]={
559
"op",
560
"operand",
561
};
562
static const char * const Lambda_fields[]={
563
"args",
564
"body",
565
};
566
static const char * const IfExp_fields[]={
567
"test",
568
"body",
569
"orelse",
570
};
571
static const char * const Dict_fields[]={
572
"keys",
573
"values",
574
};
575
static const char * const Set_fields[]={
576
"elts",
577
};
578
static const char * const ListComp_fields[]={
579
"elt",
580
"generators",
581
};
582
static const char * const SetComp_fields[]={
583
"elt",
584
"generators",
585
};
586
static const char * const DictComp_fields[]={
587
"key",
588
"value",
589
"generators",
590
};
591
static const char * const GeneratorExp_fields[]={
592
"elt",
593
"generators",
594
};
595
static const char * const Await_fields[]={
596
"value",
597
};
598
static const char * const Yield_fields[]={
599
"value",
600
};
601
static const char * const YieldFrom_fields[]={
602
"value",
603
};
604
static const char * const Compare_fields[]={
605
"left",
606
"ops",
607
"comparators",
608
};
609
static const char * const Call_fields[]={
610
"func",
611
"args",
612
"keywords",
613
};
614
static const char * const FormattedValue_fields[]={
615
"value",
616
"conversion",
617
"format_spec",
618
};
619
static const char * const JoinedStr_fields[]={
620
"values",
621
};
622
static const char * const Constant_fields[]={
623
"value",
624
"kind",
625
};
626
static const char * const Attribute_fields[]={
627
"value",
628
"attr",
629
"ctx",
630
};
631
static const char * const Subscript_fields[]={
632
"value",
633
"slice",
634
"ctx",
635
};
636
static const char * const Starred_fields[]={
637
"value",
638
"ctx",
639
};
640
static const char * const Name_fields[]={
641
"id",
642
"ctx",
643
};
644
static const char * const List_fields[]={
645
"elts",
646
"ctx",
647
};
648
static const char * const Tuple_fields[]={
649
"elts",
650
"ctx",
651
};
652
static const char * const Slice_fields[]={
653
"lower",
654
"upper",
655
"step",
656
};
657
static PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty);
658
static PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty);
659
static PyObject* ast2obj_operator(struct ast_state *state, operator_ty);
660
static PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty);
661
static PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty);
662
static PyObject* ast2obj_comprehension(struct ast_state *state, void*);
663
static const char * const comprehension_fields[]={
664
"target",
665
"iter",
666
"ifs",
667
"is_async",
668
};
669
static const char * const excepthandler_attributes[] = {
670
"lineno",
671
"col_offset",
672
"end_lineno",
673
"end_col_offset",
674
};
675
static PyObject* ast2obj_excepthandler(struct ast_state *state, void*);
676
static const char * const ExceptHandler_fields[]={
677
"type",
678
"name",
679
"body",
680
};
681
static PyObject* ast2obj_arguments(struct ast_state *state, void*);
682
static const char * const arguments_fields[]={
683
"posonlyargs",
684
"args",
685
"vararg",
686
"kwonlyargs",
687
"kw_defaults",
688
"kwarg",
689
"defaults",
690
};
691
static PyObject* ast2obj_arg(struct ast_state *state, void*);
692
static const char * const arg_attributes[] = {
693
"lineno",
694
"col_offset",
695
"end_lineno",
696
"end_col_offset",
697
};
698
static const char * const arg_fields[]={
699
"arg",
700
"annotation",
701
"type_comment",
702
};
703
static PyObject* ast2obj_keyword(struct ast_state *state, void*);
704
static const char * const keyword_attributes[] = {
705
"lineno",
706
"col_offset",
707
"end_lineno",
708
"end_col_offset",
709
};
710
static const char * const keyword_fields[]={
711
"arg",
712
"value",
713
};
714
static PyObject* ast2obj_alias(struct ast_state *state, void*);
715
static const char * const alias_attributes[] = {
716
"lineno",
717
"col_offset",
718
"end_lineno",
719
"end_col_offset",
720
};
721
static const char * const alias_fields[]={
722
"name",
723
"asname",
724
};
725
static PyObject* ast2obj_withitem(struct ast_state *state, void*);
726
static const char * const withitem_fields[]={
727
"context_expr",
728
"optional_vars",
729
};
730
static PyObject* ast2obj_match_case(struct ast_state *state, void*);
731
static const char * const match_case_fields[]={
732
"pattern",
733
"guard",
734
"body",
735
};
736
static const char * const pattern_attributes[] = {
737
"lineno",
738
"col_offset",
739
"end_lineno",
740
"end_col_offset",
741
};
742
static PyObject* ast2obj_pattern(struct ast_state *state, void*);
743
static const char * const MatchValue_fields[]={
744
"value",
745
};
746
static const char * const MatchSingleton_fields[]={
747
"value",
748
};
749
static const char * const MatchSequence_fields[]={
750
"patterns",
751
};
752
static const char * const MatchMapping_fields[]={
753
"keys",
754
"patterns",
755
"rest",
756
};
757
static const char * const MatchClass_fields[]={
758
"cls",
759
"patterns",
760
"kwd_attrs",
761
"kwd_patterns",
762
};
763
static const char * const MatchStar_fields[]={
764
"name",
765
};
766
static const char * const MatchAs_fields[]={
767
"pattern",
768
"name",
769
};
770
static const char * const MatchOr_fields[]={
771
"patterns",
772
};
773
static PyObject* ast2obj_type_ignore(struct ast_state *state, void*);
774
static const char * const TypeIgnore_fields[]={
775
"lineno",
776
"tag",
777
};
778
static const char * const type_param_attributes[] = {
779
"lineno",
780
"col_offset",
781
"end_lineno",
782
"end_col_offset",
783
};
784
static PyObject* ast2obj_type_param(struct ast_state *state, void*);
785
static const char * const TypeVar_fields[]={
786
"name",
787
"bound",
788
};
789
static const char * const ParamSpec_fields[]={
790
"name",
791
};
792
static const char * const TypeVarTuple_fields[]={
793
"name",
794
};
795
796
797
798
typedef struct {
799
PyObject_HEAD
800
PyObject *dict;
801
} AST_object;
802
803
static void
804
ast_dealloc(AST_object *self)
805
{
806
/* bpo-31095: UnTrack is needed before calling any callbacks */
807
PyTypeObject *tp = Py_TYPE(self);
808
PyObject_GC_UnTrack(self);
809
Py_CLEAR(self->dict);
810
freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
811
assert(free_func != NULL);
812
free_func(self);
813
Py_DECREF(tp);
814
}
815
816
static int
817
ast_traverse(AST_object *self, visitproc visit, void *arg)
818
{
819
Py_VISIT(Py_TYPE(self));
820
Py_VISIT(self->dict);
821
return 0;
822
}
823
824
static int
825
ast_clear(AST_object *self)
826
{
827
Py_CLEAR(self->dict);
828
return 0;
829
}
830
831
static int
832
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
833
{
834
struct ast_state *state = get_ast_state();
835
if (state == NULL) {
836
return -1;
837
}
838
839
Py_ssize_t i, numfields = 0;
840
int res = -1;
841
PyObject *key, *value, *fields;
842
if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
843
goto cleanup;
844
}
845
if (fields) {
846
numfields = PySequence_Size(fields);
847
if (numfields == -1) {
848
goto cleanup;
849
}
850
}
851
852
res = 0; /* if no error occurs, this stays 0 to the end */
853
if (numfields < PyTuple_GET_SIZE(args)) {
854
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
855
"%zd positional argument%s",
856
_PyType_Name(Py_TYPE(self)),
857
numfields, numfields == 1 ? "" : "s");
858
res = -1;
859
goto cleanup;
860
}
861
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
862
/* cannot be reached when fields is NULL */
863
PyObject *name = PySequence_GetItem(fields, i);
864
if (!name) {
865
res = -1;
866
goto cleanup;
867
}
868
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
869
Py_DECREF(name);
870
if (res < 0) {
871
goto cleanup;
872
}
873
}
874
if (kw) {
875
i = 0; /* needed by PyDict_Next */
876
while (PyDict_Next(kw, &i, &key, &value)) {
877
int contains = PySequence_Contains(fields, key);
878
if (contains == -1) {
879
res = -1;
880
goto cleanup;
881
} else if (contains == 1) {
882
Py_ssize_t p = PySequence_Index(fields, key);
883
if (p == -1) {
884
res = -1;
885
goto cleanup;
886
}
887
if (p < PyTuple_GET_SIZE(args)) {
888
PyErr_Format(PyExc_TypeError,
889
"%.400s got multiple values for argument '%U'",
890
Py_TYPE(self)->tp_name, key);
891
res = -1;
892
goto cleanup;
893
}
894
}
895
res = PyObject_SetAttr(self, key, value);
896
if (res < 0) {
897
goto cleanup;
898
}
899
}
900
}
901
cleanup:
902
Py_XDECREF(fields);
903
return res;
904
}
905
906
/* Pickling support */
907
static PyObject *
908
ast_type_reduce(PyObject *self, PyObject *unused)
909
{
910
struct ast_state *state = get_ast_state();
911
if (state == NULL) {
912
return NULL;
913
}
914
915
PyObject *dict;
916
if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
917
return NULL;
918
}
919
if (dict) {
920
return Py_BuildValue("O()N", Py_TYPE(self), dict);
921
}
922
return Py_BuildValue("O()", Py_TYPE(self));
923
}
924
925
static PyMemberDef ast_type_members[] = {
926
{"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
927
{NULL} /* Sentinel */
928
};
929
930
static PyMethodDef ast_type_methods[] = {
931
{"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
932
{NULL}
933
};
934
935
static PyGetSetDef ast_type_getsets[] = {
936
{"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
937
{NULL}
938
};
939
940
static PyType_Slot AST_type_slots[] = {
941
{Py_tp_dealloc, ast_dealloc},
942
{Py_tp_getattro, PyObject_GenericGetAttr},
943
{Py_tp_setattro, PyObject_GenericSetAttr},
944
{Py_tp_traverse, ast_traverse},
945
{Py_tp_clear, ast_clear},
946
{Py_tp_members, ast_type_members},
947
{Py_tp_methods, ast_type_methods},
948
{Py_tp_getset, ast_type_getsets},
949
{Py_tp_init, ast_type_init},
950
{Py_tp_alloc, PyType_GenericAlloc},
951
{Py_tp_new, PyType_GenericNew},
952
{Py_tp_free, PyObject_GC_Del},
953
{0, 0},
954
};
955
956
static PyType_Spec AST_type_spec = {
957
"ast.AST",
958
sizeof(AST_object),
959
0,
960
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
961
AST_type_slots
962
};
963
964
static PyObject *
965
make_type(struct ast_state *state, const char *type, PyObject* base,
966
const char* const* fields, int num_fields, const char *doc)
967
{
968
PyObject *fnames, *result;
969
int i;
970
fnames = PyTuple_New(num_fields);
971
if (!fnames) return NULL;
972
for (i = 0; i < num_fields; i++) {
973
PyObject *field = PyUnicode_InternFromString(fields[i]);
974
if (!field) {
975
Py_DECREF(fnames);
976
return NULL;
977
}
978
PyTuple_SET_ITEM(fnames, i, field);
979
}
980
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
981
type, base,
982
state->_fields, fnames,
983
state->__match_args__, fnames,
984
state->__module__,
985
state->ast,
986
state->__doc__, doc);
987
Py_DECREF(fnames);
988
return result;
989
}
990
991
static int
992
add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
993
{
994
int i, result;
995
PyObject *s, *l = PyTuple_New(num_fields);
996
if (!l)
997
return 0;
998
for (i = 0; i < num_fields; i++) {
999
s = PyUnicode_InternFromString(attrs[i]);
1000
if (!s) {
1001
Py_DECREF(l);
1002
return 0;
1003
}
1004
PyTuple_SET_ITEM(l, i, s);
1005
}
1006
result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
1007
Py_DECREF(l);
1008
return result;
1009
}
1010
1011
/* Conversion AST -> Python */
1012
1013
static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq, PyObject* (*func)(struct ast_state *state, void*))
1014
{
1015
Py_ssize_t i, n = asdl_seq_LEN(seq);
1016
PyObject *result = PyList_New(n);
1017
PyObject *value;
1018
if (!result)
1019
return NULL;
1020
for (i = 0; i < n; i++) {
1021
value = func(state, asdl_seq_GET_UNTYPED(seq, i));
1022
if (!value) {
1023
Py_DECREF(result);
1024
return NULL;
1025
}
1026
PyList_SET_ITEM(result, i, value);
1027
}
1028
return result;
1029
}
1030
1031
static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
1032
{
1033
PyObject *op = (PyObject*)o;
1034
if (!op) {
1035
op = Py_None;
1036
}
1037
return Py_NewRef(op);
1038
}
1039
#define ast2obj_constant ast2obj_object
1040
#define ast2obj_identifier ast2obj_object
1041
#define ast2obj_string ast2obj_object
1042
1043
static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
1044
{
1045
return PyLong_FromLong(b);
1046
}
1047
1048
/* Conversion Python -> AST */
1049
1050
static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1051
{
1052
if (obj == Py_None)
1053
obj = NULL;
1054
if (obj) {
1055
if (_PyArena_AddPyObject(arena, obj) < 0) {
1056
*out = NULL;
1057
return -1;
1058
}
1059
*out = Py_NewRef(obj);
1060
}
1061
else {
1062
*out = NULL;
1063
}
1064
return 0;
1065
}
1066
1067
static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1068
{
1069
if (_PyArena_AddPyObject(arena, obj) < 0) {
1070
*out = NULL;
1071
return -1;
1072
}
1073
*out = Py_NewRef(obj);
1074
return 0;
1075
}
1076
1077
static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1078
{
1079
if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1080
PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
1081
return 1;
1082
}
1083
return obj2ast_object(state, obj, out, arena);
1084
}
1085
1086
static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1087
{
1088
if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1089
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1090
return 1;
1091
}
1092
return obj2ast_object(state, obj, out, arena);
1093
}
1094
1095
static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
1096
{
1097
int i;
1098
if (!PyLong_Check(obj)) {
1099
PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
1100
return 1;
1101
}
1102
1103
i = _PyLong_AsInt(obj);
1104
if (i == -1 && PyErr_Occurred())
1105
return 1;
1106
*out = i;
1107
return 0;
1108
}
1109
1110
static int add_ast_fields(struct ast_state *state)
1111
{
1112
PyObject *empty_tuple;
1113
empty_tuple = PyTuple_New(0);
1114
if (!empty_tuple ||
1115
PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
1116
PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
1117
PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
1118
Py_XDECREF(empty_tuple);
1119
return -1;
1120
}
1121
Py_DECREF(empty_tuple);
1122
return 0;
1123
}
1124
1125
1126
1127
static int
1128
init_types(struct ast_state *state)
1129
{
1130
// init_types() must not be called after _PyAST_Fini()
1131
// has been called
1132
assert(state->initialized >= 0);
1133
1134
if (state->initialized) {
1135
return 1;
1136
}
1137
if (init_identifiers(state) < 0) {
1138
return 0;
1139
}
1140
state->AST_type = PyType_FromSpec(&AST_type_spec);
1141
if (!state->AST_type) {
1142
return 0;
1143
}
1144
if (add_ast_fields(state) < 0) {
1145
return 0;
1146
}
1147
state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
1148
"mod = Module(stmt* body, type_ignore* type_ignores)\n"
1149
" | Interactive(stmt* body)\n"
1150
" | Expression(expr body)\n"
1151
" | FunctionType(expr* argtypes, expr returns)");
1152
if (!state->mod_type) return 0;
1153
if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
1154
state->Module_type = make_type(state, "Module", state->mod_type,
1155
Module_fields, 2,
1156
"Module(stmt* body, type_ignore* type_ignores)");
1157
if (!state->Module_type) return 0;
1158
state->Interactive_type = make_type(state, "Interactive", state->mod_type,
1159
Interactive_fields, 1,
1160
"Interactive(stmt* body)");
1161
if (!state->Interactive_type) return 0;
1162
state->Expression_type = make_type(state, "Expression", state->mod_type,
1163
Expression_fields, 1,
1164
"Expression(expr body)");
1165
if (!state->Expression_type) return 0;
1166
state->FunctionType_type = make_type(state, "FunctionType",
1167
state->mod_type, FunctionType_fields,
1168
2,
1169
"FunctionType(expr* argtypes, expr returns)");
1170
if (!state->FunctionType_type) return 0;
1171
state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
1172
"stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
1173
" | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
1174
" | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
1175
" | Return(expr? value)\n"
1176
" | Delete(expr* targets)\n"
1177
" | Assign(expr* targets, expr value, string? type_comment)\n"
1178
" | TypeAlias(expr name, type_param* type_params, expr value)\n"
1179
" | AugAssign(expr target, operator op, expr value)\n"
1180
" | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1181
" | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1182
" | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1183
" | While(expr test, stmt* body, stmt* orelse)\n"
1184
" | If(expr test, stmt* body, stmt* orelse)\n"
1185
" | With(withitem* items, stmt* body, string? type_comment)\n"
1186
" | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1187
" | Match(expr subject, match_case* cases)\n"
1188
" | Raise(expr? exc, expr? cause)\n"
1189
" | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1190
" | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1191
" | Assert(expr test, expr? msg)\n"
1192
" | Import(alias* names)\n"
1193
" | ImportFrom(identifier? module, alias* names, int? level)\n"
1194
" | Global(identifier* names)\n"
1195
" | Nonlocal(identifier* names)\n"
1196
" | Expr(expr value)\n"
1197
" | Pass\n"
1198
" | Break\n"
1199
" | Continue");
1200
if (!state->stmt_type) return 0;
1201
if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
1202
if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1203
return 0;
1204
if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1205
-1)
1206
return 0;
1207
state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
1208
FunctionDef_fields, 7,
1209
"FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
1210
if (!state->FunctionDef_type) return 0;
1211
if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1212
-1)
1213
return 0;
1214
if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1215
== -1)
1216
return 0;
1217
state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
1218
state->stmt_type,
1219
AsyncFunctionDef_fields, 7,
1220
"AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
1221
if (!state->AsyncFunctionDef_type) return 0;
1222
if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1223
== -1)
1224
return 0;
1225
if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1226
Py_None) == -1)
1227
return 0;
1228
state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
1229
ClassDef_fields, 6,
1230
"ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
1231
if (!state->ClassDef_type) return 0;
1232
state->Return_type = make_type(state, "Return", state->stmt_type,
1233
Return_fields, 1,
1234
"Return(expr? value)");
1235
if (!state->Return_type) return 0;
1236
if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1237
return 0;
1238
state->Delete_type = make_type(state, "Delete", state->stmt_type,
1239
Delete_fields, 1,
1240
"Delete(expr* targets)");
1241
if (!state->Delete_type) return 0;
1242
state->Assign_type = make_type(state, "Assign", state->stmt_type,
1243
Assign_fields, 3,
1244
"Assign(expr* targets, expr value, string? type_comment)");
1245
if (!state->Assign_type) return 0;
1246
if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1247
-1)
1248
return 0;
1249
state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
1250
TypeAlias_fields, 3,
1251
"TypeAlias(expr name, type_param* type_params, expr value)");
1252
if (!state->TypeAlias_type) return 0;
1253
state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
1254
AugAssign_fields, 3,
1255
"AugAssign(expr target, operator op, expr value)");
1256
if (!state->AugAssign_type) return 0;
1257
state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
1258
AnnAssign_fields, 4,
1259
"AnnAssign(expr target, expr annotation, expr? value, int simple)");
1260
if (!state->AnnAssign_type) return 0;
1261
if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1262
return 0;
1263
state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
1264
"For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1265
if (!state->For_type) return 0;
1266
if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1267
return 0;
1268
state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
1269
AsyncFor_fields, 5,
1270
"AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1271
if (!state->AsyncFor_type) return 0;
1272
if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1273
-1)
1274
return 0;
1275
state->While_type = make_type(state, "While", state->stmt_type,
1276
While_fields, 3,
1277
"While(expr test, stmt* body, stmt* orelse)");
1278
if (!state->While_type) return 0;
1279
state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
1280
"If(expr test, stmt* body, stmt* orelse)");
1281
if (!state->If_type) return 0;
1282
state->With_type = make_type(state, "With", state->stmt_type, With_fields,
1283
3,
1284
"With(withitem* items, stmt* body, string? type_comment)");
1285
if (!state->With_type) return 0;
1286
if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1287
return 0;
1288
state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
1289
AsyncWith_fields, 3,
1290
"AsyncWith(withitem* items, stmt* body, string? type_comment)");
1291
if (!state->AsyncWith_type) return 0;
1292
if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1293
== -1)
1294
return 0;
1295
state->Match_type = make_type(state, "Match", state->stmt_type,
1296
Match_fields, 2,
1297
"Match(expr subject, match_case* cases)");
1298
if (!state->Match_type) return 0;
1299
state->Raise_type = make_type(state, "Raise", state->stmt_type,
1300
Raise_fields, 2,
1301
"Raise(expr? exc, expr? cause)");
1302
if (!state->Raise_type) return 0;
1303
if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1304
return 0;
1305
if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1306
return 0;
1307
state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
1308
"Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
1309
if (!state->Try_type) return 0;
1310
state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
1311
TryStar_fields, 4,
1312
"TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
1313
if (!state->TryStar_type) return 0;
1314
state->Assert_type = make_type(state, "Assert", state->stmt_type,
1315
Assert_fields, 2,
1316
"Assert(expr test, expr? msg)");
1317
if (!state->Assert_type) return 0;
1318
if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1319
return 0;
1320
state->Import_type = make_type(state, "Import", state->stmt_type,
1321
Import_fields, 1,
1322
"Import(alias* names)");
1323
if (!state->Import_type) return 0;
1324
state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
1325
ImportFrom_fields, 3,
1326
"ImportFrom(identifier? module, alias* names, int? level)");
1327
if (!state->ImportFrom_type) return 0;
1328
if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1329
return 0;
1330
if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1331
return 0;
1332
state->Global_type = make_type(state, "Global", state->stmt_type,
1333
Global_fields, 1,
1334
"Global(identifier* names)");
1335
if (!state->Global_type) return 0;
1336
state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
1337
Nonlocal_fields, 1,
1338
"Nonlocal(identifier* names)");
1339
if (!state->Nonlocal_type) return 0;
1340
state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
1341
1,
1342
"Expr(expr value)");
1343
if (!state->Expr_type) return 0;
1344
state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
1345
"Pass");
1346
if (!state->Pass_type) return 0;
1347
state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
1348
"Break");
1349
if (!state->Break_type) return 0;
1350
state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
1351
0,
1352
"Continue");
1353
if (!state->Continue_type) return 0;
1354
state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
1355
"expr = BoolOp(boolop op, expr* values)\n"
1356
" | NamedExpr(expr target, expr value)\n"
1357
" | BinOp(expr left, operator op, expr right)\n"
1358
" | UnaryOp(unaryop op, expr operand)\n"
1359
" | Lambda(arguments args, expr body)\n"
1360
" | IfExp(expr test, expr body, expr orelse)\n"
1361
" | Dict(expr* keys, expr* values)\n"
1362
" | Set(expr* elts)\n"
1363
" | ListComp(expr elt, comprehension* generators)\n"
1364
" | SetComp(expr elt, comprehension* generators)\n"
1365
" | DictComp(expr key, expr value, comprehension* generators)\n"
1366
" | GeneratorExp(expr elt, comprehension* generators)\n"
1367
" | Await(expr value)\n"
1368
" | Yield(expr? value)\n"
1369
" | YieldFrom(expr value)\n"
1370
" | Compare(expr left, cmpop* ops, expr* comparators)\n"
1371
" | Call(expr func, expr* args, keyword* keywords)\n"
1372
" | FormattedValue(expr value, int conversion, expr? format_spec)\n"
1373
" | JoinedStr(expr* values)\n"
1374
" | Constant(constant value, string? kind)\n"
1375
" | Attribute(expr value, identifier attr, expr_context ctx)\n"
1376
" | Subscript(expr value, expr slice, expr_context ctx)\n"
1377
" | Starred(expr value, expr_context ctx)\n"
1378
" | Name(identifier id, expr_context ctx)\n"
1379
" | List(expr* elts, expr_context ctx)\n"
1380
" | Tuple(expr* elts, expr_context ctx)\n"
1381
" | Slice(expr? lower, expr? upper, expr? step)");
1382
if (!state->expr_type) return 0;
1383
if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
1384
if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1385
return 0;
1386
if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1387
-1)
1388
return 0;
1389
state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
1390
BoolOp_fields, 2,
1391
"BoolOp(boolop op, expr* values)");
1392
if (!state->BoolOp_type) return 0;
1393
state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
1394
NamedExpr_fields, 2,
1395
"NamedExpr(expr target, expr value)");
1396
if (!state->NamedExpr_type) return 0;
1397
state->BinOp_type = make_type(state, "BinOp", state->expr_type,
1398
BinOp_fields, 3,
1399
"BinOp(expr left, operator op, expr right)");
1400
if (!state->BinOp_type) return 0;
1401
state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
1402
UnaryOp_fields, 2,
1403
"UnaryOp(unaryop op, expr operand)");
1404
if (!state->UnaryOp_type) return 0;
1405
state->Lambda_type = make_type(state, "Lambda", state->expr_type,
1406
Lambda_fields, 2,
1407
"Lambda(arguments args, expr body)");
1408
if (!state->Lambda_type) return 0;
1409
state->IfExp_type = make_type(state, "IfExp", state->expr_type,
1410
IfExp_fields, 3,
1411
"IfExp(expr test, expr body, expr orelse)");
1412
if (!state->IfExp_type) return 0;
1413
state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
1414
2,
1415
"Dict(expr* keys, expr* values)");
1416
if (!state->Dict_type) return 0;
1417
state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
1418
"Set(expr* elts)");
1419
if (!state->Set_type) return 0;
1420
state->ListComp_type = make_type(state, "ListComp", state->expr_type,
1421
ListComp_fields, 2,
1422
"ListComp(expr elt, comprehension* generators)");
1423
if (!state->ListComp_type) return 0;
1424
state->SetComp_type = make_type(state, "SetComp", state->expr_type,
1425
SetComp_fields, 2,
1426
"SetComp(expr elt, comprehension* generators)");
1427
if (!state->SetComp_type) return 0;
1428
state->DictComp_type = make_type(state, "DictComp", state->expr_type,
1429
DictComp_fields, 3,
1430
"DictComp(expr key, expr value, comprehension* generators)");
1431
if (!state->DictComp_type) return 0;
1432
state->GeneratorExp_type = make_type(state, "GeneratorExp",
1433
state->expr_type, GeneratorExp_fields,
1434
2,
1435
"GeneratorExp(expr elt, comprehension* generators)");
1436
if (!state->GeneratorExp_type) return 0;
1437
state->Await_type = make_type(state, "Await", state->expr_type,
1438
Await_fields, 1,
1439
"Await(expr value)");
1440
if (!state->Await_type) return 0;
1441
state->Yield_type = make_type(state, "Yield", state->expr_type,
1442
Yield_fields, 1,
1443
"Yield(expr? value)");
1444
if (!state->Yield_type) return 0;
1445
if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1446
return 0;
1447
state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
1448
YieldFrom_fields, 1,
1449
"YieldFrom(expr value)");
1450
if (!state->YieldFrom_type) return 0;
1451
state->Compare_type = make_type(state, "Compare", state->expr_type,
1452
Compare_fields, 3,
1453
"Compare(expr left, cmpop* ops, expr* comparators)");
1454
if (!state->Compare_type) return 0;
1455
state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
1456
3,
1457
"Call(expr func, expr* args, keyword* keywords)");
1458
if (!state->Call_type) return 0;
1459
state->FormattedValue_type = make_type(state, "FormattedValue",
1460
state->expr_type,
1461
FormattedValue_fields, 3,
1462
"FormattedValue(expr value, int conversion, expr? format_spec)");
1463
if (!state->FormattedValue_type) return 0;
1464
if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1465
Py_None) == -1)
1466
return 0;
1467
state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
1468
JoinedStr_fields, 1,
1469
"JoinedStr(expr* values)");
1470
if (!state->JoinedStr_type) return 0;
1471
state->Constant_type = make_type(state, "Constant", state->expr_type,
1472
Constant_fields, 2,
1473
"Constant(constant value, string? kind)");
1474
if (!state->Constant_type) return 0;
1475
if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1476
return 0;
1477
state->Attribute_type = make_type(state, "Attribute", state->expr_type,
1478
Attribute_fields, 3,
1479
"Attribute(expr value, identifier attr, expr_context ctx)");
1480
if (!state->Attribute_type) return 0;
1481
state->Subscript_type = make_type(state, "Subscript", state->expr_type,
1482
Subscript_fields, 3,
1483
"Subscript(expr value, expr slice, expr_context ctx)");
1484
if (!state->Subscript_type) return 0;
1485
state->Starred_type = make_type(state, "Starred", state->expr_type,
1486
Starred_fields, 2,
1487
"Starred(expr value, expr_context ctx)");
1488
if (!state->Starred_type) return 0;
1489
state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
1490
2,
1491
"Name(identifier id, expr_context ctx)");
1492
if (!state->Name_type) return 0;
1493
state->List_type = make_type(state, "List", state->expr_type, List_fields,
1494
2,
1495
"List(expr* elts, expr_context ctx)");
1496
if (!state->List_type) return 0;
1497
state->Tuple_type = make_type(state, "Tuple", state->expr_type,
1498
Tuple_fields, 2,
1499
"Tuple(expr* elts, expr_context ctx)");
1500
if (!state->Tuple_type) return 0;
1501
state->Slice_type = make_type(state, "Slice", state->expr_type,
1502
Slice_fields, 3,
1503
"Slice(expr? lower, expr? upper, expr? step)");
1504
if (!state->Slice_type) return 0;
1505
if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1506
return 0;
1507
if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1508
return 0;
1509
if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1510
return 0;
1511
state->expr_context_type = make_type(state, "expr_context",
1512
state->AST_type, NULL, 0,
1513
"expr_context = Load | Store | Del");
1514
if (!state->expr_context_type) return 0;
1515
if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
1516
state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
1517
0,
1518
"Load");
1519
if (!state->Load_type) return 0;
1520
state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1521
NULL, NULL);
1522
if (!state->Load_singleton) return 0;
1523
state->Store_type = make_type(state, "Store", state->expr_context_type,
1524
NULL, 0,
1525
"Store");
1526
if (!state->Store_type) return 0;
1527
state->Store_singleton = PyType_GenericNew((PyTypeObject
1528
*)state->Store_type, NULL, NULL);
1529
if (!state->Store_singleton) return 0;
1530
state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
1531
"Del");
1532
if (!state->Del_type) return 0;
1533
state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1534
NULL, NULL);
1535
if (!state->Del_singleton) return 0;
1536
state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
1537
"boolop = And | Or");
1538
if (!state->boolop_type) return 0;
1539
if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
1540
state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
1541
"And");
1542
if (!state->And_type) return 0;
1543
state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1544
NULL, NULL);
1545
if (!state->And_singleton) return 0;
1546
state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
1547
"Or");
1548
if (!state->Or_type) return 0;
1549
state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1550
NULL, NULL);
1551
if (!state->Or_singleton) return 0;
1552
state->operator_type = make_type(state, "operator", state->AST_type, NULL,
1553
0,
1554
"operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
1555
if (!state->operator_type) return 0;
1556
if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
1557
state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
1558
"Add");
1559
if (!state->Add_type) return 0;
1560
state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1561
NULL, NULL);
1562
if (!state->Add_singleton) return 0;
1563
state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
1564
"Sub");
1565
if (!state->Sub_type) return 0;
1566
state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1567
NULL, NULL);
1568
if (!state->Sub_singleton) return 0;
1569
state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
1570
"Mult");
1571
if (!state->Mult_type) return 0;
1572
state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1573
NULL, NULL);
1574
if (!state->Mult_singleton) return 0;
1575
state->MatMult_type = make_type(state, "MatMult", state->operator_type,
1576
NULL, 0,
1577
"MatMult");
1578
if (!state->MatMult_type) return 0;
1579
state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1580
*)state->MatMult_type, NULL,
1581
NULL);
1582
if (!state->MatMult_singleton) return 0;
1583
state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
1584
"Div");
1585
if (!state->Div_type) return 0;
1586
state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1587
NULL, NULL);
1588
if (!state->Div_singleton) return 0;
1589
state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
1590
"Mod");
1591
if (!state->Mod_type) return 0;
1592
state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1593
NULL, NULL);
1594
if (!state->Mod_singleton) return 0;
1595
state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
1596
"Pow");
1597
if (!state->Pow_type) return 0;
1598
state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1599
NULL, NULL);
1600
if (!state->Pow_singleton) return 0;
1601
state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
1602
0,
1603
"LShift");
1604
if (!state->LShift_type) return 0;
1605
state->LShift_singleton = PyType_GenericNew((PyTypeObject
1606
*)state->LShift_type, NULL,
1607
NULL);
1608
if (!state->LShift_singleton) return 0;
1609
state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
1610
0,
1611
"RShift");
1612
if (!state->RShift_type) return 0;
1613
state->RShift_singleton = PyType_GenericNew((PyTypeObject
1614
*)state->RShift_type, NULL,
1615
NULL);
1616
if (!state->RShift_singleton) return 0;
1617
state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
1618
"BitOr");
1619
if (!state->BitOr_type) return 0;
1620
state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1621
*)state->BitOr_type, NULL, NULL);
1622
if (!state->BitOr_singleton) return 0;
1623
state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
1624
0,
1625
"BitXor");
1626
if (!state->BitXor_type) return 0;
1627
state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1628
*)state->BitXor_type, NULL,
1629
NULL);
1630
if (!state->BitXor_singleton) return 0;
1631
state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
1632
0,
1633
"BitAnd");
1634
if (!state->BitAnd_type) return 0;
1635
state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1636
*)state->BitAnd_type, NULL,
1637
NULL);
1638
if (!state->BitAnd_singleton) return 0;
1639
state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
1640
NULL, 0,
1641
"FloorDiv");
1642
if (!state->FloorDiv_type) return 0;
1643
state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1644
*)state->FloorDiv_type, NULL,
1645
NULL);
1646
if (!state->FloorDiv_singleton) return 0;
1647
state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
1648
"unaryop = Invert | Not | UAdd | USub");
1649
if (!state->unaryop_type) return 0;
1650
if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
1651
state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
1652
0,
1653
"Invert");
1654
if (!state->Invert_type) return 0;
1655
state->Invert_singleton = PyType_GenericNew((PyTypeObject
1656
*)state->Invert_type, NULL,
1657
NULL);
1658
if (!state->Invert_singleton) return 0;
1659
state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
1660
"Not");
1661
if (!state->Not_type) return 0;
1662
state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1663
NULL, NULL);
1664
if (!state->Not_singleton) return 0;
1665
state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
1666
"UAdd");
1667
if (!state->UAdd_type) return 0;
1668
state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1669
NULL, NULL);
1670
if (!state->UAdd_singleton) return 0;
1671
state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
1672
"USub");
1673
if (!state->USub_type) return 0;
1674
state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1675
NULL, NULL);
1676
if (!state->USub_singleton) return 0;
1677
state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
1678
"cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
1679
if (!state->cmpop_type) return 0;
1680
if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
1681
state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
1682
"Eq");
1683
if (!state->Eq_type) return 0;
1684
state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1685
NULL, NULL);
1686
if (!state->Eq_singleton) return 0;
1687
state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
1688
"NotEq");
1689
if (!state->NotEq_type) return 0;
1690
state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1691
*)state->NotEq_type, NULL, NULL);
1692
if (!state->NotEq_singleton) return 0;
1693
state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
1694
"Lt");
1695
if (!state->Lt_type) return 0;
1696
state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1697
NULL, NULL);
1698
if (!state->Lt_singleton) return 0;
1699
state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
1700
"LtE");
1701
if (!state->LtE_type) return 0;
1702
state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1703
NULL, NULL);
1704
if (!state->LtE_singleton) return 0;
1705
state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
1706
"Gt");
1707
if (!state->Gt_type) return 0;
1708
state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1709
NULL, NULL);
1710
if (!state->Gt_singleton) return 0;
1711
state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
1712
"GtE");
1713
if (!state->GtE_type) return 0;
1714
state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1715
NULL, NULL);
1716
if (!state->GtE_singleton) return 0;
1717
state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
1718
"Is");
1719
if (!state->Is_type) return 0;
1720
state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1721
NULL, NULL);
1722
if (!state->Is_singleton) return 0;
1723
state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
1724
"IsNot");
1725
if (!state->IsNot_type) return 0;
1726
state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1727
*)state->IsNot_type, NULL, NULL);
1728
if (!state->IsNot_singleton) return 0;
1729
state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
1730
"In");
1731
if (!state->In_type) return 0;
1732
state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1733
NULL, NULL);
1734
if (!state->In_singleton) return 0;
1735
state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
1736
"NotIn");
1737
if (!state->NotIn_type) return 0;
1738
state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1739
*)state->NotIn_type, NULL, NULL);
1740
if (!state->NotIn_singleton) return 0;
1741
state->comprehension_type = make_type(state, "comprehension",
1742
state->AST_type,
1743
comprehension_fields, 4,
1744
"comprehension(expr target, expr iter, expr* ifs, int is_async)");
1745
if (!state->comprehension_type) return 0;
1746
if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
1747
state->excepthandler_type = make_type(state, "excepthandler",
1748
state->AST_type, NULL, 0,
1749
"excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
1750
if (!state->excepthandler_type) return 0;
1751
if (!add_attributes(state, state->excepthandler_type,
1752
excepthandler_attributes, 4)) return 0;
1753
if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1754
== -1)
1755
return 0;
1756
if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1757
Py_None) == -1)
1758
return 0;
1759
state->ExceptHandler_type = make_type(state, "ExceptHandler",
1760
state->excepthandler_type,
1761
ExceptHandler_fields, 3,
1762
"ExceptHandler(expr? type, identifier? name, stmt* body)");
1763
if (!state->ExceptHandler_type) return 0;
1764
if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1765
return 0;
1766
if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1767
return 0;
1768
state->arguments_type = make_type(state, "arguments", state->AST_type,
1769
arguments_fields, 7,
1770
"arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
1771
if (!state->arguments_type) return 0;
1772
if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
1773
if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1774
return 0;
1775
if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1776
return 0;
1777
state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
1778
"arg(identifier arg, expr? annotation, string? type_comment)");
1779
if (!state->arg_type) return 0;
1780
if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
1781
if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1782
return 0;
1783
if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1784
return 0;
1785
if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1786
return 0;
1787
if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1788
return 0;
1789
state->keyword_type = make_type(state, "keyword", state->AST_type,
1790
keyword_fields, 2,
1791
"keyword(identifier? arg, expr value)");
1792
if (!state->keyword_type) return 0;
1793
if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
1794
return 0;
1795
if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1796
return 0;
1797
if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1798
return 0;
1799
if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1800
== -1)
1801
return 0;
1802
state->alias_type = make_type(state, "alias", state->AST_type,
1803
alias_fields, 2,
1804
"alias(identifier name, identifier? asname)");
1805
if (!state->alias_type) return 0;
1806
if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
1807
0;
1808
if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1809
return 0;
1810
if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
1811
return 0;
1812
if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
1813
-1)
1814
return 0;
1815
state->withitem_type = make_type(state, "withitem", state->AST_type,
1816
withitem_fields, 2,
1817
"withitem(expr context_expr, expr? optional_vars)");
1818
if (!state->withitem_type) return 0;
1819
if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
1820
if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1821
== -1)
1822
return 0;
1823
state->match_case_type = make_type(state, "match_case", state->AST_type,
1824
match_case_fields, 3,
1825
"match_case(pattern pattern, expr? guard, stmt* body)");
1826
if (!state->match_case_type) return 0;
1827
if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
1828
if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
1829
return 0;
1830
state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
1831
"pattern = MatchValue(expr value)\n"
1832
" | MatchSingleton(constant value)\n"
1833
" | MatchSequence(pattern* patterns)\n"
1834
" | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
1835
" | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
1836
" | MatchStar(identifier? name)\n"
1837
" | MatchAs(pattern? pattern, identifier? name)\n"
1838
" | MatchOr(pattern* patterns)");
1839
if (!state->pattern_type) return 0;
1840
if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
1841
return 0;
1842
state->MatchValue_type = make_type(state, "MatchValue",
1843
state->pattern_type, MatchValue_fields,
1844
1,
1845
"MatchValue(expr value)");
1846
if (!state->MatchValue_type) return 0;
1847
state->MatchSingleton_type = make_type(state, "MatchSingleton",
1848
state->pattern_type,
1849
MatchSingleton_fields, 1,
1850
"MatchSingleton(constant value)");
1851
if (!state->MatchSingleton_type) return 0;
1852
state->MatchSequence_type = make_type(state, "MatchSequence",
1853
state->pattern_type,
1854
MatchSequence_fields, 1,
1855
"MatchSequence(pattern* patterns)");
1856
if (!state->MatchSequence_type) return 0;
1857
state->MatchMapping_type = make_type(state, "MatchMapping",
1858
state->pattern_type,
1859
MatchMapping_fields, 3,
1860
"MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
1861
if (!state->MatchMapping_type) return 0;
1862
if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
1863
return 0;
1864
state->MatchClass_type = make_type(state, "MatchClass",
1865
state->pattern_type, MatchClass_fields,
1866
4,
1867
"MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
1868
if (!state->MatchClass_type) return 0;
1869
state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
1870
MatchStar_fields, 1,
1871
"MatchStar(identifier? name)");
1872
if (!state->MatchStar_type) return 0;
1873
if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
1874
return 0;
1875
state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
1876
MatchAs_fields, 2,
1877
"MatchAs(pattern? pattern, identifier? name)");
1878
if (!state->MatchAs_type) return 0;
1879
if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
1880
return 0;
1881
if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
1882
return 0;
1883
state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
1884
MatchOr_fields, 1,
1885
"MatchOr(pattern* patterns)");
1886
if (!state->MatchOr_type) return 0;
1887
state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
1888
NULL, 0,
1889
"type_ignore = TypeIgnore(int lineno, string tag)");
1890
if (!state->type_ignore_type) return 0;
1891
if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
1892
state->TypeIgnore_type = make_type(state, "TypeIgnore",
1893
state->type_ignore_type,
1894
TypeIgnore_fields, 2,
1895
"TypeIgnore(int lineno, string tag)");
1896
if (!state->TypeIgnore_type) return 0;
1897
state->type_param_type = make_type(state, "type_param", state->AST_type,
1898
NULL, 0,
1899
"type_param = TypeVar(identifier name, expr? bound)\n"
1900
" | ParamSpec(identifier name)\n"
1901
" | TypeVarTuple(identifier name)");
1902
if (!state->type_param_type) return 0;
1903
if (!add_attributes(state, state->type_param_type, type_param_attributes,
1904
4)) return 0;
1905
state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
1906
TypeVar_fields, 2,
1907
"TypeVar(identifier name, expr? bound)");
1908
if (!state->TypeVar_type) return 0;
1909
if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
1910
return 0;
1911
state->ParamSpec_type = make_type(state, "ParamSpec",
1912
state->type_param_type, ParamSpec_fields,
1913
1,
1914
"ParamSpec(identifier name)");
1915
if (!state->ParamSpec_type) return 0;
1916
state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
1917
state->type_param_type,
1918
TypeVarTuple_fields, 1,
1919
"TypeVarTuple(identifier name)");
1920
if (!state->TypeVarTuple_type) return 0;
1921
1922
state->recursion_depth = 0;
1923
state->recursion_limit = 0;
1924
state->initialized = 1;
1925
return 1;
1926
}
1927
1928
static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
1929
PyArena* arena);
1930
static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
1931
PyArena* arena);
1932
static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
1933
PyArena* arena);
1934
static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
1935
expr_context_ty* out, PyArena* arena);
1936
static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
1937
out, PyArena* arena);
1938
static int obj2ast_operator(struct ast_state *state, PyObject* obj,
1939
operator_ty* out, PyArena* arena);
1940
static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
1941
out, PyArena* arena);
1942
static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
1943
PyArena* arena);
1944
static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
1945
comprehension_ty* out, PyArena* arena);
1946
static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
1947
excepthandler_ty* out, PyArena* arena);
1948
static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
1949
arguments_ty* out, PyArena* arena);
1950
static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
1951
PyArena* arena);
1952
static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
1953
out, PyArena* arena);
1954
static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
1955
PyArena* arena);
1956
static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
1957
withitem_ty* out, PyArena* arena);
1958
static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
1959
match_case_ty* out, PyArena* arena);
1960
static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
1961
out, PyArena* arena);
1962
static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
1963
type_ignore_ty* out, PyArena* arena);
1964
static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
1965
type_param_ty* out, PyArena* arena);
1966
1967
mod_ty
1968
_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
1969
PyArena *arena)
1970
{
1971
mod_ty p;
1972
p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1973
if (!p)
1974
return NULL;
1975
p->kind = Module_kind;
1976
p->v.Module.body = body;
1977
p->v.Module.type_ignores = type_ignores;
1978
return p;
1979
}
1980
1981
mod_ty
1982
_PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
1983
{
1984
mod_ty p;
1985
p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1986
if (!p)
1987
return NULL;
1988
p->kind = Interactive_kind;
1989
p->v.Interactive.body = body;
1990
return p;
1991
}
1992
1993
mod_ty
1994
_PyAST_Expression(expr_ty body, PyArena *arena)
1995
{
1996
mod_ty p;
1997
if (!body) {
1998
PyErr_SetString(PyExc_ValueError,
1999
"field 'body' is required for Expression");
2000
return NULL;
2001
}
2002
p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
2003
if (!p)
2004
return NULL;
2005
p->kind = Expression_kind;
2006
p->v.Expression.body = body;
2007
return p;
2008
}
2009
2010
mod_ty
2011
_PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
2012
{
2013
mod_ty p;
2014
if (!returns) {
2015
PyErr_SetString(PyExc_ValueError,
2016
"field 'returns' is required for FunctionType");
2017
return NULL;
2018
}
2019
p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
2020
if (!p)
2021
return NULL;
2022
p->kind = FunctionType_kind;
2023
p->v.FunctionType.argtypes = argtypes;
2024
p->v.FunctionType.returns = returns;
2025
return p;
2026
}
2027
2028
stmt_ty
2029
_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
2030
asdl_expr_seq * decorator_list, expr_ty returns, string
2031
type_comment, asdl_type_param_seq * type_params, int lineno,
2032
int col_offset, int end_lineno, int end_col_offset, PyArena
2033
*arena)
2034
{
2035
stmt_ty p;
2036
if (!name) {
2037
PyErr_SetString(PyExc_ValueError,
2038
"field 'name' is required for FunctionDef");
2039
return NULL;
2040
}
2041
if (!args) {
2042
PyErr_SetString(PyExc_ValueError,
2043
"field 'args' is required for FunctionDef");
2044
return NULL;
2045
}
2046
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2047
if (!p)
2048
return NULL;
2049
p->kind = FunctionDef_kind;
2050
p->v.FunctionDef.name = name;
2051
p->v.FunctionDef.args = args;
2052
p->v.FunctionDef.body = body;
2053
p->v.FunctionDef.decorator_list = decorator_list;
2054
p->v.FunctionDef.returns = returns;
2055
p->v.FunctionDef.type_comment = type_comment;
2056
p->v.FunctionDef.type_params = type_params;
2057
p->lineno = lineno;
2058
p->col_offset = col_offset;
2059
p->end_lineno = end_lineno;
2060
p->end_col_offset = end_col_offset;
2061
return p;
2062
}
2063
2064
stmt_ty
2065
_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
2066
body, asdl_expr_seq * decorator_list, expr_ty returns,
2067
string type_comment, asdl_type_param_seq * type_params,
2068
int lineno, int col_offset, int end_lineno, int
2069
end_col_offset, PyArena *arena)
2070
{
2071
stmt_ty p;
2072
if (!name) {
2073
PyErr_SetString(PyExc_ValueError,
2074
"field 'name' is required for AsyncFunctionDef");
2075
return NULL;
2076
}
2077
if (!args) {
2078
PyErr_SetString(PyExc_ValueError,
2079
"field 'args' is required for AsyncFunctionDef");
2080
return NULL;
2081
}
2082
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2083
if (!p)
2084
return NULL;
2085
p->kind = AsyncFunctionDef_kind;
2086
p->v.AsyncFunctionDef.name = name;
2087
p->v.AsyncFunctionDef.args = args;
2088
p->v.AsyncFunctionDef.body = body;
2089
p->v.AsyncFunctionDef.decorator_list = decorator_list;
2090
p->v.AsyncFunctionDef.returns = returns;
2091
p->v.AsyncFunctionDef.type_comment = type_comment;
2092
p->v.AsyncFunctionDef.type_params = type_params;
2093
p->lineno = lineno;
2094
p->col_offset = col_offset;
2095
p->end_lineno = end_lineno;
2096
p->end_col_offset = end_col_offset;
2097
return p;
2098
}
2099
2100
stmt_ty
2101
_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
2102
keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
2103
asdl_type_param_seq * type_params, int lineno, int col_offset,
2104
int end_lineno, int end_col_offset, PyArena *arena)
2105
{
2106
stmt_ty p;
2107
if (!name) {
2108
PyErr_SetString(PyExc_ValueError,
2109
"field 'name' is required for ClassDef");
2110
return NULL;
2111
}
2112
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2113
if (!p)
2114
return NULL;
2115
p->kind = ClassDef_kind;
2116
p->v.ClassDef.name = name;
2117
p->v.ClassDef.bases = bases;
2118
p->v.ClassDef.keywords = keywords;
2119
p->v.ClassDef.body = body;
2120
p->v.ClassDef.decorator_list = decorator_list;
2121
p->v.ClassDef.type_params = type_params;
2122
p->lineno = lineno;
2123
p->col_offset = col_offset;
2124
p->end_lineno = end_lineno;
2125
p->end_col_offset = end_col_offset;
2126
return p;
2127
}
2128
2129
stmt_ty
2130
_PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2131
end_col_offset, PyArena *arena)
2132
{
2133
stmt_ty p;
2134
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2135
if (!p)
2136
return NULL;
2137
p->kind = Return_kind;
2138
p->v.Return.value = value;
2139
p->lineno = lineno;
2140
p->col_offset = col_offset;
2141
p->end_lineno = end_lineno;
2142
p->end_col_offset = end_col_offset;
2143
return p;
2144
}
2145
2146
stmt_ty
2147
_PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
2148
end_lineno, int end_col_offset, PyArena *arena)
2149
{
2150
stmt_ty p;
2151
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2152
if (!p)
2153
return NULL;
2154
p->kind = Delete_kind;
2155
p->v.Delete.targets = targets;
2156
p->lineno = lineno;
2157
p->col_offset = col_offset;
2158
p->end_lineno = end_lineno;
2159
p->end_col_offset = end_col_offset;
2160
return p;
2161
}
2162
2163
stmt_ty
2164
_PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
2165
lineno, int col_offset, int end_lineno, int end_col_offset,
2166
PyArena *arena)
2167
{
2168
stmt_ty p;
2169
if (!value) {
2170
PyErr_SetString(PyExc_ValueError,
2171
"field 'value' is required for Assign");
2172
return NULL;
2173
}
2174
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2175
if (!p)
2176
return NULL;
2177
p->kind = Assign_kind;
2178
p->v.Assign.targets = targets;
2179
p->v.Assign.value = value;
2180
p->v.Assign.type_comment = type_comment;
2181
p->lineno = lineno;
2182
p->col_offset = col_offset;
2183
p->end_lineno = end_lineno;
2184
p->end_col_offset = end_col_offset;
2185
return p;
2186
}
2187
2188
stmt_ty
2189
_PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
2190
value, int lineno, int col_offset, int end_lineno, int
2191
end_col_offset, PyArena *arena)
2192
{
2193
stmt_ty p;
2194
if (!name) {
2195
PyErr_SetString(PyExc_ValueError,
2196
"field 'name' is required for TypeAlias");
2197
return NULL;
2198
}
2199
if (!value) {
2200
PyErr_SetString(PyExc_ValueError,
2201
"field 'value' is required for TypeAlias");
2202
return NULL;
2203
}
2204
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2205
if (!p)
2206
return NULL;
2207
p->kind = TypeAlias_kind;
2208
p->v.TypeAlias.name = name;
2209
p->v.TypeAlias.type_params = type_params;
2210
p->v.TypeAlias.value = value;
2211
p->lineno = lineno;
2212
p->col_offset = col_offset;
2213
p->end_lineno = end_lineno;
2214
p->end_col_offset = end_col_offset;
2215
return p;
2216
}
2217
2218
stmt_ty
2219
_PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
2220
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2221
{
2222
stmt_ty p;
2223
if (!target) {
2224
PyErr_SetString(PyExc_ValueError,
2225
"field 'target' is required for AugAssign");
2226
return NULL;
2227
}
2228
if (!op) {
2229
PyErr_SetString(PyExc_ValueError,
2230
"field 'op' is required for AugAssign");
2231
return NULL;
2232
}
2233
if (!value) {
2234
PyErr_SetString(PyExc_ValueError,
2235
"field 'value' is required for AugAssign");
2236
return NULL;
2237
}
2238
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2239
if (!p)
2240
return NULL;
2241
p->kind = AugAssign_kind;
2242
p->v.AugAssign.target = target;
2243
p->v.AugAssign.op = op;
2244
p->v.AugAssign.value = value;
2245
p->lineno = lineno;
2246
p->col_offset = col_offset;
2247
p->end_lineno = end_lineno;
2248
p->end_col_offset = end_col_offset;
2249
return p;
2250
}
2251
2252
stmt_ty
2253
_PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
2254
int lineno, int col_offset, int end_lineno, int
2255
end_col_offset, PyArena *arena)
2256
{
2257
stmt_ty p;
2258
if (!target) {
2259
PyErr_SetString(PyExc_ValueError,
2260
"field 'target' is required for AnnAssign");
2261
return NULL;
2262
}
2263
if (!annotation) {
2264
PyErr_SetString(PyExc_ValueError,
2265
"field 'annotation' is required for AnnAssign");
2266
return NULL;
2267
}
2268
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2269
if (!p)
2270
return NULL;
2271
p->kind = AnnAssign_kind;
2272
p->v.AnnAssign.target = target;
2273
p->v.AnnAssign.annotation = annotation;
2274
p->v.AnnAssign.value = value;
2275
p->v.AnnAssign.simple = simple;
2276
p->lineno = lineno;
2277
p->col_offset = col_offset;
2278
p->end_lineno = end_lineno;
2279
p->end_col_offset = end_col_offset;
2280
return p;
2281
}
2282
2283
stmt_ty
2284
_PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
2285
orelse, string type_comment, int lineno, int col_offset, int
2286
end_lineno, int end_col_offset, PyArena *arena)
2287
{
2288
stmt_ty p;
2289
if (!target) {
2290
PyErr_SetString(PyExc_ValueError,
2291
"field 'target' is required for For");
2292
return NULL;
2293
}
2294
if (!iter) {
2295
PyErr_SetString(PyExc_ValueError,
2296
"field 'iter' is required for For");
2297
return NULL;
2298
}
2299
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2300
if (!p)
2301
return NULL;
2302
p->kind = For_kind;
2303
p->v.For.target = target;
2304
p->v.For.iter = iter;
2305
p->v.For.body = body;
2306
p->v.For.orelse = orelse;
2307
p->v.For.type_comment = type_comment;
2308
p->lineno = lineno;
2309
p->col_offset = col_offset;
2310
p->end_lineno = end_lineno;
2311
p->end_col_offset = end_col_offset;
2312
return p;
2313
}
2314
2315
stmt_ty
2316
_PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
2317
asdl_stmt_seq * orelse, string type_comment, int lineno, int
2318
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2319
{
2320
stmt_ty p;
2321
if (!target) {
2322
PyErr_SetString(PyExc_ValueError,
2323
"field 'target' is required for AsyncFor");
2324
return NULL;
2325
}
2326
if (!iter) {
2327
PyErr_SetString(PyExc_ValueError,
2328
"field 'iter' is required for AsyncFor");
2329
return NULL;
2330
}
2331
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2332
if (!p)
2333
return NULL;
2334
p->kind = AsyncFor_kind;
2335
p->v.AsyncFor.target = target;
2336
p->v.AsyncFor.iter = iter;
2337
p->v.AsyncFor.body = body;
2338
p->v.AsyncFor.orelse = orelse;
2339
p->v.AsyncFor.type_comment = type_comment;
2340
p->lineno = lineno;
2341
p->col_offset = col_offset;
2342
p->end_lineno = end_lineno;
2343
p->end_col_offset = end_col_offset;
2344
return p;
2345
}
2346
2347
stmt_ty
2348
_PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2349
lineno, int col_offset, int end_lineno, int end_col_offset,
2350
PyArena *arena)
2351
{
2352
stmt_ty p;
2353
if (!test) {
2354
PyErr_SetString(PyExc_ValueError,
2355
"field 'test' is required for While");
2356
return NULL;
2357
}
2358
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2359
if (!p)
2360
return NULL;
2361
p->kind = While_kind;
2362
p->v.While.test = test;
2363
p->v.While.body = body;
2364
p->v.While.orelse = orelse;
2365
p->lineno = lineno;
2366
p->col_offset = col_offset;
2367
p->end_lineno = end_lineno;
2368
p->end_col_offset = end_col_offset;
2369
return p;
2370
}
2371
2372
stmt_ty
2373
_PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2374
lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2375
*arena)
2376
{
2377
stmt_ty p;
2378
if (!test) {
2379
PyErr_SetString(PyExc_ValueError,
2380
"field 'test' is required for If");
2381
return NULL;
2382
}
2383
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2384
if (!p)
2385
return NULL;
2386
p->kind = If_kind;
2387
p->v.If.test = test;
2388
p->v.If.body = body;
2389
p->v.If.orelse = orelse;
2390
p->lineno = lineno;
2391
p->col_offset = col_offset;
2392
p->end_lineno = end_lineno;
2393
p->end_col_offset = end_col_offset;
2394
return p;
2395
}
2396
2397
stmt_ty
2398
_PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2399
type_comment, int lineno, int col_offset, int end_lineno, int
2400
end_col_offset, PyArena *arena)
2401
{
2402
stmt_ty p;
2403
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2404
if (!p)
2405
return NULL;
2406
p->kind = With_kind;
2407
p->v.With.items = items;
2408
p->v.With.body = body;
2409
p->v.With.type_comment = type_comment;
2410
p->lineno = lineno;
2411
p->col_offset = col_offset;
2412
p->end_lineno = end_lineno;
2413
p->end_col_offset = end_col_offset;
2414
return p;
2415
}
2416
2417
stmt_ty
2418
_PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2419
type_comment, int lineno, int col_offset, int end_lineno, int
2420
end_col_offset, PyArena *arena)
2421
{
2422
stmt_ty p;
2423
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2424
if (!p)
2425
return NULL;
2426
p->kind = AsyncWith_kind;
2427
p->v.AsyncWith.items = items;
2428
p->v.AsyncWith.body = body;
2429
p->v.AsyncWith.type_comment = type_comment;
2430
p->lineno = lineno;
2431
p->col_offset = col_offset;
2432
p->end_lineno = end_lineno;
2433
p->end_col_offset = end_col_offset;
2434
return p;
2435
}
2436
2437
stmt_ty
2438
_PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
2439
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2440
{
2441
stmt_ty p;
2442
if (!subject) {
2443
PyErr_SetString(PyExc_ValueError,
2444
"field 'subject' is required for Match");
2445
return NULL;
2446
}
2447
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2448
if (!p)
2449
return NULL;
2450
p->kind = Match_kind;
2451
p->v.Match.subject = subject;
2452
p->v.Match.cases = cases;
2453
p->lineno = lineno;
2454
p->col_offset = col_offset;
2455
p->end_lineno = end_lineno;
2456
p->end_col_offset = end_col_offset;
2457
return p;
2458
}
2459
2460
stmt_ty
2461
_PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
2462
end_lineno, int end_col_offset, PyArena *arena)
2463
{
2464
stmt_ty p;
2465
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2466
if (!p)
2467
return NULL;
2468
p->kind = Raise_kind;
2469
p->v.Raise.exc = exc;
2470
p->v.Raise.cause = cause;
2471
p->lineno = lineno;
2472
p->col_offset = col_offset;
2473
p->end_lineno = end_lineno;
2474
p->end_col_offset = end_col_offset;
2475
return p;
2476
}
2477
2478
stmt_ty
2479
_PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2480
asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
2481
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2482
{
2483
stmt_ty p;
2484
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2485
if (!p)
2486
return NULL;
2487
p->kind = Try_kind;
2488
p->v.Try.body = body;
2489
p->v.Try.handlers = handlers;
2490
p->v.Try.orelse = orelse;
2491
p->v.Try.finalbody = finalbody;
2492
p->lineno = lineno;
2493
p->col_offset = col_offset;
2494
p->end_lineno = end_lineno;
2495
p->end_col_offset = end_col_offset;
2496
return p;
2497
}
2498
2499
stmt_ty
2500
_PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2501
asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
2502
int col_offset, int end_lineno, int end_col_offset, PyArena
2503
*arena)
2504
{
2505
stmt_ty p;
2506
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2507
if (!p)
2508
return NULL;
2509
p->kind = TryStar_kind;
2510
p->v.TryStar.body = body;
2511
p->v.TryStar.handlers = handlers;
2512
p->v.TryStar.orelse = orelse;
2513
p->v.TryStar.finalbody = finalbody;
2514
p->lineno = lineno;
2515
p->col_offset = col_offset;
2516
p->end_lineno = end_lineno;
2517
p->end_col_offset = end_col_offset;
2518
return p;
2519
}
2520
2521
stmt_ty
2522
_PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
2523
end_lineno, int end_col_offset, PyArena *arena)
2524
{
2525
stmt_ty p;
2526
if (!test) {
2527
PyErr_SetString(PyExc_ValueError,
2528
"field 'test' is required for Assert");
2529
return NULL;
2530
}
2531
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2532
if (!p)
2533
return NULL;
2534
p->kind = Assert_kind;
2535
p->v.Assert.test = test;
2536
p->v.Assert.msg = msg;
2537
p->lineno = lineno;
2538
p->col_offset = col_offset;
2539
p->end_lineno = end_lineno;
2540
p->end_col_offset = end_col_offset;
2541
return p;
2542
}
2543
2544
stmt_ty
2545
_PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
2546
end_lineno, int end_col_offset, PyArena *arena)
2547
{
2548
stmt_ty p;
2549
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2550
if (!p)
2551
return NULL;
2552
p->kind = Import_kind;
2553
p->v.Import.names = names;
2554
p->lineno = lineno;
2555
p->col_offset = col_offset;
2556
p->end_lineno = end_lineno;
2557
p->end_col_offset = end_col_offset;
2558
return p;
2559
}
2560
2561
stmt_ty
2562
_PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
2563
lineno, int col_offset, int end_lineno, int end_col_offset,
2564
PyArena *arena)
2565
{
2566
stmt_ty p;
2567
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2568
if (!p)
2569
return NULL;
2570
p->kind = ImportFrom_kind;
2571
p->v.ImportFrom.module = module;
2572
p->v.ImportFrom.names = names;
2573
p->v.ImportFrom.level = level;
2574
p->lineno = lineno;
2575
p->col_offset = col_offset;
2576
p->end_lineno = end_lineno;
2577
p->end_col_offset = end_col_offset;
2578
return p;
2579
}
2580
2581
stmt_ty
2582
_PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
2583
end_lineno, int end_col_offset, PyArena *arena)
2584
{
2585
stmt_ty p;
2586
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2587
if (!p)
2588
return NULL;
2589
p->kind = Global_kind;
2590
p->v.Global.names = names;
2591
p->lineno = lineno;
2592
p->col_offset = col_offset;
2593
p->end_lineno = end_lineno;
2594
p->end_col_offset = end_col_offset;
2595
return p;
2596
}
2597
2598
stmt_ty
2599
_PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
2600
end_lineno, int end_col_offset, PyArena *arena)
2601
{
2602
stmt_ty p;
2603
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2604
if (!p)
2605
return NULL;
2606
p->kind = Nonlocal_kind;
2607
p->v.Nonlocal.names = names;
2608
p->lineno = lineno;
2609
p->col_offset = col_offset;
2610
p->end_lineno = end_lineno;
2611
p->end_col_offset = end_col_offset;
2612
return p;
2613
}
2614
2615
stmt_ty
2616
_PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2617
end_col_offset, PyArena *arena)
2618
{
2619
stmt_ty p;
2620
if (!value) {
2621
PyErr_SetString(PyExc_ValueError,
2622
"field 'value' is required for Expr");
2623
return NULL;
2624
}
2625
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2626
if (!p)
2627
return NULL;
2628
p->kind = Expr_kind;
2629
p->v.Expr.value = value;
2630
p->lineno = lineno;
2631
p->col_offset = col_offset;
2632
p->end_lineno = end_lineno;
2633
p->end_col_offset = end_col_offset;
2634
return p;
2635
}
2636
2637
stmt_ty
2638
_PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
2639
PyArena *arena)
2640
{
2641
stmt_ty p;
2642
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2643
if (!p)
2644
return NULL;
2645
p->kind = Pass_kind;
2646
p->lineno = lineno;
2647
p->col_offset = col_offset;
2648
p->end_lineno = end_lineno;
2649
p->end_col_offset = end_col_offset;
2650
return p;
2651
}
2652
2653
stmt_ty
2654
_PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
2655
PyArena *arena)
2656
{
2657
stmt_ty p;
2658
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2659
if (!p)
2660
return NULL;
2661
p->kind = Break_kind;
2662
p->lineno = lineno;
2663
p->col_offset = col_offset;
2664
p->end_lineno = end_lineno;
2665
p->end_col_offset = end_col_offset;
2666
return p;
2667
}
2668
2669
stmt_ty
2670
_PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2671
PyArena *arena)
2672
{
2673
stmt_ty p;
2674
p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2675
if (!p)
2676
return NULL;
2677
p->kind = Continue_kind;
2678
p->lineno = lineno;
2679
p->col_offset = col_offset;
2680
p->end_lineno = end_lineno;
2681
p->end_col_offset = end_col_offset;
2682
return p;
2683
}
2684
2685
expr_ty
2686
_PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
2687
int end_lineno, int end_col_offset, PyArena *arena)
2688
{
2689
expr_ty p;
2690
if (!op) {
2691
PyErr_SetString(PyExc_ValueError,
2692
"field 'op' is required for BoolOp");
2693
return NULL;
2694
}
2695
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2696
if (!p)
2697
return NULL;
2698
p->kind = BoolOp_kind;
2699
p->v.BoolOp.op = op;
2700
p->v.BoolOp.values = values;
2701
p->lineno = lineno;
2702
p->col_offset = col_offset;
2703
p->end_lineno = end_lineno;
2704
p->end_col_offset = end_col_offset;
2705
return p;
2706
}
2707
2708
expr_ty
2709
_PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2710
end_lineno, int end_col_offset, PyArena *arena)
2711
{
2712
expr_ty p;
2713
if (!target) {
2714
PyErr_SetString(PyExc_ValueError,
2715
"field 'target' is required for NamedExpr");
2716
return NULL;
2717
}
2718
if (!value) {
2719
PyErr_SetString(PyExc_ValueError,
2720
"field 'value' is required for NamedExpr");
2721
return NULL;
2722
}
2723
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2724
if (!p)
2725
return NULL;
2726
p->kind = NamedExpr_kind;
2727
p->v.NamedExpr.target = target;
2728
p->v.NamedExpr.value = value;
2729
p->lineno = lineno;
2730
p->col_offset = col_offset;
2731
p->end_lineno = end_lineno;
2732
p->end_col_offset = end_col_offset;
2733
return p;
2734
}
2735
2736
expr_ty
2737
_PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
2738
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2739
{
2740
expr_ty p;
2741
if (!left) {
2742
PyErr_SetString(PyExc_ValueError,
2743
"field 'left' is required for BinOp");
2744
return NULL;
2745
}
2746
if (!op) {
2747
PyErr_SetString(PyExc_ValueError,
2748
"field 'op' is required for BinOp");
2749
return NULL;
2750
}
2751
if (!right) {
2752
PyErr_SetString(PyExc_ValueError,
2753
"field 'right' is required for BinOp");
2754
return NULL;
2755
}
2756
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2757
if (!p)
2758
return NULL;
2759
p->kind = BinOp_kind;
2760
p->v.BinOp.left = left;
2761
p->v.BinOp.op = op;
2762
p->v.BinOp.right = right;
2763
p->lineno = lineno;
2764
p->col_offset = col_offset;
2765
p->end_lineno = end_lineno;
2766
p->end_col_offset = end_col_offset;
2767
return p;
2768
}
2769
2770
expr_ty
2771
_PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2772
end_lineno, int end_col_offset, PyArena *arena)
2773
{
2774
expr_ty p;
2775
if (!op) {
2776
PyErr_SetString(PyExc_ValueError,
2777
"field 'op' is required for UnaryOp");
2778
return NULL;
2779
}
2780
if (!operand) {
2781
PyErr_SetString(PyExc_ValueError,
2782
"field 'operand' is required for UnaryOp");
2783
return NULL;
2784
}
2785
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2786
if (!p)
2787
return NULL;
2788
p->kind = UnaryOp_kind;
2789
p->v.UnaryOp.op = op;
2790
p->v.UnaryOp.operand = operand;
2791
p->lineno = lineno;
2792
p->col_offset = col_offset;
2793
p->end_lineno = end_lineno;
2794
p->end_col_offset = end_col_offset;
2795
return p;
2796
}
2797
2798
expr_ty
2799
_PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2800
end_lineno, int end_col_offset, PyArena *arena)
2801
{
2802
expr_ty p;
2803
if (!args) {
2804
PyErr_SetString(PyExc_ValueError,
2805
"field 'args' is required for Lambda");
2806
return NULL;
2807
}
2808
if (!body) {
2809
PyErr_SetString(PyExc_ValueError,
2810
"field 'body' is required for Lambda");
2811
return NULL;
2812
}
2813
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2814
if (!p)
2815
return NULL;
2816
p->kind = Lambda_kind;
2817
p->v.Lambda.args = args;
2818
p->v.Lambda.body = body;
2819
p->lineno = lineno;
2820
p->col_offset = col_offset;
2821
p->end_lineno = end_lineno;
2822
p->end_col_offset = end_col_offset;
2823
return p;
2824
}
2825
2826
expr_ty
2827
_PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
2828
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2829
{
2830
expr_ty p;
2831
if (!test) {
2832
PyErr_SetString(PyExc_ValueError,
2833
"field 'test' is required for IfExp");
2834
return NULL;
2835
}
2836
if (!body) {
2837
PyErr_SetString(PyExc_ValueError,
2838
"field 'body' is required for IfExp");
2839
return NULL;
2840
}
2841
if (!orelse) {
2842
PyErr_SetString(PyExc_ValueError,
2843
"field 'orelse' is required for IfExp");
2844
return NULL;
2845
}
2846
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2847
if (!p)
2848
return NULL;
2849
p->kind = IfExp_kind;
2850
p->v.IfExp.test = test;
2851
p->v.IfExp.body = body;
2852
p->v.IfExp.orelse = orelse;
2853
p->lineno = lineno;
2854
p->col_offset = col_offset;
2855
p->end_lineno = end_lineno;
2856
p->end_col_offset = end_col_offset;
2857
return p;
2858
}
2859
2860
expr_ty
2861
_PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
2862
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2863
{
2864
expr_ty p;
2865
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2866
if (!p)
2867
return NULL;
2868
p->kind = Dict_kind;
2869
p->v.Dict.keys = keys;
2870
p->v.Dict.values = values;
2871
p->lineno = lineno;
2872
p->col_offset = col_offset;
2873
p->end_lineno = end_lineno;
2874
p->end_col_offset = end_col_offset;
2875
return p;
2876
}
2877
2878
expr_ty
2879
_PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
2880
int end_col_offset, PyArena *arena)
2881
{
2882
expr_ty p;
2883
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2884
if (!p)
2885
return NULL;
2886
p->kind = Set_kind;
2887
p->v.Set.elts = elts;
2888
p->lineno = lineno;
2889
p->col_offset = col_offset;
2890
p->end_lineno = end_lineno;
2891
p->end_col_offset = end_col_offset;
2892
return p;
2893
}
2894
2895
expr_ty
2896
_PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2897
int col_offset, int end_lineno, int end_col_offset, PyArena
2898
*arena)
2899
{
2900
expr_ty p;
2901
if (!elt) {
2902
PyErr_SetString(PyExc_ValueError,
2903
"field 'elt' is required for ListComp");
2904
return NULL;
2905
}
2906
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2907
if (!p)
2908
return NULL;
2909
p->kind = ListComp_kind;
2910
p->v.ListComp.elt = elt;
2911
p->v.ListComp.generators = generators;
2912
p->lineno = lineno;
2913
p->col_offset = col_offset;
2914
p->end_lineno = end_lineno;
2915
p->end_col_offset = end_col_offset;
2916
return p;
2917
}
2918
2919
expr_ty
2920
_PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2921
int col_offset, int end_lineno, int end_col_offset, PyArena
2922
*arena)
2923
{
2924
expr_ty p;
2925
if (!elt) {
2926
PyErr_SetString(PyExc_ValueError,
2927
"field 'elt' is required for SetComp");
2928
return NULL;
2929
}
2930
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2931
if (!p)
2932
return NULL;
2933
p->kind = SetComp_kind;
2934
p->v.SetComp.elt = elt;
2935
p->v.SetComp.generators = generators;
2936
p->lineno = lineno;
2937
p->col_offset = col_offset;
2938
p->end_lineno = end_lineno;
2939
p->end_col_offset = end_col_offset;
2940
return p;
2941
}
2942
2943
expr_ty
2944
_PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
2945
generators, int lineno, int col_offset, int end_lineno, int
2946
end_col_offset, PyArena *arena)
2947
{
2948
expr_ty p;
2949
if (!key) {
2950
PyErr_SetString(PyExc_ValueError,
2951
"field 'key' is required for DictComp");
2952
return NULL;
2953
}
2954
if (!value) {
2955
PyErr_SetString(PyExc_ValueError,
2956
"field 'value' is required for DictComp");
2957
return NULL;
2958
}
2959
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2960
if (!p)
2961
return NULL;
2962
p->kind = DictComp_kind;
2963
p->v.DictComp.key = key;
2964
p->v.DictComp.value = value;
2965
p->v.DictComp.generators = generators;
2966
p->lineno = lineno;
2967
p->col_offset = col_offset;
2968
p->end_lineno = end_lineno;
2969
p->end_col_offset = end_col_offset;
2970
return p;
2971
}
2972
2973
expr_ty
2974
_PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
2975
lineno, int col_offset, int end_lineno, int end_col_offset,
2976
PyArena *arena)
2977
{
2978
expr_ty p;
2979
if (!elt) {
2980
PyErr_SetString(PyExc_ValueError,
2981
"field 'elt' is required for GeneratorExp");
2982
return NULL;
2983
}
2984
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2985
if (!p)
2986
return NULL;
2987
p->kind = GeneratorExp_kind;
2988
p->v.GeneratorExp.elt = elt;
2989
p->v.GeneratorExp.generators = generators;
2990
p->lineno = lineno;
2991
p->col_offset = col_offset;
2992
p->end_lineno = end_lineno;
2993
p->end_col_offset = end_col_offset;
2994
return p;
2995
}
2996
2997
expr_ty
2998
_PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2999
end_col_offset, PyArena *arena)
3000
{
3001
expr_ty p;
3002
if (!value) {
3003
PyErr_SetString(PyExc_ValueError,
3004
"field 'value' is required for Await");
3005
return NULL;
3006
}
3007
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3008
if (!p)
3009
return NULL;
3010
p->kind = Await_kind;
3011
p->v.Await.value = value;
3012
p->lineno = lineno;
3013
p->col_offset = col_offset;
3014
p->end_lineno = end_lineno;
3015
p->end_col_offset = end_col_offset;
3016
return p;
3017
}
3018
3019
expr_ty
3020
_PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3021
end_col_offset, PyArena *arena)
3022
{
3023
expr_ty p;
3024
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3025
if (!p)
3026
return NULL;
3027
p->kind = Yield_kind;
3028
p->v.Yield.value = value;
3029
p->lineno = lineno;
3030
p->col_offset = col_offset;
3031
p->end_lineno = end_lineno;
3032
p->end_col_offset = end_col_offset;
3033
return p;
3034
}
3035
3036
expr_ty
3037
_PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3038
end_col_offset, PyArena *arena)
3039
{
3040
expr_ty p;
3041
if (!value) {
3042
PyErr_SetString(PyExc_ValueError,
3043
"field 'value' is required for YieldFrom");
3044
return NULL;
3045
}
3046
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3047
if (!p)
3048
return NULL;
3049
p->kind = YieldFrom_kind;
3050
p->v.YieldFrom.value = value;
3051
p->lineno = lineno;
3052
p->col_offset = col_offset;
3053
p->end_lineno = end_lineno;
3054
p->end_col_offset = end_col_offset;
3055
return p;
3056
}
3057
3058
expr_ty
3059
_PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
3060
int lineno, int col_offset, int end_lineno, int end_col_offset,
3061
PyArena *arena)
3062
{
3063
expr_ty p;
3064
if (!left) {
3065
PyErr_SetString(PyExc_ValueError,
3066
"field 'left' is required for Compare");
3067
return NULL;
3068
}
3069
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3070
if (!p)
3071
return NULL;
3072
p->kind = Compare_kind;
3073
p->v.Compare.left = left;
3074
p->v.Compare.ops = ops;
3075
p->v.Compare.comparators = comparators;
3076
p->lineno = lineno;
3077
p->col_offset = col_offset;
3078
p->end_lineno = end_lineno;
3079
p->end_col_offset = end_col_offset;
3080
return p;
3081
}
3082
3083
expr_ty
3084
_PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
3085
int lineno, int col_offset, int end_lineno, int end_col_offset,
3086
PyArena *arena)
3087
{
3088
expr_ty p;
3089
if (!func) {
3090
PyErr_SetString(PyExc_ValueError,
3091
"field 'func' is required for Call");
3092
return NULL;
3093
}
3094
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3095
if (!p)
3096
return NULL;
3097
p->kind = Call_kind;
3098
p->v.Call.func = func;
3099
p->v.Call.args = args;
3100
p->v.Call.keywords = keywords;
3101
p->lineno = lineno;
3102
p->col_offset = col_offset;
3103
p->end_lineno = end_lineno;
3104
p->end_col_offset = end_col_offset;
3105
return p;
3106
}
3107
3108
expr_ty
3109
_PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
3110
lineno, int col_offset, int end_lineno, int
3111
end_col_offset, PyArena *arena)
3112
{
3113
expr_ty p;
3114
if (!value) {
3115
PyErr_SetString(PyExc_ValueError,
3116
"field 'value' is required for FormattedValue");
3117
return NULL;
3118
}
3119
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3120
if (!p)
3121
return NULL;
3122
p->kind = FormattedValue_kind;
3123
p->v.FormattedValue.value = value;
3124
p->v.FormattedValue.conversion = conversion;
3125
p->v.FormattedValue.format_spec = format_spec;
3126
p->lineno = lineno;
3127
p->col_offset = col_offset;
3128
p->end_lineno = end_lineno;
3129
p->end_col_offset = end_col_offset;
3130
return p;
3131
}
3132
3133
expr_ty
3134
_PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
3135
end_lineno, int end_col_offset, PyArena *arena)
3136
{
3137
expr_ty p;
3138
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3139
if (!p)
3140
return NULL;
3141
p->kind = JoinedStr_kind;
3142
p->v.JoinedStr.values = values;
3143
p->lineno = lineno;
3144
p->col_offset = col_offset;
3145
p->end_lineno = end_lineno;
3146
p->end_col_offset = end_col_offset;
3147
return p;
3148
}
3149
3150
expr_ty
3151
_PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
3152
end_lineno, int end_col_offset, PyArena *arena)
3153
{
3154
expr_ty p;
3155
if (!value) {
3156
PyErr_SetString(PyExc_ValueError,
3157
"field 'value' is required for Constant");
3158
return NULL;
3159
}
3160
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3161
if (!p)
3162
return NULL;
3163
p->kind = Constant_kind;
3164
p->v.Constant.value = value;
3165
p->v.Constant.kind = kind;
3166
p->lineno = lineno;
3167
p->col_offset = col_offset;
3168
p->end_lineno = end_lineno;
3169
p->end_col_offset = end_col_offset;
3170
return p;
3171
}
3172
3173
expr_ty
3174
_PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
3175
lineno, int col_offset, int end_lineno, int end_col_offset,
3176
PyArena *arena)
3177
{
3178
expr_ty p;
3179
if (!value) {
3180
PyErr_SetString(PyExc_ValueError,
3181
"field 'value' is required for Attribute");
3182
return NULL;
3183
}
3184
if (!attr) {
3185
PyErr_SetString(PyExc_ValueError,
3186
"field 'attr' is required for Attribute");
3187
return NULL;
3188
}
3189
if (!ctx) {
3190
PyErr_SetString(PyExc_ValueError,
3191
"field 'ctx' is required for Attribute");
3192
return NULL;
3193
}
3194
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3195
if (!p)
3196
return NULL;
3197
p->kind = Attribute_kind;
3198
p->v.Attribute.value = value;
3199
p->v.Attribute.attr = attr;
3200
p->v.Attribute.ctx = ctx;
3201
p->lineno = lineno;
3202
p->col_offset = col_offset;
3203
p->end_lineno = end_lineno;
3204
p->end_col_offset = end_col_offset;
3205
return p;
3206
}
3207
3208
expr_ty
3209
_PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
3210
int col_offset, int end_lineno, int end_col_offset, PyArena
3211
*arena)
3212
{
3213
expr_ty p;
3214
if (!value) {
3215
PyErr_SetString(PyExc_ValueError,
3216
"field 'value' is required for Subscript");
3217
return NULL;
3218
}
3219
if (!slice) {
3220
PyErr_SetString(PyExc_ValueError,
3221
"field 'slice' is required for Subscript");
3222
return NULL;
3223
}
3224
if (!ctx) {
3225
PyErr_SetString(PyExc_ValueError,
3226
"field 'ctx' is required for Subscript");
3227
return NULL;
3228
}
3229
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3230
if (!p)
3231
return NULL;
3232
p->kind = Subscript_kind;
3233
p->v.Subscript.value = value;
3234
p->v.Subscript.slice = slice;
3235
p->v.Subscript.ctx = ctx;
3236
p->lineno = lineno;
3237
p->col_offset = col_offset;
3238
p->end_lineno = end_lineno;
3239
p->end_col_offset = end_col_offset;
3240
return p;
3241
}
3242
3243
expr_ty
3244
_PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
3245
int end_lineno, int end_col_offset, PyArena *arena)
3246
{
3247
expr_ty p;
3248
if (!value) {
3249
PyErr_SetString(PyExc_ValueError,
3250
"field 'value' is required for Starred");
3251
return NULL;
3252
}
3253
if (!ctx) {
3254
PyErr_SetString(PyExc_ValueError,
3255
"field 'ctx' is required for Starred");
3256
return NULL;
3257
}
3258
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3259
if (!p)
3260
return NULL;
3261
p->kind = Starred_kind;
3262
p->v.Starred.value = value;
3263
p->v.Starred.ctx = ctx;
3264
p->lineno = lineno;
3265
p->col_offset = col_offset;
3266
p->end_lineno = end_lineno;
3267
p->end_col_offset = end_col_offset;
3268
return p;
3269
}
3270
3271
expr_ty
3272
_PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3273
end_lineno, int end_col_offset, PyArena *arena)
3274
{
3275
expr_ty p;
3276
if (!id) {
3277
PyErr_SetString(PyExc_ValueError,
3278
"field 'id' is required for Name");
3279
return NULL;
3280
}
3281
if (!ctx) {
3282
PyErr_SetString(PyExc_ValueError,
3283
"field 'ctx' is required for Name");
3284
return NULL;
3285
}
3286
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3287
if (!p)
3288
return NULL;
3289
p->kind = Name_kind;
3290
p->v.Name.id = id;
3291
p->v.Name.ctx = ctx;
3292
p->lineno = lineno;
3293
p->col_offset = col_offset;
3294
p->end_lineno = end_lineno;
3295
p->end_col_offset = end_col_offset;
3296
return p;
3297
}
3298
3299
expr_ty
3300
_PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3301
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3302
{
3303
expr_ty p;
3304
if (!ctx) {
3305
PyErr_SetString(PyExc_ValueError,
3306
"field 'ctx' is required for List");
3307
return NULL;
3308
}
3309
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3310
if (!p)
3311
return NULL;
3312
p->kind = List_kind;
3313
p->v.List.elts = elts;
3314
p->v.List.ctx = ctx;
3315
p->lineno = lineno;
3316
p->col_offset = col_offset;
3317
p->end_lineno = end_lineno;
3318
p->end_col_offset = end_col_offset;
3319
return p;
3320
}
3321
3322
expr_ty
3323
_PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3324
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3325
{
3326
expr_ty p;
3327
if (!ctx) {
3328
PyErr_SetString(PyExc_ValueError,
3329
"field 'ctx' is required for Tuple");
3330
return NULL;
3331
}
3332
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3333
if (!p)
3334
return NULL;
3335
p->kind = Tuple_kind;
3336
p->v.Tuple.elts = elts;
3337
p->v.Tuple.ctx = ctx;
3338
p->lineno = lineno;
3339
p->col_offset = col_offset;
3340
p->end_lineno = end_lineno;
3341
p->end_col_offset = end_col_offset;
3342
return p;
3343
}
3344
3345
expr_ty
3346
_PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
3347
col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3348
{
3349
expr_ty p;
3350
p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3351
if (!p)
3352
return NULL;
3353
p->kind = Slice_kind;
3354
p->v.Slice.lower = lower;
3355
p->v.Slice.upper = upper;
3356
p->v.Slice.step = step;
3357
p->lineno = lineno;
3358
p->col_offset = col_offset;
3359
p->end_lineno = end_lineno;
3360
p->end_col_offset = end_col_offset;
3361
return p;
3362
}
3363
3364
comprehension_ty
3365
_PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
3366
is_async, PyArena *arena)
3367
{
3368
comprehension_ty p;
3369
if (!target) {
3370
PyErr_SetString(PyExc_ValueError,
3371
"field 'target' is required for comprehension");
3372
return NULL;
3373
}
3374
if (!iter) {
3375
PyErr_SetString(PyExc_ValueError,
3376
"field 'iter' is required for comprehension");
3377
return NULL;
3378
}
3379
p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
3380
if (!p)
3381
return NULL;
3382
p->target = target;
3383
p->iter = iter;
3384
p->ifs = ifs;
3385
p->is_async = is_async;
3386
return p;
3387
}
3388
3389
excepthandler_ty
3390
_PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
3391
lineno, int col_offset, int end_lineno, int
3392
end_col_offset, PyArena *arena)
3393
{
3394
excepthandler_ty p;
3395
p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
3396
if (!p)
3397
return NULL;
3398
p->kind = ExceptHandler_kind;
3399
p->v.ExceptHandler.type = type;
3400
p->v.ExceptHandler.name = name;
3401
p->v.ExceptHandler.body = body;
3402
p->lineno = lineno;
3403
p->col_offset = col_offset;
3404
p->end_lineno = end_lineno;
3405
p->end_col_offset = end_col_offset;
3406
return p;
3407
}
3408
3409
arguments_ty
3410
_PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
3411
vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
3412
kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
3413
*arena)
3414
{
3415
arguments_ty p;
3416
p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
3417
if (!p)
3418
return NULL;
3419
p->posonlyargs = posonlyargs;
3420
p->args = args;
3421
p->vararg = vararg;
3422
p->kwonlyargs = kwonlyargs;
3423
p->kw_defaults = kw_defaults;
3424
p->kwarg = kwarg;
3425
p->defaults = defaults;
3426
return p;
3427
}
3428
3429
arg_ty
3430
_PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
3431
int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3432
{
3433
arg_ty p;
3434
if (!arg) {
3435
PyErr_SetString(PyExc_ValueError,
3436
"field 'arg' is required for arg");
3437
return NULL;
3438
}
3439
p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
3440
if (!p)
3441
return NULL;
3442
p->arg = arg;
3443
p->annotation = annotation;
3444
p->type_comment = type_comment;
3445
p->lineno = lineno;
3446
p->col_offset = col_offset;
3447
p->end_lineno = end_lineno;
3448
p->end_col_offset = end_col_offset;
3449
return p;
3450
}
3451
3452
keyword_ty
3453
_PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3454
end_lineno, int end_col_offset, PyArena *arena)
3455
{
3456
keyword_ty p;
3457
if (!value) {
3458
PyErr_SetString(PyExc_ValueError,
3459
"field 'value' is required for keyword");
3460
return NULL;
3461
}
3462
p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
3463
if (!p)
3464
return NULL;
3465
p->arg = arg;
3466
p->value = value;
3467
p->lineno = lineno;
3468
p->col_offset = col_offset;
3469
p->end_lineno = end_lineno;
3470
p->end_col_offset = end_col_offset;
3471
return p;
3472
}
3473
3474
alias_ty
3475
_PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
3476
int end_lineno, int end_col_offset, PyArena *arena)
3477
{
3478
alias_ty p;
3479
if (!name) {
3480
PyErr_SetString(PyExc_ValueError,
3481
"field 'name' is required for alias");
3482
return NULL;
3483
}
3484
p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
3485
if (!p)
3486
return NULL;
3487
p->name = name;
3488
p->asname = asname;
3489
p->lineno = lineno;
3490
p->col_offset = col_offset;
3491
p->end_lineno = end_lineno;
3492
p->end_col_offset = end_col_offset;
3493
return p;
3494
}
3495
3496
withitem_ty
3497
_PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3498
{
3499
withitem_ty p;
3500
if (!context_expr) {
3501
PyErr_SetString(PyExc_ValueError,
3502
"field 'context_expr' is required for withitem");
3503
return NULL;
3504
}
3505
p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
3506
if (!p)
3507
return NULL;
3508
p->context_expr = context_expr;
3509
p->optional_vars = optional_vars;
3510
return p;
3511
}
3512
3513
match_case_ty
3514
_PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
3515
PyArena *arena)
3516
{
3517
match_case_ty p;
3518
if (!pattern) {
3519
PyErr_SetString(PyExc_ValueError,
3520
"field 'pattern' is required for match_case");
3521
return NULL;
3522
}
3523
p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
3524
if (!p)
3525
return NULL;
3526
p->pattern = pattern;
3527
p->guard = guard;
3528
p->body = body;
3529
return p;
3530
}
3531
3532
pattern_ty
3533
_PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
3534
int end_col_offset, PyArena *arena)
3535
{
3536
pattern_ty p;
3537
if (!value) {
3538
PyErr_SetString(PyExc_ValueError,
3539
"field 'value' is required for MatchValue");
3540
return NULL;
3541
}
3542
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3543
if (!p)
3544
return NULL;
3545
p->kind = MatchValue_kind;
3546
p->v.MatchValue.value = value;
3547
p->lineno = lineno;
3548
p->col_offset = col_offset;
3549
p->end_lineno = end_lineno;
3550
p->end_col_offset = end_col_offset;
3551
return p;
3552
}
3553
3554
pattern_ty
3555
_PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
3556
end_lineno, int end_col_offset, PyArena *arena)
3557
{
3558
pattern_ty p;
3559
if (!value) {
3560
PyErr_SetString(PyExc_ValueError,
3561
"field 'value' is required for MatchSingleton");
3562
return NULL;
3563
}
3564
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3565
if (!p)
3566
return NULL;
3567
p->kind = MatchSingleton_kind;
3568
p->v.MatchSingleton.value = value;
3569
p->lineno = lineno;
3570
p->col_offset = col_offset;
3571
p->end_lineno = end_lineno;
3572
p->end_col_offset = end_col_offset;
3573
return p;
3574
}
3575
3576
pattern_ty
3577
_PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
3578
int end_lineno, int end_col_offset, PyArena *arena)
3579
{
3580
pattern_ty p;
3581
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3582
if (!p)
3583
return NULL;
3584
p->kind = MatchSequence_kind;
3585
p->v.MatchSequence.patterns = patterns;
3586
p->lineno = lineno;
3587
p->col_offset = col_offset;
3588
p->end_lineno = end_lineno;
3589
p->end_col_offset = end_col_offset;
3590
return p;
3591
}
3592
3593
pattern_ty
3594
_PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
3595
identifier rest, int lineno, int col_offset, int
3596
end_lineno, int end_col_offset, PyArena *arena)
3597
{
3598
pattern_ty p;
3599
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3600
if (!p)
3601
return NULL;
3602
p->kind = MatchMapping_kind;
3603
p->v.MatchMapping.keys = keys;
3604
p->v.MatchMapping.patterns = patterns;
3605
p->v.MatchMapping.rest = rest;
3606
p->lineno = lineno;
3607
p->col_offset = col_offset;
3608
p->end_lineno = end_lineno;
3609
p->end_col_offset = end_col_offset;
3610
return p;
3611
}
3612
3613
pattern_ty
3614
_PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
3615
* kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
3616
col_offset, int end_lineno, int end_col_offset, PyArena
3617
*arena)
3618
{
3619
pattern_ty p;
3620
if (!cls) {
3621
PyErr_SetString(PyExc_ValueError,
3622
"field 'cls' is required for MatchClass");
3623
return NULL;
3624
}
3625
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3626
if (!p)
3627
return NULL;
3628
p->kind = MatchClass_kind;
3629
p->v.MatchClass.cls = cls;
3630
p->v.MatchClass.patterns = patterns;
3631
p->v.MatchClass.kwd_attrs = kwd_attrs;
3632
p->v.MatchClass.kwd_patterns = kwd_patterns;
3633
p->lineno = lineno;
3634
p->col_offset = col_offset;
3635
p->end_lineno = end_lineno;
3636
p->end_col_offset = end_col_offset;
3637
return p;
3638
}
3639
3640
pattern_ty
3641
_PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
3642
int end_col_offset, PyArena *arena)
3643
{
3644
pattern_ty p;
3645
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3646
if (!p)
3647
return NULL;
3648
p->kind = MatchStar_kind;
3649
p->v.MatchStar.name = name;
3650
p->lineno = lineno;
3651
p->col_offset = col_offset;
3652
p->end_lineno = end_lineno;
3653
p->end_col_offset = end_col_offset;
3654
return p;
3655
}
3656
3657
pattern_ty
3658
_PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
3659
int end_lineno, int end_col_offset, PyArena *arena)
3660
{
3661
pattern_ty p;
3662
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3663
if (!p)
3664
return NULL;
3665
p->kind = MatchAs_kind;
3666
p->v.MatchAs.pattern = pattern;
3667
p->v.MatchAs.name = name;
3668
p->lineno = lineno;
3669
p->col_offset = col_offset;
3670
p->end_lineno = end_lineno;
3671
p->end_col_offset = end_col_offset;
3672
return p;
3673
}
3674
3675
pattern_ty
3676
_PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
3677
end_lineno, int end_col_offset, PyArena *arena)
3678
{
3679
pattern_ty p;
3680
p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3681
if (!p)
3682
return NULL;
3683
p->kind = MatchOr_kind;
3684
p->v.MatchOr.patterns = patterns;
3685
p->lineno = lineno;
3686
p->col_offset = col_offset;
3687
p->end_lineno = end_lineno;
3688
p->end_col_offset = end_col_offset;
3689
return p;
3690
}
3691
3692
type_ignore_ty
3693
_PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
3694
{
3695
type_ignore_ty p;
3696
if (!tag) {
3697
PyErr_SetString(PyExc_ValueError,
3698
"field 'tag' is required for TypeIgnore");
3699
return NULL;
3700
}
3701
p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
3702
if (!p)
3703
return NULL;
3704
p->kind = TypeIgnore_kind;
3705
p->v.TypeIgnore.lineno = lineno;
3706
p->v.TypeIgnore.tag = tag;
3707
return p;
3708
}
3709
3710
type_param_ty
3711
_PyAST_TypeVar(identifier name, expr_ty bound, int lineno, int col_offset, int
3712
end_lineno, int end_col_offset, PyArena *arena)
3713
{
3714
type_param_ty p;
3715
if (!name) {
3716
PyErr_SetString(PyExc_ValueError,
3717
"field 'name' is required for TypeVar");
3718
return NULL;
3719
}
3720
p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
3721
if (!p)
3722
return NULL;
3723
p->kind = TypeVar_kind;
3724
p->v.TypeVar.name = name;
3725
p->v.TypeVar.bound = bound;
3726
p->lineno = lineno;
3727
p->col_offset = col_offset;
3728
p->end_lineno = end_lineno;
3729
p->end_col_offset = end_col_offset;
3730
return p;
3731
}
3732
3733
type_param_ty
3734
_PyAST_ParamSpec(identifier name, int lineno, int col_offset, int end_lineno,
3735
int end_col_offset, PyArena *arena)
3736
{
3737
type_param_ty p;
3738
if (!name) {
3739
PyErr_SetString(PyExc_ValueError,
3740
"field 'name' is required for ParamSpec");
3741
return NULL;
3742
}
3743
p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
3744
if (!p)
3745
return NULL;
3746
p->kind = ParamSpec_kind;
3747
p->v.ParamSpec.name = name;
3748
p->lineno = lineno;
3749
p->col_offset = col_offset;
3750
p->end_lineno = end_lineno;
3751
p->end_col_offset = end_col_offset;
3752
return p;
3753
}
3754
3755
type_param_ty
3756
_PyAST_TypeVarTuple(identifier name, int lineno, int col_offset, int
3757
end_lineno, int end_col_offset, PyArena *arena)
3758
{
3759
type_param_ty p;
3760
if (!name) {
3761
PyErr_SetString(PyExc_ValueError,
3762
"field 'name' is required for TypeVarTuple");
3763
return NULL;
3764
}
3765
p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
3766
if (!p)
3767
return NULL;
3768
p->kind = TypeVarTuple_kind;
3769
p->v.TypeVarTuple.name = name;
3770
p->lineno = lineno;
3771
p->col_offset = col_offset;
3772
p->end_lineno = end_lineno;
3773
p->end_col_offset = end_col_offset;
3774
return p;
3775
}
3776
3777
3778
PyObject*
3779
ast2obj_mod(struct ast_state *state, void* _o)
3780
{
3781
mod_ty o = (mod_ty)_o;
3782
PyObject *result = NULL, *value = NULL;
3783
PyTypeObject *tp;
3784
if (!o) {
3785
Py_RETURN_NONE;
3786
}
3787
if (++state->recursion_depth > state->recursion_limit) {
3788
PyErr_SetString(PyExc_RecursionError,
3789
"maximum recursion depth exceeded during ast construction");
3790
return 0;
3791
}
3792
switch (o->kind) {
3793
case Module_kind:
3794
tp = (PyTypeObject *)state->Module_type;
3795
result = PyType_GenericNew(tp, NULL, NULL);
3796
if (!result) goto failed;
3797
value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
3798
if (!value) goto failed;
3799
if (PyObject_SetAttr(result, state->body, value) == -1)
3800
goto failed;
3801
Py_DECREF(value);
3802
value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
3803
ast2obj_type_ignore);
3804
if (!value) goto failed;
3805
if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
3806
goto failed;
3807
Py_DECREF(value);
3808
break;
3809
case Interactive_kind:
3810
tp = (PyTypeObject *)state->Interactive_type;
3811
result = PyType_GenericNew(tp, NULL, NULL);
3812
if (!result) goto failed;
3813
value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
3814
ast2obj_stmt);
3815
if (!value) goto failed;
3816
if (PyObject_SetAttr(result, state->body, value) == -1)
3817
goto failed;
3818
Py_DECREF(value);
3819
break;
3820
case Expression_kind:
3821
tp = (PyTypeObject *)state->Expression_type;
3822
result = PyType_GenericNew(tp, NULL, NULL);
3823
if (!result) goto failed;
3824
value = ast2obj_expr(state, o->v.Expression.body);
3825
if (!value) goto failed;
3826
if (PyObject_SetAttr(result, state->body, value) == -1)
3827
goto failed;
3828
Py_DECREF(value);
3829
break;
3830
case FunctionType_kind:
3831
tp = (PyTypeObject *)state->FunctionType_type;
3832
result = PyType_GenericNew(tp, NULL, NULL);
3833
if (!result) goto failed;
3834
value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
3835
ast2obj_expr);
3836
if (!value) goto failed;
3837
if (PyObject_SetAttr(result, state->argtypes, value) == -1)
3838
goto failed;
3839
Py_DECREF(value);
3840
value = ast2obj_expr(state, o->v.FunctionType.returns);
3841
if (!value) goto failed;
3842
if (PyObject_SetAttr(result, state->returns, value) == -1)
3843
goto failed;
3844
Py_DECREF(value);
3845
break;
3846
}
3847
state->recursion_depth--;
3848
return result;
3849
failed:
3850
Py_XDECREF(value);
3851
Py_XDECREF(result);
3852
return NULL;
3853
}
3854
3855
PyObject*
3856
ast2obj_stmt(struct ast_state *state, void* _o)
3857
{
3858
stmt_ty o = (stmt_ty)_o;
3859
PyObject *result = NULL, *value = NULL;
3860
PyTypeObject *tp;
3861
if (!o) {
3862
Py_RETURN_NONE;
3863
}
3864
if (++state->recursion_depth > state->recursion_limit) {
3865
PyErr_SetString(PyExc_RecursionError,
3866
"maximum recursion depth exceeded during ast construction");
3867
return 0;
3868
}
3869
switch (o->kind) {
3870
case FunctionDef_kind:
3871
tp = (PyTypeObject *)state->FunctionDef_type;
3872
result = PyType_GenericNew(tp, NULL, NULL);
3873
if (!result) goto failed;
3874
value = ast2obj_identifier(state, o->v.FunctionDef.name);
3875
if (!value) goto failed;
3876
if (PyObject_SetAttr(result, state->name, value) == -1)
3877
goto failed;
3878
Py_DECREF(value);
3879
value = ast2obj_arguments(state, o->v.FunctionDef.args);
3880
if (!value) goto failed;
3881
if (PyObject_SetAttr(result, state->args, value) == -1)
3882
goto failed;
3883
Py_DECREF(value);
3884
value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
3885
ast2obj_stmt);
3886
if (!value) goto failed;
3887
if (PyObject_SetAttr(result, state->body, value) == -1)
3888
goto failed;
3889
Py_DECREF(value);
3890
value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
3891
ast2obj_expr);
3892
if (!value) goto failed;
3893
if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3894
goto failed;
3895
Py_DECREF(value);
3896
value = ast2obj_expr(state, o->v.FunctionDef.returns);
3897
if (!value) goto failed;
3898
if (PyObject_SetAttr(result, state->returns, value) == -1)
3899
goto failed;
3900
Py_DECREF(value);
3901
value = ast2obj_string(state, o->v.FunctionDef.type_comment);
3902
if (!value) goto failed;
3903
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3904
goto failed;
3905
Py_DECREF(value);
3906
value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.type_params,
3907
ast2obj_type_param);
3908
if (!value) goto failed;
3909
if (PyObject_SetAttr(result, state->type_params, value) == -1)
3910
goto failed;
3911
Py_DECREF(value);
3912
break;
3913
case AsyncFunctionDef_kind:
3914
tp = (PyTypeObject *)state->AsyncFunctionDef_type;
3915
result = PyType_GenericNew(tp, NULL, NULL);
3916
if (!result) goto failed;
3917
value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
3918
if (!value) goto failed;
3919
if (PyObject_SetAttr(result, state->name, value) == -1)
3920
goto failed;
3921
Py_DECREF(value);
3922
value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
3923
if (!value) goto failed;
3924
if (PyObject_SetAttr(result, state->args, value) == -1)
3925
goto failed;
3926
Py_DECREF(value);
3927
value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
3928
ast2obj_stmt);
3929
if (!value) goto failed;
3930
if (PyObject_SetAttr(result, state->body, value) == -1)
3931
goto failed;
3932
Py_DECREF(value);
3933
value = ast2obj_list(state,
3934
(asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
3935
ast2obj_expr);
3936
if (!value) goto failed;
3937
if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3938
goto failed;
3939
Py_DECREF(value);
3940
value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
3941
if (!value) goto failed;
3942
if (PyObject_SetAttr(result, state->returns, value) == -1)
3943
goto failed;
3944
Py_DECREF(value);
3945
value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
3946
if (!value) goto failed;
3947
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3948
goto failed;
3949
Py_DECREF(value);
3950
value = ast2obj_list(state,
3951
(asdl_seq*)o->v.AsyncFunctionDef.type_params,
3952
ast2obj_type_param);
3953
if (!value) goto failed;
3954
if (PyObject_SetAttr(result, state->type_params, value) == -1)
3955
goto failed;
3956
Py_DECREF(value);
3957
break;
3958
case ClassDef_kind:
3959
tp = (PyTypeObject *)state->ClassDef_type;
3960
result = PyType_GenericNew(tp, NULL, NULL);
3961
if (!result) goto failed;
3962
value = ast2obj_identifier(state, o->v.ClassDef.name);
3963
if (!value) goto failed;
3964
if (PyObject_SetAttr(result, state->name, value) == -1)
3965
goto failed;
3966
Py_DECREF(value);
3967
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
3968
ast2obj_expr);
3969
if (!value) goto failed;
3970
if (PyObject_SetAttr(result, state->bases, value) == -1)
3971
goto failed;
3972
Py_DECREF(value);
3973
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
3974
ast2obj_keyword);
3975
if (!value) goto failed;
3976
if (PyObject_SetAttr(result, state->keywords, value) == -1)
3977
goto failed;
3978
Py_DECREF(value);
3979
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
3980
ast2obj_stmt);
3981
if (!value) goto failed;
3982
if (PyObject_SetAttr(result, state->body, value) == -1)
3983
goto failed;
3984
Py_DECREF(value);
3985
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
3986
ast2obj_expr);
3987
if (!value) goto failed;
3988
if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3989
goto failed;
3990
Py_DECREF(value);
3991
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.type_params,
3992
ast2obj_type_param);
3993
if (!value) goto failed;
3994
if (PyObject_SetAttr(result, state->type_params, value) == -1)
3995
goto failed;
3996
Py_DECREF(value);
3997
break;
3998
case Return_kind:
3999
tp = (PyTypeObject *)state->Return_type;
4000
result = PyType_GenericNew(tp, NULL, NULL);
4001
if (!result) goto failed;
4002
value = ast2obj_expr(state, o->v.Return.value);
4003
if (!value) goto failed;
4004
if (PyObject_SetAttr(result, state->value, value) == -1)
4005
goto failed;
4006
Py_DECREF(value);
4007
break;
4008
case Delete_kind:
4009
tp = (PyTypeObject *)state->Delete_type;
4010
result = PyType_GenericNew(tp, NULL, NULL);
4011
if (!result) goto failed;
4012
value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
4013
ast2obj_expr);
4014
if (!value) goto failed;
4015
if (PyObject_SetAttr(result, state->targets, value) == -1)
4016
goto failed;
4017
Py_DECREF(value);
4018
break;
4019
case Assign_kind:
4020
tp = (PyTypeObject *)state->Assign_type;
4021
result = PyType_GenericNew(tp, NULL, NULL);
4022
if (!result) goto failed;
4023
value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
4024
ast2obj_expr);
4025
if (!value) goto failed;
4026
if (PyObject_SetAttr(result, state->targets, value) == -1)
4027
goto failed;
4028
Py_DECREF(value);
4029
value = ast2obj_expr(state, o->v.Assign.value);
4030
if (!value) goto failed;
4031
if (PyObject_SetAttr(result, state->value, value) == -1)
4032
goto failed;
4033
Py_DECREF(value);
4034
value = ast2obj_string(state, o->v.Assign.type_comment);
4035
if (!value) goto failed;
4036
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4037
goto failed;
4038
Py_DECREF(value);
4039
break;
4040
case TypeAlias_kind:
4041
tp = (PyTypeObject *)state->TypeAlias_type;
4042
result = PyType_GenericNew(tp, NULL, NULL);
4043
if (!result) goto failed;
4044
value = ast2obj_expr(state, o->v.TypeAlias.name);
4045
if (!value) goto failed;
4046
if (PyObject_SetAttr(result, state->name, value) == -1)
4047
goto failed;
4048
Py_DECREF(value);
4049
value = ast2obj_list(state, (asdl_seq*)o->v.TypeAlias.type_params,
4050
ast2obj_type_param);
4051
if (!value) goto failed;
4052
if (PyObject_SetAttr(result, state->type_params, value) == -1)
4053
goto failed;
4054
Py_DECREF(value);
4055
value = ast2obj_expr(state, o->v.TypeAlias.value);
4056
if (!value) goto failed;
4057
if (PyObject_SetAttr(result, state->value, value) == -1)
4058
goto failed;
4059
Py_DECREF(value);
4060
break;
4061
case AugAssign_kind:
4062
tp = (PyTypeObject *)state->AugAssign_type;
4063
result = PyType_GenericNew(tp, NULL, NULL);
4064
if (!result) goto failed;
4065
value = ast2obj_expr(state, o->v.AugAssign.target);
4066
if (!value) goto failed;
4067
if (PyObject_SetAttr(result, state->target, value) == -1)
4068
goto failed;
4069
Py_DECREF(value);
4070
value = ast2obj_operator(state, o->v.AugAssign.op);
4071
if (!value) goto failed;
4072
if (PyObject_SetAttr(result, state->op, value) == -1)
4073
goto failed;
4074
Py_DECREF(value);
4075
value = ast2obj_expr(state, o->v.AugAssign.value);
4076
if (!value) goto failed;
4077
if (PyObject_SetAttr(result, state->value, value) == -1)
4078
goto failed;
4079
Py_DECREF(value);
4080
break;
4081
case AnnAssign_kind:
4082
tp = (PyTypeObject *)state->AnnAssign_type;
4083
result = PyType_GenericNew(tp, NULL, NULL);
4084
if (!result) goto failed;
4085
value = ast2obj_expr(state, o->v.AnnAssign.target);
4086
if (!value) goto failed;
4087
if (PyObject_SetAttr(result, state->target, value) == -1)
4088
goto failed;
4089
Py_DECREF(value);
4090
value = ast2obj_expr(state, o->v.AnnAssign.annotation);
4091
if (!value) goto failed;
4092
if (PyObject_SetAttr(result, state->annotation, value) == -1)
4093
goto failed;
4094
Py_DECREF(value);
4095
value = ast2obj_expr(state, o->v.AnnAssign.value);
4096
if (!value) goto failed;
4097
if (PyObject_SetAttr(result, state->value, value) == -1)
4098
goto failed;
4099
Py_DECREF(value);
4100
value = ast2obj_int(state, o->v.AnnAssign.simple);
4101
if (!value) goto failed;
4102
if (PyObject_SetAttr(result, state->simple, value) == -1)
4103
goto failed;
4104
Py_DECREF(value);
4105
break;
4106
case For_kind:
4107
tp = (PyTypeObject *)state->For_type;
4108
result = PyType_GenericNew(tp, NULL, NULL);
4109
if (!result) goto failed;
4110
value = ast2obj_expr(state, o->v.For.target);
4111
if (!value) goto failed;
4112
if (PyObject_SetAttr(result, state->target, value) == -1)
4113
goto failed;
4114
Py_DECREF(value);
4115
value = ast2obj_expr(state, o->v.For.iter);
4116
if (!value) goto failed;
4117
if (PyObject_SetAttr(result, state->iter, value) == -1)
4118
goto failed;
4119
Py_DECREF(value);
4120
value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
4121
if (!value) goto failed;
4122
if (PyObject_SetAttr(result, state->body, value) == -1)
4123
goto failed;
4124
Py_DECREF(value);
4125
value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
4126
if (!value) goto failed;
4127
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4128
goto failed;
4129
Py_DECREF(value);
4130
value = ast2obj_string(state, o->v.For.type_comment);
4131
if (!value) goto failed;
4132
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4133
goto failed;
4134
Py_DECREF(value);
4135
break;
4136
case AsyncFor_kind:
4137
tp = (PyTypeObject *)state->AsyncFor_type;
4138
result = PyType_GenericNew(tp, NULL, NULL);
4139
if (!result) goto failed;
4140
value = ast2obj_expr(state, o->v.AsyncFor.target);
4141
if (!value) goto failed;
4142
if (PyObject_SetAttr(result, state->target, value) == -1)
4143
goto failed;
4144
Py_DECREF(value);
4145
value = ast2obj_expr(state, o->v.AsyncFor.iter);
4146
if (!value) goto failed;
4147
if (PyObject_SetAttr(result, state->iter, value) == -1)
4148
goto failed;
4149
Py_DECREF(value);
4150
value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
4151
ast2obj_stmt);
4152
if (!value) goto failed;
4153
if (PyObject_SetAttr(result, state->body, value) == -1)
4154
goto failed;
4155
Py_DECREF(value);
4156
value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
4157
ast2obj_stmt);
4158
if (!value) goto failed;
4159
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4160
goto failed;
4161
Py_DECREF(value);
4162
value = ast2obj_string(state, o->v.AsyncFor.type_comment);
4163
if (!value) goto failed;
4164
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4165
goto failed;
4166
Py_DECREF(value);
4167
break;
4168
case While_kind:
4169
tp = (PyTypeObject *)state->While_type;
4170
result = PyType_GenericNew(tp, NULL, NULL);
4171
if (!result) goto failed;
4172
value = ast2obj_expr(state, o->v.While.test);
4173
if (!value) goto failed;
4174
if (PyObject_SetAttr(result, state->test, value) == -1)
4175
goto failed;
4176
Py_DECREF(value);
4177
value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
4178
if (!value) goto failed;
4179
if (PyObject_SetAttr(result, state->body, value) == -1)
4180
goto failed;
4181
Py_DECREF(value);
4182
value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
4183
if (!value) goto failed;
4184
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4185
goto failed;
4186
Py_DECREF(value);
4187
break;
4188
case If_kind:
4189
tp = (PyTypeObject *)state->If_type;
4190
result = PyType_GenericNew(tp, NULL, NULL);
4191
if (!result) goto failed;
4192
value = ast2obj_expr(state, o->v.If.test);
4193
if (!value) goto failed;
4194
if (PyObject_SetAttr(result, state->test, value) == -1)
4195
goto failed;
4196
Py_DECREF(value);
4197
value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
4198
if (!value) goto failed;
4199
if (PyObject_SetAttr(result, state->body, value) == -1)
4200
goto failed;
4201
Py_DECREF(value);
4202
value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
4203
if (!value) goto failed;
4204
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4205
goto failed;
4206
Py_DECREF(value);
4207
break;
4208
case With_kind:
4209
tp = (PyTypeObject *)state->With_type;
4210
result = PyType_GenericNew(tp, NULL, NULL);
4211
if (!result) goto failed;
4212
value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
4213
ast2obj_withitem);
4214
if (!value) goto failed;
4215
if (PyObject_SetAttr(result, state->items, value) == -1)
4216
goto failed;
4217
Py_DECREF(value);
4218
value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
4219
if (!value) goto failed;
4220
if (PyObject_SetAttr(result, state->body, value) == -1)
4221
goto failed;
4222
Py_DECREF(value);
4223
value = ast2obj_string(state, o->v.With.type_comment);
4224
if (!value) goto failed;
4225
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4226
goto failed;
4227
Py_DECREF(value);
4228
break;
4229
case AsyncWith_kind:
4230
tp = (PyTypeObject *)state->AsyncWith_type;
4231
result = PyType_GenericNew(tp, NULL, NULL);
4232
if (!result) goto failed;
4233
value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
4234
ast2obj_withitem);
4235
if (!value) goto failed;
4236
if (PyObject_SetAttr(result, state->items, value) == -1)
4237
goto failed;
4238
Py_DECREF(value);
4239
value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
4240
ast2obj_stmt);
4241
if (!value) goto failed;
4242
if (PyObject_SetAttr(result, state->body, value) == -1)
4243
goto failed;
4244
Py_DECREF(value);
4245
value = ast2obj_string(state, o->v.AsyncWith.type_comment);
4246
if (!value) goto failed;
4247
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4248
goto failed;
4249
Py_DECREF(value);
4250
break;
4251
case Match_kind:
4252
tp = (PyTypeObject *)state->Match_type;
4253
result = PyType_GenericNew(tp, NULL, NULL);
4254
if (!result) goto failed;
4255
value = ast2obj_expr(state, o->v.Match.subject);
4256
if (!value) goto failed;
4257
if (PyObject_SetAttr(result, state->subject, value) == -1)
4258
goto failed;
4259
Py_DECREF(value);
4260
value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
4261
ast2obj_match_case);
4262
if (!value) goto failed;
4263
if (PyObject_SetAttr(result, state->cases, value) == -1)
4264
goto failed;
4265
Py_DECREF(value);
4266
break;
4267
case Raise_kind:
4268
tp = (PyTypeObject *)state->Raise_type;
4269
result = PyType_GenericNew(tp, NULL, NULL);
4270
if (!result) goto failed;
4271
value = ast2obj_expr(state, o->v.Raise.exc);
4272
if (!value) goto failed;
4273
if (PyObject_SetAttr(result, state->exc, value) == -1)
4274
goto failed;
4275
Py_DECREF(value);
4276
value = ast2obj_expr(state, o->v.Raise.cause);
4277
if (!value) goto failed;
4278
if (PyObject_SetAttr(result, state->cause, value) == -1)
4279
goto failed;
4280
Py_DECREF(value);
4281
break;
4282
case Try_kind:
4283
tp = (PyTypeObject *)state->Try_type;
4284
result = PyType_GenericNew(tp, NULL, NULL);
4285
if (!result) goto failed;
4286
value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
4287
if (!value) goto failed;
4288
if (PyObject_SetAttr(result, state->body, value) == -1)
4289
goto failed;
4290
Py_DECREF(value);
4291
value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
4292
ast2obj_excepthandler);
4293
if (!value) goto failed;
4294
if (PyObject_SetAttr(result, state->handlers, value) == -1)
4295
goto failed;
4296
Py_DECREF(value);
4297
value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
4298
if (!value) goto failed;
4299
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4300
goto failed;
4301
Py_DECREF(value);
4302
value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
4303
ast2obj_stmt);
4304
if (!value) goto failed;
4305
if (PyObject_SetAttr(result, state->finalbody, value) == -1)
4306
goto failed;
4307
Py_DECREF(value);
4308
break;
4309
case TryStar_kind:
4310
tp = (PyTypeObject *)state->TryStar_type;
4311
result = PyType_GenericNew(tp, NULL, NULL);
4312
if (!result) goto failed;
4313
value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.body, ast2obj_stmt);
4314
if (!value) goto failed;
4315
if (PyObject_SetAttr(result, state->body, value) == -1)
4316
goto failed;
4317
Py_DECREF(value);
4318
value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.handlers,
4319
ast2obj_excepthandler);
4320
if (!value) goto failed;
4321
if (PyObject_SetAttr(result, state->handlers, value) == -1)
4322
goto failed;
4323
Py_DECREF(value);
4324
value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.orelse,
4325
ast2obj_stmt);
4326
if (!value) goto failed;
4327
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4328
goto failed;
4329
Py_DECREF(value);
4330
value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.finalbody,
4331
ast2obj_stmt);
4332
if (!value) goto failed;
4333
if (PyObject_SetAttr(result, state->finalbody, value) == -1)
4334
goto failed;
4335
Py_DECREF(value);
4336
break;
4337
case Assert_kind:
4338
tp = (PyTypeObject *)state->Assert_type;
4339
result = PyType_GenericNew(tp, NULL, NULL);
4340
if (!result) goto failed;
4341
value = ast2obj_expr(state, o->v.Assert.test);
4342
if (!value) goto failed;
4343
if (PyObject_SetAttr(result, state->test, value) == -1)
4344
goto failed;
4345
Py_DECREF(value);
4346
value = ast2obj_expr(state, o->v.Assert.msg);
4347
if (!value) goto failed;
4348
if (PyObject_SetAttr(result, state->msg, value) == -1)
4349
goto failed;
4350
Py_DECREF(value);
4351
break;
4352
case Import_kind:
4353
tp = (PyTypeObject *)state->Import_type;
4354
result = PyType_GenericNew(tp, NULL, NULL);
4355
if (!result) goto failed;
4356
value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
4357
ast2obj_alias);
4358
if (!value) goto failed;
4359
if (PyObject_SetAttr(result, state->names, value) == -1)
4360
goto failed;
4361
Py_DECREF(value);
4362
break;
4363
case ImportFrom_kind:
4364
tp = (PyTypeObject *)state->ImportFrom_type;
4365
result = PyType_GenericNew(tp, NULL, NULL);
4366
if (!result) goto failed;
4367
value = ast2obj_identifier(state, o->v.ImportFrom.module);
4368
if (!value) goto failed;
4369
if (PyObject_SetAttr(result, state->module, value) == -1)
4370
goto failed;
4371
Py_DECREF(value);
4372
value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
4373
ast2obj_alias);
4374
if (!value) goto failed;
4375
if (PyObject_SetAttr(result, state->names, value) == -1)
4376
goto failed;
4377
Py_DECREF(value);
4378
value = ast2obj_int(state, o->v.ImportFrom.level);
4379
if (!value) goto failed;
4380
if (PyObject_SetAttr(result, state->level, value) == -1)
4381
goto failed;
4382
Py_DECREF(value);
4383
break;
4384
case Global_kind:
4385
tp = (PyTypeObject *)state->Global_type;
4386
result = PyType_GenericNew(tp, NULL, NULL);
4387
if (!result) goto failed;
4388
value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
4389
ast2obj_identifier);
4390
if (!value) goto failed;
4391
if (PyObject_SetAttr(result, state->names, value) == -1)
4392
goto failed;
4393
Py_DECREF(value);
4394
break;
4395
case Nonlocal_kind:
4396
tp = (PyTypeObject *)state->Nonlocal_type;
4397
result = PyType_GenericNew(tp, NULL, NULL);
4398
if (!result) goto failed;
4399
value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
4400
ast2obj_identifier);
4401
if (!value) goto failed;
4402
if (PyObject_SetAttr(result, state->names, value) == -1)
4403
goto failed;
4404
Py_DECREF(value);
4405
break;
4406
case Expr_kind:
4407
tp = (PyTypeObject *)state->Expr_type;
4408
result = PyType_GenericNew(tp, NULL, NULL);
4409
if (!result) goto failed;
4410
value = ast2obj_expr(state, o->v.Expr.value);
4411
if (!value) goto failed;
4412
if (PyObject_SetAttr(result, state->value, value) == -1)
4413
goto failed;
4414
Py_DECREF(value);
4415
break;
4416
case Pass_kind:
4417
tp = (PyTypeObject *)state->Pass_type;
4418
result = PyType_GenericNew(tp, NULL, NULL);
4419
if (!result) goto failed;
4420
break;
4421
case Break_kind:
4422
tp = (PyTypeObject *)state->Break_type;
4423
result = PyType_GenericNew(tp, NULL, NULL);
4424
if (!result) goto failed;
4425
break;
4426
case Continue_kind:
4427
tp = (PyTypeObject *)state->Continue_type;
4428
result = PyType_GenericNew(tp, NULL, NULL);
4429
if (!result) goto failed;
4430
break;
4431
}
4432
value = ast2obj_int(state, o->lineno);
4433
if (!value) goto failed;
4434
if (PyObject_SetAttr(result, state->lineno, value) < 0)
4435
goto failed;
4436
Py_DECREF(value);
4437
value = ast2obj_int(state, o->col_offset);
4438
if (!value) goto failed;
4439
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4440
goto failed;
4441
Py_DECREF(value);
4442
value = ast2obj_int(state, o->end_lineno);
4443
if (!value) goto failed;
4444
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4445
goto failed;
4446
Py_DECREF(value);
4447
value = ast2obj_int(state, o->end_col_offset);
4448
if (!value) goto failed;
4449
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4450
goto failed;
4451
Py_DECREF(value);
4452
state->recursion_depth--;
4453
return result;
4454
failed:
4455
Py_XDECREF(value);
4456
Py_XDECREF(result);
4457
return NULL;
4458
}
4459
4460
PyObject*
4461
ast2obj_expr(struct ast_state *state, void* _o)
4462
{
4463
expr_ty o = (expr_ty)_o;
4464
PyObject *result = NULL, *value = NULL;
4465
PyTypeObject *tp;
4466
if (!o) {
4467
Py_RETURN_NONE;
4468
}
4469
if (++state->recursion_depth > state->recursion_limit) {
4470
PyErr_SetString(PyExc_RecursionError,
4471
"maximum recursion depth exceeded during ast construction");
4472
return 0;
4473
}
4474
switch (o->kind) {
4475
case BoolOp_kind:
4476
tp = (PyTypeObject *)state->BoolOp_type;
4477
result = PyType_GenericNew(tp, NULL, NULL);
4478
if (!result) goto failed;
4479
value = ast2obj_boolop(state, o->v.BoolOp.op);
4480
if (!value) goto failed;
4481
if (PyObject_SetAttr(result, state->op, value) == -1)
4482
goto failed;
4483
Py_DECREF(value);
4484
value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
4485
ast2obj_expr);
4486
if (!value) goto failed;
4487
if (PyObject_SetAttr(result, state->values, value) == -1)
4488
goto failed;
4489
Py_DECREF(value);
4490
break;
4491
case NamedExpr_kind:
4492
tp = (PyTypeObject *)state->NamedExpr_type;
4493
result = PyType_GenericNew(tp, NULL, NULL);
4494
if (!result) goto failed;
4495
value = ast2obj_expr(state, o->v.NamedExpr.target);
4496
if (!value) goto failed;
4497
if (PyObject_SetAttr(result, state->target, value) == -1)
4498
goto failed;
4499
Py_DECREF(value);
4500
value = ast2obj_expr(state, o->v.NamedExpr.value);
4501
if (!value) goto failed;
4502
if (PyObject_SetAttr(result, state->value, value) == -1)
4503
goto failed;
4504
Py_DECREF(value);
4505
break;
4506
case BinOp_kind:
4507
tp = (PyTypeObject *)state->BinOp_type;
4508
result = PyType_GenericNew(tp, NULL, NULL);
4509
if (!result) goto failed;
4510
value = ast2obj_expr(state, o->v.BinOp.left);
4511
if (!value) goto failed;
4512
if (PyObject_SetAttr(result, state->left, value) == -1)
4513
goto failed;
4514
Py_DECREF(value);
4515
value = ast2obj_operator(state, o->v.BinOp.op);
4516
if (!value) goto failed;
4517
if (PyObject_SetAttr(result, state->op, value) == -1)
4518
goto failed;
4519
Py_DECREF(value);
4520
value = ast2obj_expr(state, o->v.BinOp.right);
4521
if (!value) goto failed;
4522
if (PyObject_SetAttr(result, state->right, value) == -1)
4523
goto failed;
4524
Py_DECREF(value);
4525
break;
4526
case UnaryOp_kind:
4527
tp = (PyTypeObject *)state->UnaryOp_type;
4528
result = PyType_GenericNew(tp, NULL, NULL);
4529
if (!result) goto failed;
4530
value = ast2obj_unaryop(state, o->v.UnaryOp.op);
4531
if (!value) goto failed;
4532
if (PyObject_SetAttr(result, state->op, value) == -1)
4533
goto failed;
4534
Py_DECREF(value);
4535
value = ast2obj_expr(state, o->v.UnaryOp.operand);
4536
if (!value) goto failed;
4537
if (PyObject_SetAttr(result, state->operand, value) == -1)
4538
goto failed;
4539
Py_DECREF(value);
4540
break;
4541
case Lambda_kind:
4542
tp = (PyTypeObject *)state->Lambda_type;
4543
result = PyType_GenericNew(tp, NULL, NULL);
4544
if (!result) goto failed;
4545
value = ast2obj_arguments(state, o->v.Lambda.args);
4546
if (!value) goto failed;
4547
if (PyObject_SetAttr(result, state->args, value) == -1)
4548
goto failed;
4549
Py_DECREF(value);
4550
value = ast2obj_expr(state, o->v.Lambda.body);
4551
if (!value) goto failed;
4552
if (PyObject_SetAttr(result, state->body, value) == -1)
4553
goto failed;
4554
Py_DECREF(value);
4555
break;
4556
case IfExp_kind:
4557
tp = (PyTypeObject *)state->IfExp_type;
4558
result = PyType_GenericNew(tp, NULL, NULL);
4559
if (!result) goto failed;
4560
value = ast2obj_expr(state, o->v.IfExp.test);
4561
if (!value) goto failed;
4562
if (PyObject_SetAttr(result, state->test, value) == -1)
4563
goto failed;
4564
Py_DECREF(value);
4565
value = ast2obj_expr(state, o->v.IfExp.body);
4566
if (!value) goto failed;
4567
if (PyObject_SetAttr(result, state->body, value) == -1)
4568
goto failed;
4569
Py_DECREF(value);
4570
value = ast2obj_expr(state, o->v.IfExp.orelse);
4571
if (!value) goto failed;
4572
if (PyObject_SetAttr(result, state->orelse, value) == -1)
4573
goto failed;
4574
Py_DECREF(value);
4575
break;
4576
case Dict_kind:
4577
tp = (PyTypeObject *)state->Dict_type;
4578
result = PyType_GenericNew(tp, NULL, NULL);
4579
if (!result) goto failed;
4580
value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
4581
if (!value) goto failed;
4582
if (PyObject_SetAttr(result, state->keys, value) == -1)
4583
goto failed;
4584
Py_DECREF(value);
4585
value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
4586
if (!value) goto failed;
4587
if (PyObject_SetAttr(result, state->values, value) == -1)
4588
goto failed;
4589
Py_DECREF(value);
4590
break;
4591
case Set_kind:
4592
tp = (PyTypeObject *)state->Set_type;
4593
result = PyType_GenericNew(tp, NULL, NULL);
4594
if (!result) goto failed;
4595
value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
4596
if (!value) goto failed;
4597
if (PyObject_SetAttr(result, state->elts, value) == -1)
4598
goto failed;
4599
Py_DECREF(value);
4600
break;
4601
case ListComp_kind:
4602
tp = (PyTypeObject *)state->ListComp_type;
4603
result = PyType_GenericNew(tp, NULL, NULL);
4604
if (!result) goto failed;
4605
value = ast2obj_expr(state, o->v.ListComp.elt);
4606
if (!value) goto failed;
4607
if (PyObject_SetAttr(result, state->elt, value) == -1)
4608
goto failed;
4609
Py_DECREF(value);
4610
value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
4611
ast2obj_comprehension);
4612
if (!value) goto failed;
4613
if (PyObject_SetAttr(result, state->generators, value) == -1)
4614
goto failed;
4615
Py_DECREF(value);
4616
break;
4617
case SetComp_kind:
4618
tp = (PyTypeObject *)state->SetComp_type;
4619
result = PyType_GenericNew(tp, NULL, NULL);
4620
if (!result) goto failed;
4621
value = ast2obj_expr(state, o->v.SetComp.elt);
4622
if (!value) goto failed;
4623
if (PyObject_SetAttr(result, state->elt, value) == -1)
4624
goto failed;
4625
Py_DECREF(value);
4626
value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
4627
ast2obj_comprehension);
4628
if (!value) goto failed;
4629
if (PyObject_SetAttr(result, state->generators, value) == -1)
4630
goto failed;
4631
Py_DECREF(value);
4632
break;
4633
case DictComp_kind:
4634
tp = (PyTypeObject *)state->DictComp_type;
4635
result = PyType_GenericNew(tp, NULL, NULL);
4636
if (!result) goto failed;
4637
value = ast2obj_expr(state, o->v.DictComp.key);
4638
if (!value) goto failed;
4639
if (PyObject_SetAttr(result, state->key, value) == -1)
4640
goto failed;
4641
Py_DECREF(value);
4642
value = ast2obj_expr(state, o->v.DictComp.value);
4643
if (!value) goto failed;
4644
if (PyObject_SetAttr(result, state->value, value) == -1)
4645
goto failed;
4646
Py_DECREF(value);
4647
value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
4648
ast2obj_comprehension);
4649
if (!value) goto failed;
4650
if (PyObject_SetAttr(result, state->generators, value) == -1)
4651
goto failed;
4652
Py_DECREF(value);
4653
break;
4654
case GeneratorExp_kind:
4655
tp = (PyTypeObject *)state->GeneratorExp_type;
4656
result = PyType_GenericNew(tp, NULL, NULL);
4657
if (!result) goto failed;
4658
value = ast2obj_expr(state, o->v.GeneratorExp.elt);
4659
if (!value) goto failed;
4660
if (PyObject_SetAttr(result, state->elt, value) == -1)
4661
goto failed;
4662
Py_DECREF(value);
4663
value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
4664
ast2obj_comprehension);
4665
if (!value) goto failed;
4666
if (PyObject_SetAttr(result, state->generators, value) == -1)
4667
goto failed;
4668
Py_DECREF(value);
4669
break;
4670
case Await_kind:
4671
tp = (PyTypeObject *)state->Await_type;
4672
result = PyType_GenericNew(tp, NULL, NULL);
4673
if (!result) goto failed;
4674
value = ast2obj_expr(state, o->v.Await.value);
4675
if (!value) goto failed;
4676
if (PyObject_SetAttr(result, state->value, value) == -1)
4677
goto failed;
4678
Py_DECREF(value);
4679
break;
4680
case Yield_kind:
4681
tp = (PyTypeObject *)state->Yield_type;
4682
result = PyType_GenericNew(tp, NULL, NULL);
4683
if (!result) goto failed;
4684
value = ast2obj_expr(state, o->v.Yield.value);
4685
if (!value) goto failed;
4686
if (PyObject_SetAttr(result, state->value, value) == -1)
4687
goto failed;
4688
Py_DECREF(value);
4689
break;
4690
case YieldFrom_kind:
4691
tp = (PyTypeObject *)state->YieldFrom_type;
4692
result = PyType_GenericNew(tp, NULL, NULL);
4693
if (!result) goto failed;
4694
value = ast2obj_expr(state, o->v.YieldFrom.value);
4695
if (!value) goto failed;
4696
if (PyObject_SetAttr(result, state->value, value) == -1)
4697
goto failed;
4698
Py_DECREF(value);
4699
break;
4700
case Compare_kind:
4701
tp = (PyTypeObject *)state->Compare_type;
4702
result = PyType_GenericNew(tp, NULL, NULL);
4703
if (!result) goto failed;
4704
value = ast2obj_expr(state, o->v.Compare.left);
4705
if (!value) goto failed;
4706
if (PyObject_SetAttr(result, state->left, value) == -1)
4707
goto failed;
4708
Py_DECREF(value);
4709
{
4710
Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4711
value = PyList_New(n);
4712
if (!value) goto failed;
4713
for(i = 0; i < n; i++)
4714
PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
4715
}
4716
if (!value) goto failed;
4717
if (PyObject_SetAttr(result, state->ops, value) == -1)
4718
goto failed;
4719
Py_DECREF(value);
4720
value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
4721
ast2obj_expr);
4722
if (!value) goto failed;
4723
if (PyObject_SetAttr(result, state->comparators, value) == -1)
4724
goto failed;
4725
Py_DECREF(value);
4726
break;
4727
case Call_kind:
4728
tp = (PyTypeObject *)state->Call_type;
4729
result = PyType_GenericNew(tp, NULL, NULL);
4730
if (!result) goto failed;
4731
value = ast2obj_expr(state, o->v.Call.func);
4732
if (!value) goto failed;
4733
if (PyObject_SetAttr(result, state->func, value) == -1)
4734
goto failed;
4735
Py_DECREF(value);
4736
value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
4737
if (!value) goto failed;
4738
if (PyObject_SetAttr(result, state->args, value) == -1)
4739
goto failed;
4740
Py_DECREF(value);
4741
value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
4742
ast2obj_keyword);
4743
if (!value) goto failed;
4744
if (PyObject_SetAttr(result, state->keywords, value) == -1)
4745
goto failed;
4746
Py_DECREF(value);
4747
break;
4748
case FormattedValue_kind:
4749
tp = (PyTypeObject *)state->FormattedValue_type;
4750
result = PyType_GenericNew(tp, NULL, NULL);
4751
if (!result) goto failed;
4752
value = ast2obj_expr(state, o->v.FormattedValue.value);
4753
if (!value) goto failed;
4754
if (PyObject_SetAttr(result, state->value, value) == -1)
4755
goto failed;
4756
Py_DECREF(value);
4757
value = ast2obj_int(state, o->v.FormattedValue.conversion);
4758
if (!value) goto failed;
4759
if (PyObject_SetAttr(result, state->conversion, value) == -1)
4760
goto failed;
4761
Py_DECREF(value);
4762
value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
4763
if (!value) goto failed;
4764
if (PyObject_SetAttr(result, state->format_spec, value) == -1)
4765
goto failed;
4766
Py_DECREF(value);
4767
break;
4768
case JoinedStr_kind:
4769
tp = (PyTypeObject *)state->JoinedStr_type;
4770
result = PyType_GenericNew(tp, NULL, NULL);
4771
if (!result) goto failed;
4772
value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
4773
ast2obj_expr);
4774
if (!value) goto failed;
4775
if (PyObject_SetAttr(result, state->values, value) == -1)
4776
goto failed;
4777
Py_DECREF(value);
4778
break;
4779
case Constant_kind:
4780
tp = (PyTypeObject *)state->Constant_type;
4781
result = PyType_GenericNew(tp, NULL, NULL);
4782
if (!result) goto failed;
4783
value = ast2obj_constant(state, o->v.Constant.value);
4784
if (!value) goto failed;
4785
if (PyObject_SetAttr(result, state->value, value) == -1)
4786
goto failed;
4787
Py_DECREF(value);
4788
value = ast2obj_string(state, o->v.Constant.kind);
4789
if (!value) goto failed;
4790
if (PyObject_SetAttr(result, state->kind, value) == -1)
4791
goto failed;
4792
Py_DECREF(value);
4793
break;
4794
case Attribute_kind:
4795
tp = (PyTypeObject *)state->Attribute_type;
4796
result = PyType_GenericNew(tp, NULL, NULL);
4797
if (!result) goto failed;
4798
value = ast2obj_expr(state, o->v.Attribute.value);
4799
if (!value) goto failed;
4800
if (PyObject_SetAttr(result, state->value, value) == -1)
4801
goto failed;
4802
Py_DECREF(value);
4803
value = ast2obj_identifier(state, o->v.Attribute.attr);
4804
if (!value) goto failed;
4805
if (PyObject_SetAttr(result, state->attr, value) == -1)
4806
goto failed;
4807
Py_DECREF(value);
4808
value = ast2obj_expr_context(state, o->v.Attribute.ctx);
4809
if (!value) goto failed;
4810
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4811
goto failed;
4812
Py_DECREF(value);
4813
break;
4814
case Subscript_kind:
4815
tp = (PyTypeObject *)state->Subscript_type;
4816
result = PyType_GenericNew(tp, NULL, NULL);
4817
if (!result) goto failed;
4818
value = ast2obj_expr(state, o->v.Subscript.value);
4819
if (!value) goto failed;
4820
if (PyObject_SetAttr(result, state->value, value) == -1)
4821
goto failed;
4822
Py_DECREF(value);
4823
value = ast2obj_expr(state, o->v.Subscript.slice);
4824
if (!value) goto failed;
4825
if (PyObject_SetAttr(result, state->slice, value) == -1)
4826
goto failed;
4827
Py_DECREF(value);
4828
value = ast2obj_expr_context(state, o->v.Subscript.ctx);
4829
if (!value) goto failed;
4830
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4831
goto failed;
4832
Py_DECREF(value);
4833
break;
4834
case Starred_kind:
4835
tp = (PyTypeObject *)state->Starred_type;
4836
result = PyType_GenericNew(tp, NULL, NULL);
4837
if (!result) goto failed;
4838
value = ast2obj_expr(state, o->v.Starred.value);
4839
if (!value) goto failed;
4840
if (PyObject_SetAttr(result, state->value, value) == -1)
4841
goto failed;
4842
Py_DECREF(value);
4843
value = ast2obj_expr_context(state, o->v.Starred.ctx);
4844
if (!value) goto failed;
4845
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4846
goto failed;
4847
Py_DECREF(value);
4848
break;
4849
case Name_kind:
4850
tp = (PyTypeObject *)state->Name_type;
4851
result = PyType_GenericNew(tp, NULL, NULL);
4852
if (!result) goto failed;
4853
value = ast2obj_identifier(state, o->v.Name.id);
4854
if (!value) goto failed;
4855
if (PyObject_SetAttr(result, state->id, value) == -1)
4856
goto failed;
4857
Py_DECREF(value);
4858
value = ast2obj_expr_context(state, o->v.Name.ctx);
4859
if (!value) goto failed;
4860
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4861
goto failed;
4862
Py_DECREF(value);
4863
break;
4864
case List_kind:
4865
tp = (PyTypeObject *)state->List_type;
4866
result = PyType_GenericNew(tp, NULL, NULL);
4867
if (!result) goto failed;
4868
value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
4869
if (!value) goto failed;
4870
if (PyObject_SetAttr(result, state->elts, value) == -1)
4871
goto failed;
4872
Py_DECREF(value);
4873
value = ast2obj_expr_context(state, o->v.List.ctx);
4874
if (!value) goto failed;
4875
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4876
goto failed;
4877
Py_DECREF(value);
4878
break;
4879
case Tuple_kind:
4880
tp = (PyTypeObject *)state->Tuple_type;
4881
result = PyType_GenericNew(tp, NULL, NULL);
4882
if (!result) goto failed;
4883
value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
4884
if (!value) goto failed;
4885
if (PyObject_SetAttr(result, state->elts, value) == -1)
4886
goto failed;
4887
Py_DECREF(value);
4888
value = ast2obj_expr_context(state, o->v.Tuple.ctx);
4889
if (!value) goto failed;
4890
if (PyObject_SetAttr(result, state->ctx, value) == -1)
4891
goto failed;
4892
Py_DECREF(value);
4893
break;
4894
case Slice_kind:
4895
tp = (PyTypeObject *)state->Slice_type;
4896
result = PyType_GenericNew(tp, NULL, NULL);
4897
if (!result) goto failed;
4898
value = ast2obj_expr(state, o->v.Slice.lower);
4899
if (!value) goto failed;
4900
if (PyObject_SetAttr(result, state->lower, value) == -1)
4901
goto failed;
4902
Py_DECREF(value);
4903
value = ast2obj_expr(state, o->v.Slice.upper);
4904
if (!value) goto failed;
4905
if (PyObject_SetAttr(result, state->upper, value) == -1)
4906
goto failed;
4907
Py_DECREF(value);
4908
value = ast2obj_expr(state, o->v.Slice.step);
4909
if (!value) goto failed;
4910
if (PyObject_SetAttr(result, state->step, value) == -1)
4911
goto failed;
4912
Py_DECREF(value);
4913
break;
4914
}
4915
value = ast2obj_int(state, o->lineno);
4916
if (!value) goto failed;
4917
if (PyObject_SetAttr(result, state->lineno, value) < 0)
4918
goto failed;
4919
Py_DECREF(value);
4920
value = ast2obj_int(state, o->col_offset);
4921
if (!value) goto failed;
4922
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4923
goto failed;
4924
Py_DECREF(value);
4925
value = ast2obj_int(state, o->end_lineno);
4926
if (!value) goto failed;
4927
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4928
goto failed;
4929
Py_DECREF(value);
4930
value = ast2obj_int(state, o->end_col_offset);
4931
if (!value) goto failed;
4932
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4933
goto failed;
4934
Py_DECREF(value);
4935
state->recursion_depth--;
4936
return result;
4937
failed:
4938
Py_XDECREF(value);
4939
Py_XDECREF(result);
4940
return NULL;
4941
}
4942
4943
PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
4944
{
4945
switch(o) {
4946
case Load:
4947
return Py_NewRef(state->Load_singleton);
4948
case Store:
4949
return Py_NewRef(state->Store_singleton);
4950
case Del:
4951
return Py_NewRef(state->Del_singleton);
4952
}
4953
Py_UNREACHABLE();
4954
}
4955
PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
4956
{
4957
switch(o) {
4958
case And:
4959
return Py_NewRef(state->And_singleton);
4960
case Or:
4961
return Py_NewRef(state->Or_singleton);
4962
}
4963
Py_UNREACHABLE();
4964
}
4965
PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
4966
{
4967
switch(o) {
4968
case Add:
4969
return Py_NewRef(state->Add_singleton);
4970
case Sub:
4971
return Py_NewRef(state->Sub_singleton);
4972
case Mult:
4973
return Py_NewRef(state->Mult_singleton);
4974
case MatMult:
4975
return Py_NewRef(state->MatMult_singleton);
4976
case Div:
4977
return Py_NewRef(state->Div_singleton);
4978
case Mod:
4979
return Py_NewRef(state->Mod_singleton);
4980
case Pow:
4981
return Py_NewRef(state->Pow_singleton);
4982
case LShift:
4983
return Py_NewRef(state->LShift_singleton);
4984
case RShift:
4985
return Py_NewRef(state->RShift_singleton);
4986
case BitOr:
4987
return Py_NewRef(state->BitOr_singleton);
4988
case BitXor:
4989
return Py_NewRef(state->BitXor_singleton);
4990
case BitAnd:
4991
return Py_NewRef(state->BitAnd_singleton);
4992
case FloorDiv:
4993
return Py_NewRef(state->FloorDiv_singleton);
4994
}
4995
Py_UNREACHABLE();
4996
}
4997
PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
4998
{
4999
switch(o) {
5000
case Invert:
5001
return Py_NewRef(state->Invert_singleton);
5002
case Not:
5003
return Py_NewRef(state->Not_singleton);
5004
case UAdd:
5005
return Py_NewRef(state->UAdd_singleton);
5006
case USub:
5007
return Py_NewRef(state->USub_singleton);
5008
}
5009
Py_UNREACHABLE();
5010
}
5011
PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
5012
{
5013
switch(o) {
5014
case Eq:
5015
return Py_NewRef(state->Eq_singleton);
5016
case NotEq:
5017
return Py_NewRef(state->NotEq_singleton);
5018
case Lt:
5019
return Py_NewRef(state->Lt_singleton);
5020
case LtE:
5021
return Py_NewRef(state->LtE_singleton);
5022
case Gt:
5023
return Py_NewRef(state->Gt_singleton);
5024
case GtE:
5025
return Py_NewRef(state->GtE_singleton);
5026
case Is:
5027
return Py_NewRef(state->Is_singleton);
5028
case IsNot:
5029
return Py_NewRef(state->IsNot_singleton);
5030
case In:
5031
return Py_NewRef(state->In_singleton);
5032
case NotIn:
5033
return Py_NewRef(state->NotIn_singleton);
5034
}
5035
Py_UNREACHABLE();
5036
}
5037
PyObject*
5038
ast2obj_comprehension(struct ast_state *state, void* _o)
5039
{
5040
comprehension_ty o = (comprehension_ty)_o;
5041
PyObject *result = NULL, *value = NULL;
5042
PyTypeObject *tp;
5043
if (!o) {
5044
Py_RETURN_NONE;
5045
}
5046
if (++state->recursion_depth > state->recursion_limit) {
5047
PyErr_SetString(PyExc_RecursionError,
5048
"maximum recursion depth exceeded during ast construction");
5049
return 0;
5050
}
5051
tp = (PyTypeObject *)state->comprehension_type;
5052
result = PyType_GenericNew(tp, NULL, NULL);
5053
if (!result) return NULL;
5054
value = ast2obj_expr(state, o->target);
5055
if (!value) goto failed;
5056
if (PyObject_SetAttr(result, state->target, value) == -1)
5057
goto failed;
5058
Py_DECREF(value);
5059
value = ast2obj_expr(state, o->iter);
5060
if (!value) goto failed;
5061
if (PyObject_SetAttr(result, state->iter, value) == -1)
5062
goto failed;
5063
Py_DECREF(value);
5064
value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
5065
if (!value) goto failed;
5066
if (PyObject_SetAttr(result, state->ifs, value) == -1)
5067
goto failed;
5068
Py_DECREF(value);
5069
value = ast2obj_int(state, o->is_async);
5070
if (!value) goto failed;
5071
if (PyObject_SetAttr(result, state->is_async, value) == -1)
5072
goto failed;
5073
Py_DECREF(value);
5074
state->recursion_depth--;
5075
return result;
5076
failed:
5077
Py_XDECREF(value);
5078
Py_XDECREF(result);
5079
return NULL;
5080
}
5081
5082
PyObject*
5083
ast2obj_excepthandler(struct ast_state *state, void* _o)
5084
{
5085
excepthandler_ty o = (excepthandler_ty)_o;
5086
PyObject *result = NULL, *value = NULL;
5087
PyTypeObject *tp;
5088
if (!o) {
5089
Py_RETURN_NONE;
5090
}
5091
if (++state->recursion_depth > state->recursion_limit) {
5092
PyErr_SetString(PyExc_RecursionError,
5093
"maximum recursion depth exceeded during ast construction");
5094
return 0;
5095
}
5096
switch (o->kind) {
5097
case ExceptHandler_kind:
5098
tp = (PyTypeObject *)state->ExceptHandler_type;
5099
result = PyType_GenericNew(tp, NULL, NULL);
5100
if (!result) goto failed;
5101
value = ast2obj_expr(state, o->v.ExceptHandler.type);
5102
if (!value) goto failed;
5103
if (PyObject_SetAttr(result, state->type, value) == -1)
5104
goto failed;
5105
Py_DECREF(value);
5106
value = ast2obj_identifier(state, o->v.ExceptHandler.name);
5107
if (!value) goto failed;
5108
if (PyObject_SetAttr(result, state->name, value) == -1)
5109
goto failed;
5110
Py_DECREF(value);
5111
value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
5112
ast2obj_stmt);
5113
if (!value) goto failed;
5114
if (PyObject_SetAttr(result, state->body, value) == -1)
5115
goto failed;
5116
Py_DECREF(value);
5117
break;
5118
}
5119
value = ast2obj_int(state, o->lineno);
5120
if (!value) goto failed;
5121
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5122
goto failed;
5123
Py_DECREF(value);
5124
value = ast2obj_int(state, o->col_offset);
5125
if (!value) goto failed;
5126
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5127
goto failed;
5128
Py_DECREF(value);
5129
value = ast2obj_int(state, o->end_lineno);
5130
if (!value) goto failed;
5131
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5132
goto failed;
5133
Py_DECREF(value);
5134
value = ast2obj_int(state, o->end_col_offset);
5135
if (!value) goto failed;
5136
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5137
goto failed;
5138
Py_DECREF(value);
5139
state->recursion_depth--;
5140
return result;
5141
failed:
5142
Py_XDECREF(value);
5143
Py_XDECREF(result);
5144
return NULL;
5145
}
5146
5147
PyObject*
5148
ast2obj_arguments(struct ast_state *state, void* _o)
5149
{
5150
arguments_ty o = (arguments_ty)_o;
5151
PyObject *result = NULL, *value = NULL;
5152
PyTypeObject *tp;
5153
if (!o) {
5154
Py_RETURN_NONE;
5155
}
5156
if (++state->recursion_depth > state->recursion_limit) {
5157
PyErr_SetString(PyExc_RecursionError,
5158
"maximum recursion depth exceeded during ast construction");
5159
return 0;
5160
}
5161
tp = (PyTypeObject *)state->arguments_type;
5162
result = PyType_GenericNew(tp, NULL, NULL);
5163
if (!result) return NULL;
5164
value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
5165
if (!value) goto failed;
5166
if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
5167
goto failed;
5168
Py_DECREF(value);
5169
value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
5170
if (!value) goto failed;
5171
if (PyObject_SetAttr(result, state->args, value) == -1)
5172
goto failed;
5173
Py_DECREF(value);
5174
value = ast2obj_arg(state, o->vararg);
5175
if (!value) goto failed;
5176
if (PyObject_SetAttr(result, state->vararg, value) == -1)
5177
goto failed;
5178
Py_DECREF(value);
5179
value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
5180
if (!value) goto failed;
5181
if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
5182
goto failed;
5183
Py_DECREF(value);
5184
value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
5185
if (!value) goto failed;
5186
if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
5187
goto failed;
5188
Py_DECREF(value);
5189
value = ast2obj_arg(state, o->kwarg);
5190
if (!value) goto failed;
5191
if (PyObject_SetAttr(result, state->kwarg, value) == -1)
5192
goto failed;
5193
Py_DECREF(value);
5194
value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
5195
if (!value) goto failed;
5196
if (PyObject_SetAttr(result, state->defaults, value) == -1)
5197
goto failed;
5198
Py_DECREF(value);
5199
state->recursion_depth--;
5200
return result;
5201
failed:
5202
Py_XDECREF(value);
5203
Py_XDECREF(result);
5204
return NULL;
5205
}
5206
5207
PyObject*
5208
ast2obj_arg(struct ast_state *state, void* _o)
5209
{
5210
arg_ty o = (arg_ty)_o;
5211
PyObject *result = NULL, *value = NULL;
5212
PyTypeObject *tp;
5213
if (!o) {
5214
Py_RETURN_NONE;
5215
}
5216
if (++state->recursion_depth > state->recursion_limit) {
5217
PyErr_SetString(PyExc_RecursionError,
5218
"maximum recursion depth exceeded during ast construction");
5219
return 0;
5220
}
5221
tp = (PyTypeObject *)state->arg_type;
5222
result = PyType_GenericNew(tp, NULL, NULL);
5223
if (!result) return NULL;
5224
value = ast2obj_identifier(state, o->arg);
5225
if (!value) goto failed;
5226
if (PyObject_SetAttr(result, state->arg, value) == -1)
5227
goto failed;
5228
Py_DECREF(value);
5229
value = ast2obj_expr(state, o->annotation);
5230
if (!value) goto failed;
5231
if (PyObject_SetAttr(result, state->annotation, value) == -1)
5232
goto failed;
5233
Py_DECREF(value);
5234
value = ast2obj_string(state, o->type_comment);
5235
if (!value) goto failed;
5236
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5237
goto failed;
5238
Py_DECREF(value);
5239
value = ast2obj_int(state, o->lineno);
5240
if (!value) goto failed;
5241
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5242
goto failed;
5243
Py_DECREF(value);
5244
value = ast2obj_int(state, o->col_offset);
5245
if (!value) goto failed;
5246
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5247
goto failed;
5248
Py_DECREF(value);
5249
value = ast2obj_int(state, o->end_lineno);
5250
if (!value) goto failed;
5251
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5252
goto failed;
5253
Py_DECREF(value);
5254
value = ast2obj_int(state, o->end_col_offset);
5255
if (!value) goto failed;
5256
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5257
goto failed;
5258
Py_DECREF(value);
5259
state->recursion_depth--;
5260
return result;
5261
failed:
5262
Py_XDECREF(value);
5263
Py_XDECREF(result);
5264
return NULL;
5265
}
5266
5267
PyObject*
5268
ast2obj_keyword(struct ast_state *state, void* _o)
5269
{
5270
keyword_ty o = (keyword_ty)_o;
5271
PyObject *result = NULL, *value = NULL;
5272
PyTypeObject *tp;
5273
if (!o) {
5274
Py_RETURN_NONE;
5275
}
5276
if (++state->recursion_depth > state->recursion_limit) {
5277
PyErr_SetString(PyExc_RecursionError,
5278
"maximum recursion depth exceeded during ast construction");
5279
return 0;
5280
}
5281
tp = (PyTypeObject *)state->keyword_type;
5282
result = PyType_GenericNew(tp, NULL, NULL);
5283
if (!result) return NULL;
5284
value = ast2obj_identifier(state, o->arg);
5285
if (!value) goto failed;
5286
if (PyObject_SetAttr(result, state->arg, value) == -1)
5287
goto failed;
5288
Py_DECREF(value);
5289
value = ast2obj_expr(state, o->value);
5290
if (!value) goto failed;
5291
if (PyObject_SetAttr(result, state->value, value) == -1)
5292
goto failed;
5293
Py_DECREF(value);
5294
value = ast2obj_int(state, o->lineno);
5295
if (!value) goto failed;
5296
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5297
goto failed;
5298
Py_DECREF(value);
5299
value = ast2obj_int(state, o->col_offset);
5300
if (!value) goto failed;
5301
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5302
goto failed;
5303
Py_DECREF(value);
5304
value = ast2obj_int(state, o->end_lineno);
5305
if (!value) goto failed;
5306
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5307
goto failed;
5308
Py_DECREF(value);
5309
value = ast2obj_int(state, o->end_col_offset);
5310
if (!value) goto failed;
5311
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5312
goto failed;
5313
Py_DECREF(value);
5314
state->recursion_depth--;
5315
return result;
5316
failed:
5317
Py_XDECREF(value);
5318
Py_XDECREF(result);
5319
return NULL;
5320
}
5321
5322
PyObject*
5323
ast2obj_alias(struct ast_state *state, void* _o)
5324
{
5325
alias_ty o = (alias_ty)_o;
5326
PyObject *result = NULL, *value = NULL;
5327
PyTypeObject *tp;
5328
if (!o) {
5329
Py_RETURN_NONE;
5330
}
5331
if (++state->recursion_depth > state->recursion_limit) {
5332
PyErr_SetString(PyExc_RecursionError,
5333
"maximum recursion depth exceeded during ast construction");
5334
return 0;
5335
}
5336
tp = (PyTypeObject *)state->alias_type;
5337
result = PyType_GenericNew(tp, NULL, NULL);
5338
if (!result) return NULL;
5339
value = ast2obj_identifier(state, o->name);
5340
if (!value) goto failed;
5341
if (PyObject_SetAttr(result, state->name, value) == -1)
5342
goto failed;
5343
Py_DECREF(value);
5344
value = ast2obj_identifier(state, o->asname);
5345
if (!value) goto failed;
5346
if (PyObject_SetAttr(result, state->asname, value) == -1)
5347
goto failed;
5348
Py_DECREF(value);
5349
value = ast2obj_int(state, o->lineno);
5350
if (!value) goto failed;
5351
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5352
goto failed;
5353
Py_DECREF(value);
5354
value = ast2obj_int(state, o->col_offset);
5355
if (!value) goto failed;
5356
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5357
goto failed;
5358
Py_DECREF(value);
5359
value = ast2obj_int(state, o->end_lineno);
5360
if (!value) goto failed;
5361
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5362
goto failed;
5363
Py_DECREF(value);
5364
value = ast2obj_int(state, o->end_col_offset);
5365
if (!value) goto failed;
5366
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5367
goto failed;
5368
Py_DECREF(value);
5369
state->recursion_depth--;
5370
return result;
5371
failed:
5372
Py_XDECREF(value);
5373
Py_XDECREF(result);
5374
return NULL;
5375
}
5376
5377
PyObject*
5378
ast2obj_withitem(struct ast_state *state, void* _o)
5379
{
5380
withitem_ty o = (withitem_ty)_o;
5381
PyObject *result = NULL, *value = NULL;
5382
PyTypeObject *tp;
5383
if (!o) {
5384
Py_RETURN_NONE;
5385
}
5386
if (++state->recursion_depth > state->recursion_limit) {
5387
PyErr_SetString(PyExc_RecursionError,
5388
"maximum recursion depth exceeded during ast construction");
5389
return 0;
5390
}
5391
tp = (PyTypeObject *)state->withitem_type;
5392
result = PyType_GenericNew(tp, NULL, NULL);
5393
if (!result) return NULL;
5394
value = ast2obj_expr(state, o->context_expr);
5395
if (!value) goto failed;
5396
if (PyObject_SetAttr(result, state->context_expr, value) == -1)
5397
goto failed;
5398
Py_DECREF(value);
5399
value = ast2obj_expr(state, o->optional_vars);
5400
if (!value) goto failed;
5401
if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
5402
goto failed;
5403
Py_DECREF(value);
5404
state->recursion_depth--;
5405
return result;
5406
failed:
5407
Py_XDECREF(value);
5408
Py_XDECREF(result);
5409
return NULL;
5410
}
5411
5412
PyObject*
5413
ast2obj_match_case(struct ast_state *state, void* _o)
5414
{
5415
match_case_ty o = (match_case_ty)_o;
5416
PyObject *result = NULL, *value = NULL;
5417
PyTypeObject *tp;
5418
if (!o) {
5419
Py_RETURN_NONE;
5420
}
5421
if (++state->recursion_depth > state->recursion_limit) {
5422
PyErr_SetString(PyExc_RecursionError,
5423
"maximum recursion depth exceeded during ast construction");
5424
return 0;
5425
}
5426
tp = (PyTypeObject *)state->match_case_type;
5427
result = PyType_GenericNew(tp, NULL, NULL);
5428
if (!result) return NULL;
5429
value = ast2obj_pattern(state, o->pattern);
5430
if (!value) goto failed;
5431
if (PyObject_SetAttr(result, state->pattern, value) == -1)
5432
goto failed;
5433
Py_DECREF(value);
5434
value = ast2obj_expr(state, o->guard);
5435
if (!value) goto failed;
5436
if (PyObject_SetAttr(result, state->guard, value) == -1)
5437
goto failed;
5438
Py_DECREF(value);
5439
value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
5440
if (!value) goto failed;
5441
if (PyObject_SetAttr(result, state->body, value) == -1)
5442
goto failed;
5443
Py_DECREF(value);
5444
state->recursion_depth--;
5445
return result;
5446
failed:
5447
Py_XDECREF(value);
5448
Py_XDECREF(result);
5449
return NULL;
5450
}
5451
5452
PyObject*
5453
ast2obj_pattern(struct ast_state *state, void* _o)
5454
{
5455
pattern_ty o = (pattern_ty)_o;
5456
PyObject *result = NULL, *value = NULL;
5457
PyTypeObject *tp;
5458
if (!o) {
5459
Py_RETURN_NONE;
5460
}
5461
if (++state->recursion_depth > state->recursion_limit) {
5462
PyErr_SetString(PyExc_RecursionError,
5463
"maximum recursion depth exceeded during ast construction");
5464
return 0;
5465
}
5466
switch (o->kind) {
5467
case MatchValue_kind:
5468
tp = (PyTypeObject *)state->MatchValue_type;
5469
result = PyType_GenericNew(tp, NULL, NULL);
5470
if (!result) goto failed;
5471
value = ast2obj_expr(state, o->v.MatchValue.value);
5472
if (!value) goto failed;
5473
if (PyObject_SetAttr(result, state->value, value) == -1)
5474
goto failed;
5475
Py_DECREF(value);
5476
break;
5477
case MatchSingleton_kind:
5478
tp = (PyTypeObject *)state->MatchSingleton_type;
5479
result = PyType_GenericNew(tp, NULL, NULL);
5480
if (!result) goto failed;
5481
value = ast2obj_constant(state, o->v.MatchSingleton.value);
5482
if (!value) goto failed;
5483
if (PyObject_SetAttr(result, state->value, value) == -1)
5484
goto failed;
5485
Py_DECREF(value);
5486
break;
5487
case MatchSequence_kind:
5488
tp = (PyTypeObject *)state->MatchSequence_type;
5489
result = PyType_GenericNew(tp, NULL, NULL);
5490
if (!result) goto failed;
5491
value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
5492
ast2obj_pattern);
5493
if (!value) goto failed;
5494
if (PyObject_SetAttr(result, state->patterns, value) == -1)
5495
goto failed;
5496
Py_DECREF(value);
5497
break;
5498
case MatchMapping_kind:
5499
tp = (PyTypeObject *)state->MatchMapping_type;
5500
result = PyType_GenericNew(tp, NULL, NULL);
5501
if (!result) goto failed;
5502
value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
5503
ast2obj_expr);
5504
if (!value) goto failed;
5505
if (PyObject_SetAttr(result, state->keys, value) == -1)
5506
goto failed;
5507
Py_DECREF(value);
5508
value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
5509
ast2obj_pattern);
5510
if (!value) goto failed;
5511
if (PyObject_SetAttr(result, state->patterns, value) == -1)
5512
goto failed;
5513
Py_DECREF(value);
5514
value = ast2obj_identifier(state, o->v.MatchMapping.rest);
5515
if (!value) goto failed;
5516
if (PyObject_SetAttr(result, state->rest, value) == -1)
5517
goto failed;
5518
Py_DECREF(value);
5519
break;
5520
case MatchClass_kind:
5521
tp = (PyTypeObject *)state->MatchClass_type;
5522
result = PyType_GenericNew(tp, NULL, NULL);
5523
if (!result) goto failed;
5524
value = ast2obj_expr(state, o->v.MatchClass.cls);
5525
if (!value) goto failed;
5526
if (PyObject_SetAttr(result, state->cls, value) == -1)
5527
goto failed;
5528
Py_DECREF(value);
5529
value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
5530
ast2obj_pattern);
5531
if (!value) goto failed;
5532
if (PyObject_SetAttr(result, state->patterns, value) == -1)
5533
goto failed;
5534
Py_DECREF(value);
5535
value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
5536
ast2obj_identifier);
5537
if (!value) goto failed;
5538
if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
5539
goto failed;
5540
Py_DECREF(value);
5541
value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
5542
ast2obj_pattern);
5543
if (!value) goto failed;
5544
if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
5545
goto failed;
5546
Py_DECREF(value);
5547
break;
5548
case MatchStar_kind:
5549
tp = (PyTypeObject *)state->MatchStar_type;
5550
result = PyType_GenericNew(tp, NULL, NULL);
5551
if (!result) goto failed;
5552
value = ast2obj_identifier(state, o->v.MatchStar.name);
5553
if (!value) goto failed;
5554
if (PyObject_SetAttr(result, state->name, value) == -1)
5555
goto failed;
5556
Py_DECREF(value);
5557
break;
5558
case MatchAs_kind:
5559
tp = (PyTypeObject *)state->MatchAs_type;
5560
result = PyType_GenericNew(tp, NULL, NULL);
5561
if (!result) goto failed;
5562
value = ast2obj_pattern(state, o->v.MatchAs.pattern);
5563
if (!value) goto failed;
5564
if (PyObject_SetAttr(result, state->pattern, value) == -1)
5565
goto failed;
5566
Py_DECREF(value);
5567
value = ast2obj_identifier(state, o->v.MatchAs.name);
5568
if (!value) goto failed;
5569
if (PyObject_SetAttr(result, state->name, value) == -1)
5570
goto failed;
5571
Py_DECREF(value);
5572
break;
5573
case MatchOr_kind:
5574
tp = (PyTypeObject *)state->MatchOr_type;
5575
result = PyType_GenericNew(tp, NULL, NULL);
5576
if (!result) goto failed;
5577
value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
5578
ast2obj_pattern);
5579
if (!value) goto failed;
5580
if (PyObject_SetAttr(result, state->patterns, value) == -1)
5581
goto failed;
5582
Py_DECREF(value);
5583
break;
5584
}
5585
value = ast2obj_int(state, o->lineno);
5586
if (!value) goto failed;
5587
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5588
goto failed;
5589
Py_DECREF(value);
5590
value = ast2obj_int(state, o->col_offset);
5591
if (!value) goto failed;
5592
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5593
goto failed;
5594
Py_DECREF(value);
5595
value = ast2obj_int(state, o->end_lineno);
5596
if (!value) goto failed;
5597
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5598
goto failed;
5599
Py_DECREF(value);
5600
value = ast2obj_int(state, o->end_col_offset);
5601
if (!value) goto failed;
5602
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5603
goto failed;
5604
Py_DECREF(value);
5605
state->recursion_depth--;
5606
return result;
5607
failed:
5608
Py_XDECREF(value);
5609
Py_XDECREF(result);
5610
return NULL;
5611
}
5612
5613
PyObject*
5614
ast2obj_type_ignore(struct ast_state *state, void* _o)
5615
{
5616
type_ignore_ty o = (type_ignore_ty)_o;
5617
PyObject *result = NULL, *value = NULL;
5618
PyTypeObject *tp;
5619
if (!o) {
5620
Py_RETURN_NONE;
5621
}
5622
if (++state->recursion_depth > state->recursion_limit) {
5623
PyErr_SetString(PyExc_RecursionError,
5624
"maximum recursion depth exceeded during ast construction");
5625
return 0;
5626
}
5627
switch (o->kind) {
5628
case TypeIgnore_kind:
5629
tp = (PyTypeObject *)state->TypeIgnore_type;
5630
result = PyType_GenericNew(tp, NULL, NULL);
5631
if (!result) goto failed;
5632
value = ast2obj_int(state, o->v.TypeIgnore.lineno);
5633
if (!value) goto failed;
5634
if (PyObject_SetAttr(result, state->lineno, value) == -1)
5635
goto failed;
5636
Py_DECREF(value);
5637
value = ast2obj_string(state, o->v.TypeIgnore.tag);
5638
if (!value) goto failed;
5639
if (PyObject_SetAttr(result, state->tag, value) == -1)
5640
goto failed;
5641
Py_DECREF(value);
5642
break;
5643
}
5644
state->recursion_depth--;
5645
return result;
5646
failed:
5647
Py_XDECREF(value);
5648
Py_XDECREF(result);
5649
return NULL;
5650
}
5651
5652
PyObject*
5653
ast2obj_type_param(struct ast_state *state, void* _o)
5654
{
5655
type_param_ty o = (type_param_ty)_o;
5656
PyObject *result = NULL, *value = NULL;
5657
PyTypeObject *tp;
5658
if (!o) {
5659
Py_RETURN_NONE;
5660
}
5661
if (++state->recursion_depth > state->recursion_limit) {
5662
PyErr_SetString(PyExc_RecursionError,
5663
"maximum recursion depth exceeded during ast construction");
5664
return 0;
5665
}
5666
switch (o->kind) {
5667
case TypeVar_kind:
5668
tp = (PyTypeObject *)state->TypeVar_type;
5669
result = PyType_GenericNew(tp, NULL, NULL);
5670
if (!result) goto failed;
5671
value = ast2obj_identifier(state, o->v.TypeVar.name);
5672
if (!value) goto failed;
5673
if (PyObject_SetAttr(result, state->name, value) == -1)
5674
goto failed;
5675
Py_DECREF(value);
5676
value = ast2obj_expr(state, o->v.TypeVar.bound);
5677
if (!value) goto failed;
5678
if (PyObject_SetAttr(result, state->bound, value) == -1)
5679
goto failed;
5680
Py_DECREF(value);
5681
break;
5682
case ParamSpec_kind:
5683
tp = (PyTypeObject *)state->ParamSpec_type;
5684
result = PyType_GenericNew(tp, NULL, NULL);
5685
if (!result) goto failed;
5686
value = ast2obj_identifier(state, o->v.ParamSpec.name);
5687
if (!value) goto failed;
5688
if (PyObject_SetAttr(result, state->name, value) == -1)
5689
goto failed;
5690
Py_DECREF(value);
5691
break;
5692
case TypeVarTuple_kind:
5693
tp = (PyTypeObject *)state->TypeVarTuple_type;
5694
result = PyType_GenericNew(tp, NULL, NULL);
5695
if (!result) goto failed;
5696
value = ast2obj_identifier(state, o->v.TypeVarTuple.name);
5697
if (!value) goto failed;
5698
if (PyObject_SetAttr(result, state->name, value) == -1)
5699
goto failed;
5700
Py_DECREF(value);
5701
break;
5702
}
5703
value = ast2obj_int(state, o->lineno);
5704
if (!value) goto failed;
5705
if (PyObject_SetAttr(result, state->lineno, value) < 0)
5706
goto failed;
5707
Py_DECREF(value);
5708
value = ast2obj_int(state, o->col_offset);
5709
if (!value) goto failed;
5710
if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5711
goto failed;
5712
Py_DECREF(value);
5713
value = ast2obj_int(state, o->end_lineno);
5714
if (!value) goto failed;
5715
if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5716
goto failed;
5717
Py_DECREF(value);
5718
value = ast2obj_int(state, o->end_col_offset);
5719
if (!value) goto failed;
5720
if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5721
goto failed;
5722
Py_DECREF(value);
5723
state->recursion_depth--;
5724
return result;
5725
failed:
5726
Py_XDECREF(value);
5727
Py_XDECREF(result);
5728
return NULL;
5729
}
5730
5731
5732
int
5733
obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
5734
{
5735
int isinstance;
5736
5737
PyObject *tmp = NULL;
5738
PyObject *tp;
5739
5740
if (obj == Py_None) {
5741
*out = NULL;
5742
return 0;
5743
}
5744
tp = state->Module_type;
5745
isinstance = PyObject_IsInstance(obj, tp);
5746
if (isinstance == -1) {
5747
return 1;
5748
}
5749
if (isinstance) {
5750
asdl_stmt_seq* body;
5751
asdl_type_ignore_seq* type_ignores;
5752
5753
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5754
return 1;
5755
}
5756
if (tmp == NULL) {
5757
tmp = PyList_New(0);
5758
if (tmp == NULL) {
5759
return 1;
5760
}
5761
}
5762
{
5763
int res;
5764
Py_ssize_t len;
5765
Py_ssize_t i;
5766
if (!PyList_Check(tmp)) {
5767
PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5768
goto failed;
5769
}
5770
len = PyList_GET_SIZE(tmp);
5771
body = _Py_asdl_stmt_seq_new(len, arena);
5772
if (body == NULL) goto failed;
5773
for (i = 0; i < len; i++) {
5774
stmt_ty val;
5775
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
5776
if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5777
goto failed;
5778
}
5779
res = obj2ast_stmt(state, tmp2, &val, arena);
5780
_Py_LeaveRecursiveCall();
5781
Py_DECREF(tmp2);
5782
if (res != 0) goto failed;
5783
if (len != PyList_GET_SIZE(tmp)) {
5784
PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5785
goto failed;
5786
}
5787
asdl_seq_SET(body, i, val);
5788
}
5789
Py_CLEAR(tmp);
5790
}
5791
if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
5792
return 1;
5793
}
5794
if (tmp == NULL) {
5795
tmp = PyList_New(0);
5796
if (tmp == NULL) {
5797
return 1;
5798
}
5799
}
5800
{
5801
int res;
5802
Py_ssize_t len;
5803
Py_ssize_t i;
5804
if (!PyList_Check(tmp)) {
5805
PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5806
goto failed;
5807
}
5808
len = PyList_GET_SIZE(tmp);
5809
type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
5810
if (type_ignores == NULL) goto failed;
5811
for (i = 0; i < len; i++) {
5812
type_ignore_ty val;
5813
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
5814
if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5815
goto failed;
5816
}
5817
res = obj2ast_type_ignore(state, tmp2, &val, arena);
5818
_Py_LeaveRecursiveCall();
5819
Py_DECREF(tmp2);
5820
if (res != 0) goto failed;
5821
if (len != PyList_GET_SIZE(tmp)) {
5822
PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5823
goto failed;
5824
}
5825
asdl_seq_SET(type_ignores, i, val);
5826
}
5827
Py_CLEAR(tmp);
5828
}
5829
*out = _PyAST_Module(body, type_ignores, arena);
5830
if (*out == NULL) goto failed;
5831
return 0;
5832
}
5833
tp = state->Interactive_type;
5834
isinstance = PyObject_IsInstance(obj, tp);
5835
if (isinstance == -1) {
5836
return 1;
5837
}
5838
if (isinstance) {
5839
asdl_stmt_seq* body;
5840
5841
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5842
return 1;
5843
}
5844
if (tmp == NULL) {
5845
tmp = PyList_New(0);
5846
if (tmp == NULL) {
5847
return 1;
5848
}
5849
}
5850
{
5851
int res;
5852
Py_ssize_t len;
5853
Py_ssize_t i;
5854
if (!PyList_Check(tmp)) {
5855
PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5856
goto failed;
5857
}
5858
len = PyList_GET_SIZE(tmp);
5859
body = _Py_asdl_stmt_seq_new(len, arena);
5860
if (body == NULL) goto failed;
5861
for (i = 0; i < len; i++) {
5862
stmt_ty val;
5863
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
5864
if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
5865
goto failed;
5866
}
5867
res = obj2ast_stmt(state, tmp2, &val, arena);
5868
_Py_LeaveRecursiveCall();
5869
Py_DECREF(tmp2);
5870
if (res != 0) goto failed;
5871
if (len != PyList_GET_SIZE(tmp)) {
5872
PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5873
goto failed;
5874
}
5875
asdl_seq_SET(body, i, val);
5876
}
5877
Py_CLEAR(tmp);
5878
}
5879
*out = _PyAST_Interactive(body, arena);
5880
if (*out == NULL) goto failed;
5881
return 0;
5882
}
5883
tp = state->Expression_type;
5884
isinstance = PyObject_IsInstance(obj, tp);
5885
if (isinstance == -1) {
5886
return 1;
5887
}
5888
if (isinstance) {
5889
expr_ty body;
5890
5891
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5892
return 1;
5893
}
5894
if (tmp == NULL) {
5895
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5896
return 1;
5897
}
5898
else {
5899
int res;
5900
if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
5901
goto failed;
5902
}
5903
res = obj2ast_expr(state, tmp, &body, arena);
5904
_Py_LeaveRecursiveCall();
5905
if (res != 0) goto failed;
5906
Py_CLEAR(tmp);
5907
}
5908
*out = _PyAST_Expression(body, arena);
5909
if (*out == NULL) goto failed;
5910
return 0;
5911
}
5912
tp = state->FunctionType_type;
5913
isinstance = PyObject_IsInstance(obj, tp);
5914
if (isinstance == -1) {
5915
return 1;
5916
}
5917
if (isinstance) {
5918
asdl_expr_seq* argtypes;
5919
expr_ty returns;
5920
5921
if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
5922
return 1;
5923
}
5924
if (tmp == NULL) {
5925
tmp = PyList_New(0);
5926
if (tmp == NULL) {
5927
return 1;
5928
}
5929
}
5930
{
5931
int res;
5932
Py_ssize_t len;
5933
Py_ssize_t i;
5934
if (!PyList_Check(tmp)) {
5935
PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5936
goto failed;
5937
}
5938
len = PyList_GET_SIZE(tmp);
5939
argtypes = _Py_asdl_expr_seq_new(len, arena);
5940
if (argtypes == NULL) goto failed;
5941
for (i = 0; i < len; i++) {
5942
expr_ty val;
5943
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
5944
if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5945
goto failed;
5946
}
5947
res = obj2ast_expr(state, tmp2, &val, arena);
5948
_Py_LeaveRecursiveCall();
5949
Py_DECREF(tmp2);
5950
if (res != 0) goto failed;
5951
if (len != PyList_GET_SIZE(tmp)) {
5952
PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5953
goto failed;
5954
}
5955
asdl_seq_SET(argtypes, i, val);
5956
}
5957
Py_CLEAR(tmp);
5958
}
5959
if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5960
return 1;
5961
}
5962
if (tmp == NULL) {
5963
PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5964
return 1;
5965
}
5966
else {
5967
int res;
5968
if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5969
goto failed;
5970
}
5971
res = obj2ast_expr(state, tmp, &returns, arena);
5972
_Py_LeaveRecursiveCall();
5973
if (res != 0) goto failed;
5974
Py_CLEAR(tmp);
5975
}
5976
*out = _PyAST_FunctionType(argtypes, returns, arena);
5977
if (*out == NULL) goto failed;
5978
return 0;
5979
}
5980
5981
PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5982
failed:
5983
Py_XDECREF(tmp);
5984
return 1;
5985
}
5986
5987
int
5988
obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
5989
arena)
5990
{
5991
int isinstance;
5992
5993
PyObject *tmp = NULL;
5994
PyObject *tp;
5995
int lineno;
5996
int col_offset;
5997
int end_lineno;
5998
int end_col_offset;
5999
6000
if (obj == Py_None) {
6001
*out = NULL;
6002
return 0;
6003
}
6004
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
6005
return 1;
6006
}
6007
if (tmp == NULL) {
6008
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
6009
return 1;
6010
}
6011
else {
6012
int res;
6013
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
6014
goto failed;
6015
}
6016
res = obj2ast_int(state, tmp, &lineno, arena);
6017
_Py_LeaveRecursiveCall();
6018
if (res != 0) goto failed;
6019
Py_CLEAR(tmp);
6020
}
6021
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
6022
return 1;
6023
}
6024
if (tmp == NULL) {
6025
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
6026
return 1;
6027
}
6028
else {
6029
int res;
6030
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
6031
goto failed;
6032
}
6033
res = obj2ast_int(state, tmp, &col_offset, arena);
6034
_Py_LeaveRecursiveCall();
6035
if (res != 0) goto failed;
6036
Py_CLEAR(tmp);
6037
}
6038
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
6039
return 1;
6040
}
6041
if (tmp == NULL || tmp == Py_None) {
6042
Py_CLEAR(tmp);
6043
end_lineno = lineno;
6044
}
6045
else {
6046
int res;
6047
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
6048
goto failed;
6049
}
6050
res = obj2ast_int(state, tmp, &end_lineno, arena);
6051
_Py_LeaveRecursiveCall();
6052
if (res != 0) goto failed;
6053
Py_CLEAR(tmp);
6054
}
6055
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
6056
return 1;
6057
}
6058
if (tmp == NULL || tmp == Py_None) {
6059
Py_CLEAR(tmp);
6060
end_col_offset = col_offset;
6061
}
6062
else {
6063
int res;
6064
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
6065
goto failed;
6066
}
6067
res = obj2ast_int(state, tmp, &end_col_offset, arena);
6068
_Py_LeaveRecursiveCall();
6069
if (res != 0) goto failed;
6070
Py_CLEAR(tmp);
6071
}
6072
tp = state->FunctionDef_type;
6073
isinstance = PyObject_IsInstance(obj, tp);
6074
if (isinstance == -1) {
6075
return 1;
6076
}
6077
if (isinstance) {
6078
identifier name;
6079
arguments_ty args;
6080
asdl_stmt_seq* body;
6081
asdl_expr_seq* decorator_list;
6082
expr_ty returns;
6083
string type_comment;
6084
asdl_type_param_seq* type_params;
6085
6086
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6087
return 1;
6088
}
6089
if (tmp == NULL) {
6090
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
6091
return 1;
6092
}
6093
else {
6094
int res;
6095
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6096
goto failed;
6097
}
6098
res = obj2ast_identifier(state, tmp, &name, arena);
6099
_Py_LeaveRecursiveCall();
6100
if (res != 0) goto failed;
6101
Py_CLEAR(tmp);
6102
}
6103
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
6104
return 1;
6105
}
6106
if (tmp == NULL) {
6107
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
6108
return 1;
6109
}
6110
else {
6111
int res;
6112
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6113
goto failed;
6114
}
6115
res = obj2ast_arguments(state, tmp, &args, arena);
6116
_Py_LeaveRecursiveCall();
6117
if (res != 0) goto failed;
6118
Py_CLEAR(tmp);
6119
}
6120
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6121
return 1;
6122
}
6123
if (tmp == NULL) {
6124
tmp = PyList_New(0);
6125
if (tmp == NULL) {
6126
return 1;
6127
}
6128
}
6129
{
6130
int res;
6131
Py_ssize_t len;
6132
Py_ssize_t i;
6133
if (!PyList_Check(tmp)) {
6134
PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6135
goto failed;
6136
}
6137
len = PyList_GET_SIZE(tmp);
6138
body = _Py_asdl_stmt_seq_new(len, arena);
6139
if (body == NULL) goto failed;
6140
for (i = 0; i < len; i++) {
6141
stmt_ty val;
6142
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6143
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6144
goto failed;
6145
}
6146
res = obj2ast_stmt(state, tmp2, &val, arena);
6147
_Py_LeaveRecursiveCall();
6148
Py_DECREF(tmp2);
6149
if (res != 0) goto failed;
6150
if (len != PyList_GET_SIZE(tmp)) {
6151
PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
6152
goto failed;
6153
}
6154
asdl_seq_SET(body, i, val);
6155
}
6156
Py_CLEAR(tmp);
6157
}
6158
if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6159
return 1;
6160
}
6161
if (tmp == NULL) {
6162
tmp = PyList_New(0);
6163
if (tmp == NULL) {
6164
return 1;
6165
}
6166
}
6167
{
6168
int res;
6169
Py_ssize_t len;
6170
Py_ssize_t i;
6171
if (!PyList_Check(tmp)) {
6172
PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6173
goto failed;
6174
}
6175
len = PyList_GET_SIZE(tmp);
6176
decorator_list = _Py_asdl_expr_seq_new(len, arena);
6177
if (decorator_list == NULL) goto failed;
6178
for (i = 0; i < len; i++) {
6179
expr_ty val;
6180
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6181
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6182
goto failed;
6183
}
6184
res = obj2ast_expr(state, tmp2, &val, arena);
6185
_Py_LeaveRecursiveCall();
6186
Py_DECREF(tmp2);
6187
if (res != 0) goto failed;
6188
if (len != PyList_GET_SIZE(tmp)) {
6189
PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
6190
goto failed;
6191
}
6192
asdl_seq_SET(decorator_list, i, val);
6193
}
6194
Py_CLEAR(tmp);
6195
}
6196
if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
6197
return 1;
6198
}
6199
if (tmp == NULL || tmp == Py_None) {
6200
Py_CLEAR(tmp);
6201
returns = NULL;
6202
}
6203
else {
6204
int res;
6205
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6206
goto failed;
6207
}
6208
res = obj2ast_expr(state, tmp, &returns, arena);
6209
_Py_LeaveRecursiveCall();
6210
if (res != 0) goto failed;
6211
Py_CLEAR(tmp);
6212
}
6213
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6214
return 1;
6215
}
6216
if (tmp == NULL || tmp == Py_None) {
6217
Py_CLEAR(tmp);
6218
type_comment = NULL;
6219
}
6220
else {
6221
int res;
6222
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6223
goto failed;
6224
}
6225
res = obj2ast_string(state, tmp, &type_comment, arena);
6226
_Py_LeaveRecursiveCall();
6227
if (res != 0) goto failed;
6228
Py_CLEAR(tmp);
6229
}
6230
if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
6231
return 1;
6232
}
6233
if (tmp == NULL) {
6234
tmp = PyList_New(0);
6235
if (tmp == NULL) {
6236
return 1;
6237
}
6238
}
6239
{
6240
int res;
6241
Py_ssize_t len;
6242
Py_ssize_t i;
6243
if (!PyList_Check(tmp)) {
6244
PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6245
goto failed;
6246
}
6247
len = PyList_GET_SIZE(tmp);
6248
type_params = _Py_asdl_type_param_seq_new(len, arena);
6249
if (type_params == NULL) goto failed;
6250
for (i = 0; i < len; i++) {
6251
type_param_ty val;
6252
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6253
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
6254
goto failed;
6255
}
6256
res = obj2ast_type_param(state, tmp2, &val, arena);
6257
_Py_LeaveRecursiveCall();
6258
Py_DECREF(tmp2);
6259
if (res != 0) goto failed;
6260
if (len != PyList_GET_SIZE(tmp)) {
6261
PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
6262
goto failed;
6263
}
6264
asdl_seq_SET(type_params, i, val);
6265
}
6266
Py_CLEAR(tmp);
6267
}
6268
*out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
6269
type_comment, type_params, lineno,
6270
col_offset, end_lineno, end_col_offset,
6271
arena);
6272
if (*out == NULL) goto failed;
6273
return 0;
6274
}
6275
tp = state->AsyncFunctionDef_type;
6276
isinstance = PyObject_IsInstance(obj, tp);
6277
if (isinstance == -1) {
6278
return 1;
6279
}
6280
if (isinstance) {
6281
identifier name;
6282
arguments_ty args;
6283
asdl_stmt_seq* body;
6284
asdl_expr_seq* decorator_list;
6285
expr_ty returns;
6286
string type_comment;
6287
asdl_type_param_seq* type_params;
6288
6289
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6290
return 1;
6291
}
6292
if (tmp == NULL) {
6293
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
6294
return 1;
6295
}
6296
else {
6297
int res;
6298
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6299
goto failed;
6300
}
6301
res = obj2ast_identifier(state, tmp, &name, arena);
6302
_Py_LeaveRecursiveCall();
6303
if (res != 0) goto failed;
6304
Py_CLEAR(tmp);
6305
}
6306
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
6307
return 1;
6308
}
6309
if (tmp == NULL) {
6310
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
6311
return 1;
6312
}
6313
else {
6314
int res;
6315
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6316
goto failed;
6317
}
6318
res = obj2ast_arguments(state, tmp, &args, arena);
6319
_Py_LeaveRecursiveCall();
6320
if (res != 0) goto failed;
6321
Py_CLEAR(tmp);
6322
}
6323
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6324
return 1;
6325
}
6326
if (tmp == NULL) {
6327
tmp = PyList_New(0);
6328
if (tmp == NULL) {
6329
return 1;
6330
}
6331
}
6332
{
6333
int res;
6334
Py_ssize_t len;
6335
Py_ssize_t i;
6336
if (!PyList_Check(tmp)) {
6337
PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6338
goto failed;
6339
}
6340
len = PyList_GET_SIZE(tmp);
6341
body = _Py_asdl_stmt_seq_new(len, arena);
6342
if (body == NULL) goto failed;
6343
for (i = 0; i < len; i++) {
6344
stmt_ty val;
6345
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6346
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6347
goto failed;
6348
}
6349
res = obj2ast_stmt(state, tmp2, &val, arena);
6350
_Py_LeaveRecursiveCall();
6351
Py_DECREF(tmp2);
6352
if (res != 0) goto failed;
6353
if (len != PyList_GET_SIZE(tmp)) {
6354
PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
6355
goto failed;
6356
}
6357
asdl_seq_SET(body, i, val);
6358
}
6359
Py_CLEAR(tmp);
6360
}
6361
if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6362
return 1;
6363
}
6364
if (tmp == NULL) {
6365
tmp = PyList_New(0);
6366
if (tmp == NULL) {
6367
return 1;
6368
}
6369
}
6370
{
6371
int res;
6372
Py_ssize_t len;
6373
Py_ssize_t i;
6374
if (!PyList_Check(tmp)) {
6375
PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6376
goto failed;
6377
}
6378
len = PyList_GET_SIZE(tmp);
6379
decorator_list = _Py_asdl_expr_seq_new(len, arena);
6380
if (decorator_list == NULL) goto failed;
6381
for (i = 0; i < len; i++) {
6382
expr_ty val;
6383
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6384
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6385
goto failed;
6386
}
6387
res = obj2ast_expr(state, tmp2, &val, arena);
6388
_Py_LeaveRecursiveCall();
6389
Py_DECREF(tmp2);
6390
if (res != 0) goto failed;
6391
if (len != PyList_GET_SIZE(tmp)) {
6392
PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
6393
goto failed;
6394
}
6395
asdl_seq_SET(decorator_list, i, val);
6396
}
6397
Py_CLEAR(tmp);
6398
}
6399
if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
6400
return 1;
6401
}
6402
if (tmp == NULL || tmp == Py_None) {
6403
Py_CLEAR(tmp);
6404
returns = NULL;
6405
}
6406
else {
6407
int res;
6408
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6409
goto failed;
6410
}
6411
res = obj2ast_expr(state, tmp, &returns, arena);
6412
_Py_LeaveRecursiveCall();
6413
if (res != 0) goto failed;
6414
Py_CLEAR(tmp);
6415
}
6416
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6417
return 1;
6418
}
6419
if (tmp == NULL || tmp == Py_None) {
6420
Py_CLEAR(tmp);
6421
type_comment = NULL;
6422
}
6423
else {
6424
int res;
6425
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6426
goto failed;
6427
}
6428
res = obj2ast_string(state, tmp, &type_comment, arena);
6429
_Py_LeaveRecursiveCall();
6430
if (res != 0) goto failed;
6431
Py_CLEAR(tmp);
6432
}
6433
if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
6434
return 1;
6435
}
6436
if (tmp == NULL) {
6437
tmp = PyList_New(0);
6438
if (tmp == NULL) {
6439
return 1;
6440
}
6441
}
6442
{
6443
int res;
6444
Py_ssize_t len;
6445
Py_ssize_t i;
6446
if (!PyList_Check(tmp)) {
6447
PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6448
goto failed;
6449
}
6450
len = PyList_GET_SIZE(tmp);
6451
type_params = _Py_asdl_type_param_seq_new(len, arena);
6452
if (type_params == NULL) goto failed;
6453
for (i = 0; i < len; i++) {
6454
type_param_ty val;
6455
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6456
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6457
goto failed;
6458
}
6459
res = obj2ast_type_param(state, tmp2, &val, arena);
6460
_Py_LeaveRecursiveCall();
6461
Py_DECREF(tmp2);
6462
if (res != 0) goto failed;
6463
if (len != PyList_GET_SIZE(tmp)) {
6464
PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
6465
goto failed;
6466
}
6467
asdl_seq_SET(type_params, i, val);
6468
}
6469
Py_CLEAR(tmp);
6470
}
6471
*out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
6472
returns, type_comment, type_params,
6473
lineno, col_offset, end_lineno,
6474
end_col_offset, arena);
6475
if (*out == NULL) goto failed;
6476
return 0;
6477
}
6478
tp = state->ClassDef_type;
6479
isinstance = PyObject_IsInstance(obj, tp);
6480
if (isinstance == -1) {
6481
return 1;
6482
}
6483
if (isinstance) {
6484
identifier name;
6485
asdl_expr_seq* bases;
6486
asdl_keyword_seq* keywords;
6487
asdl_stmt_seq* body;
6488
asdl_expr_seq* decorator_list;
6489
asdl_type_param_seq* type_params;
6490
6491
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6492
return 1;
6493
}
6494
if (tmp == NULL) {
6495
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
6496
return 1;
6497
}
6498
else {
6499
int res;
6500
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6501
goto failed;
6502
}
6503
res = obj2ast_identifier(state, tmp, &name, arena);
6504
_Py_LeaveRecursiveCall();
6505
if (res != 0) goto failed;
6506
Py_CLEAR(tmp);
6507
}
6508
if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
6509
return 1;
6510
}
6511
if (tmp == NULL) {
6512
tmp = PyList_New(0);
6513
if (tmp == NULL) {
6514
return 1;
6515
}
6516
}
6517
{
6518
int res;
6519
Py_ssize_t len;
6520
Py_ssize_t i;
6521
if (!PyList_Check(tmp)) {
6522
PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6523
goto failed;
6524
}
6525
len = PyList_GET_SIZE(tmp);
6526
bases = _Py_asdl_expr_seq_new(len, arena);
6527
if (bases == NULL) goto failed;
6528
for (i = 0; i < len; i++) {
6529
expr_ty val;
6530
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6531
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6532
goto failed;
6533
}
6534
res = obj2ast_expr(state, tmp2, &val, arena);
6535
_Py_LeaveRecursiveCall();
6536
Py_DECREF(tmp2);
6537
if (res != 0) goto failed;
6538
if (len != PyList_GET_SIZE(tmp)) {
6539
PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
6540
goto failed;
6541
}
6542
asdl_seq_SET(bases, i, val);
6543
}
6544
Py_CLEAR(tmp);
6545
}
6546
if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
6547
return 1;
6548
}
6549
if (tmp == NULL) {
6550
tmp = PyList_New(0);
6551
if (tmp == NULL) {
6552
return 1;
6553
}
6554
}
6555
{
6556
int res;
6557
Py_ssize_t len;
6558
Py_ssize_t i;
6559
if (!PyList_Check(tmp)) {
6560
PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6561
goto failed;
6562
}
6563
len = PyList_GET_SIZE(tmp);
6564
keywords = _Py_asdl_keyword_seq_new(len, arena);
6565
if (keywords == NULL) goto failed;
6566
for (i = 0; i < len; i++) {
6567
keyword_ty val;
6568
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6569
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6570
goto failed;
6571
}
6572
res = obj2ast_keyword(state, tmp2, &val, arena);
6573
_Py_LeaveRecursiveCall();
6574
Py_DECREF(tmp2);
6575
if (res != 0) goto failed;
6576
if (len != PyList_GET_SIZE(tmp)) {
6577
PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
6578
goto failed;
6579
}
6580
asdl_seq_SET(keywords, i, val);
6581
}
6582
Py_CLEAR(tmp);
6583
}
6584
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6585
return 1;
6586
}
6587
if (tmp == NULL) {
6588
tmp = PyList_New(0);
6589
if (tmp == NULL) {
6590
return 1;
6591
}
6592
}
6593
{
6594
int res;
6595
Py_ssize_t len;
6596
Py_ssize_t i;
6597
if (!PyList_Check(tmp)) {
6598
PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6599
goto failed;
6600
}
6601
len = PyList_GET_SIZE(tmp);
6602
body = _Py_asdl_stmt_seq_new(len, arena);
6603
if (body == NULL) goto failed;
6604
for (i = 0; i < len; i++) {
6605
stmt_ty val;
6606
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6607
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6608
goto failed;
6609
}
6610
res = obj2ast_stmt(state, tmp2, &val, arena);
6611
_Py_LeaveRecursiveCall();
6612
Py_DECREF(tmp2);
6613
if (res != 0) goto failed;
6614
if (len != PyList_GET_SIZE(tmp)) {
6615
PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
6616
goto failed;
6617
}
6618
asdl_seq_SET(body, i, val);
6619
}
6620
Py_CLEAR(tmp);
6621
}
6622
if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6623
return 1;
6624
}
6625
if (tmp == NULL) {
6626
tmp = PyList_New(0);
6627
if (tmp == NULL) {
6628
return 1;
6629
}
6630
}
6631
{
6632
int res;
6633
Py_ssize_t len;
6634
Py_ssize_t i;
6635
if (!PyList_Check(tmp)) {
6636
PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6637
goto failed;
6638
}
6639
len = PyList_GET_SIZE(tmp);
6640
decorator_list = _Py_asdl_expr_seq_new(len, arena);
6641
if (decorator_list == NULL) goto failed;
6642
for (i = 0; i < len; i++) {
6643
expr_ty val;
6644
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6645
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6646
goto failed;
6647
}
6648
res = obj2ast_expr(state, tmp2, &val, arena);
6649
_Py_LeaveRecursiveCall();
6650
Py_DECREF(tmp2);
6651
if (res != 0) goto failed;
6652
if (len != PyList_GET_SIZE(tmp)) {
6653
PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
6654
goto failed;
6655
}
6656
asdl_seq_SET(decorator_list, i, val);
6657
}
6658
Py_CLEAR(tmp);
6659
}
6660
if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
6661
return 1;
6662
}
6663
if (tmp == NULL) {
6664
tmp = PyList_New(0);
6665
if (tmp == NULL) {
6666
return 1;
6667
}
6668
}
6669
{
6670
int res;
6671
Py_ssize_t len;
6672
Py_ssize_t i;
6673
if (!PyList_Check(tmp)) {
6674
PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6675
goto failed;
6676
}
6677
len = PyList_GET_SIZE(tmp);
6678
type_params = _Py_asdl_type_param_seq_new(len, arena);
6679
if (type_params == NULL) goto failed;
6680
for (i = 0; i < len; i++) {
6681
type_param_ty val;
6682
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6683
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6684
goto failed;
6685
}
6686
res = obj2ast_type_param(state, tmp2, &val, arena);
6687
_Py_LeaveRecursiveCall();
6688
Py_DECREF(tmp2);
6689
if (res != 0) goto failed;
6690
if (len != PyList_GET_SIZE(tmp)) {
6691
PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
6692
goto failed;
6693
}
6694
asdl_seq_SET(type_params, i, val);
6695
}
6696
Py_CLEAR(tmp);
6697
}
6698
*out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
6699
type_params, lineno, col_offset, end_lineno,
6700
end_col_offset, arena);
6701
if (*out == NULL) goto failed;
6702
return 0;
6703
}
6704
tp = state->Return_type;
6705
isinstance = PyObject_IsInstance(obj, tp);
6706
if (isinstance == -1) {
6707
return 1;
6708
}
6709
if (isinstance) {
6710
expr_ty value;
6711
6712
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6713
return 1;
6714
}
6715
if (tmp == NULL || tmp == Py_None) {
6716
Py_CLEAR(tmp);
6717
value = NULL;
6718
}
6719
else {
6720
int res;
6721
if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
6722
goto failed;
6723
}
6724
res = obj2ast_expr(state, tmp, &value, arena);
6725
_Py_LeaveRecursiveCall();
6726
if (res != 0) goto failed;
6727
Py_CLEAR(tmp);
6728
}
6729
*out = _PyAST_Return(value, lineno, col_offset, end_lineno,
6730
end_col_offset, arena);
6731
if (*out == NULL) goto failed;
6732
return 0;
6733
}
6734
tp = state->Delete_type;
6735
isinstance = PyObject_IsInstance(obj, tp);
6736
if (isinstance == -1) {
6737
return 1;
6738
}
6739
if (isinstance) {
6740
asdl_expr_seq* targets;
6741
6742
if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6743
return 1;
6744
}
6745
if (tmp == NULL) {
6746
tmp = PyList_New(0);
6747
if (tmp == NULL) {
6748
return 1;
6749
}
6750
}
6751
{
6752
int res;
6753
Py_ssize_t len;
6754
Py_ssize_t i;
6755
if (!PyList_Check(tmp)) {
6756
PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6757
goto failed;
6758
}
6759
len = PyList_GET_SIZE(tmp);
6760
targets = _Py_asdl_expr_seq_new(len, arena);
6761
if (targets == NULL) goto failed;
6762
for (i = 0; i < len; i++) {
6763
expr_ty val;
6764
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6765
if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
6766
goto failed;
6767
}
6768
res = obj2ast_expr(state, tmp2, &val, arena);
6769
_Py_LeaveRecursiveCall();
6770
Py_DECREF(tmp2);
6771
if (res != 0) goto failed;
6772
if (len != PyList_GET_SIZE(tmp)) {
6773
PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
6774
goto failed;
6775
}
6776
asdl_seq_SET(targets, i, val);
6777
}
6778
Py_CLEAR(tmp);
6779
}
6780
*out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
6781
end_col_offset, arena);
6782
if (*out == NULL) goto failed;
6783
return 0;
6784
}
6785
tp = state->Assign_type;
6786
isinstance = PyObject_IsInstance(obj, tp);
6787
if (isinstance == -1) {
6788
return 1;
6789
}
6790
if (isinstance) {
6791
asdl_expr_seq* targets;
6792
expr_ty value;
6793
string type_comment;
6794
6795
if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6796
return 1;
6797
}
6798
if (tmp == NULL) {
6799
tmp = PyList_New(0);
6800
if (tmp == NULL) {
6801
return 1;
6802
}
6803
}
6804
{
6805
int res;
6806
Py_ssize_t len;
6807
Py_ssize_t i;
6808
if (!PyList_Check(tmp)) {
6809
PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6810
goto failed;
6811
}
6812
len = PyList_GET_SIZE(tmp);
6813
targets = _Py_asdl_expr_seq_new(len, arena);
6814
if (targets == NULL) goto failed;
6815
for (i = 0; i < len; i++) {
6816
expr_ty val;
6817
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6818
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6819
goto failed;
6820
}
6821
res = obj2ast_expr(state, tmp2, &val, arena);
6822
_Py_LeaveRecursiveCall();
6823
Py_DECREF(tmp2);
6824
if (res != 0) goto failed;
6825
if (len != PyList_GET_SIZE(tmp)) {
6826
PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
6827
goto failed;
6828
}
6829
asdl_seq_SET(targets, i, val);
6830
}
6831
Py_CLEAR(tmp);
6832
}
6833
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6834
return 1;
6835
}
6836
if (tmp == NULL) {
6837
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
6838
return 1;
6839
}
6840
else {
6841
int res;
6842
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6843
goto failed;
6844
}
6845
res = obj2ast_expr(state, tmp, &value, arena);
6846
_Py_LeaveRecursiveCall();
6847
if (res != 0) goto failed;
6848
Py_CLEAR(tmp);
6849
}
6850
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6851
return 1;
6852
}
6853
if (tmp == NULL || tmp == Py_None) {
6854
Py_CLEAR(tmp);
6855
type_comment = NULL;
6856
}
6857
else {
6858
int res;
6859
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6860
goto failed;
6861
}
6862
res = obj2ast_string(state, tmp, &type_comment, arena);
6863
_Py_LeaveRecursiveCall();
6864
if (res != 0) goto failed;
6865
Py_CLEAR(tmp);
6866
}
6867
*out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
6868
end_lineno, end_col_offset, arena);
6869
if (*out == NULL) goto failed;
6870
return 0;
6871
}
6872
tp = state->TypeAlias_type;
6873
isinstance = PyObject_IsInstance(obj, tp);
6874
if (isinstance == -1) {
6875
return 1;
6876
}
6877
if (isinstance) {
6878
expr_ty name;
6879
asdl_type_param_seq* type_params;
6880
expr_ty value;
6881
6882
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6883
return 1;
6884
}
6885
if (tmp == NULL) {
6886
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
6887
return 1;
6888
}
6889
else {
6890
int res;
6891
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
6892
goto failed;
6893
}
6894
res = obj2ast_expr(state, tmp, &name, arena);
6895
_Py_LeaveRecursiveCall();
6896
if (res != 0) goto failed;
6897
Py_CLEAR(tmp);
6898
}
6899
if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
6900
return 1;
6901
}
6902
if (tmp == NULL) {
6903
tmp = PyList_New(0);
6904
if (tmp == NULL) {
6905
return 1;
6906
}
6907
}
6908
{
6909
int res;
6910
Py_ssize_t len;
6911
Py_ssize_t i;
6912
if (!PyList_Check(tmp)) {
6913
PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6914
goto failed;
6915
}
6916
len = PyList_GET_SIZE(tmp);
6917
type_params = _Py_asdl_type_param_seq_new(len, arena);
6918
if (type_params == NULL) goto failed;
6919
for (i = 0; i < len; i++) {
6920
type_param_ty val;
6921
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
6922
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
6923
goto failed;
6924
}
6925
res = obj2ast_type_param(state, tmp2, &val, arena);
6926
_Py_LeaveRecursiveCall();
6927
Py_DECREF(tmp2);
6928
if (res != 0) goto failed;
6929
if (len != PyList_GET_SIZE(tmp)) {
6930
PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
6931
goto failed;
6932
}
6933
asdl_seq_SET(type_params, i, val);
6934
}
6935
Py_CLEAR(tmp);
6936
}
6937
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6938
return 1;
6939
}
6940
if (tmp == NULL) {
6941
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
6942
return 1;
6943
}
6944
else {
6945
int res;
6946
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
6947
goto failed;
6948
}
6949
res = obj2ast_expr(state, tmp, &value, arena);
6950
_Py_LeaveRecursiveCall();
6951
if (res != 0) goto failed;
6952
Py_CLEAR(tmp);
6953
}
6954
*out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
6955
end_lineno, end_col_offset, arena);
6956
if (*out == NULL) goto failed;
6957
return 0;
6958
}
6959
tp = state->AugAssign_type;
6960
isinstance = PyObject_IsInstance(obj, tp);
6961
if (isinstance == -1) {
6962
return 1;
6963
}
6964
if (isinstance) {
6965
expr_ty target;
6966
operator_ty op;
6967
expr_ty value;
6968
6969
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6970
return 1;
6971
}
6972
if (tmp == NULL) {
6973
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6974
return 1;
6975
}
6976
else {
6977
int res;
6978
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6979
goto failed;
6980
}
6981
res = obj2ast_expr(state, tmp, &target, arena);
6982
_Py_LeaveRecursiveCall();
6983
if (res != 0) goto failed;
6984
Py_CLEAR(tmp);
6985
}
6986
if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
6987
return 1;
6988
}
6989
if (tmp == NULL) {
6990
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6991
return 1;
6992
}
6993
else {
6994
int res;
6995
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6996
goto failed;
6997
}
6998
res = obj2ast_operator(state, tmp, &op, arena);
6999
_Py_LeaveRecursiveCall();
7000
if (res != 0) goto failed;
7001
Py_CLEAR(tmp);
7002
}
7003
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
7004
return 1;
7005
}
7006
if (tmp == NULL) {
7007
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
7008
return 1;
7009
}
7010
else {
7011
int res;
7012
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
7013
goto failed;
7014
}
7015
res = obj2ast_expr(state, tmp, &value, arena);
7016
_Py_LeaveRecursiveCall();
7017
if (res != 0) goto failed;
7018
Py_CLEAR(tmp);
7019
}
7020
*out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
7021
end_lineno, end_col_offset, arena);
7022
if (*out == NULL) goto failed;
7023
return 0;
7024
}
7025
tp = state->AnnAssign_type;
7026
isinstance = PyObject_IsInstance(obj, tp);
7027
if (isinstance == -1) {
7028
return 1;
7029
}
7030
if (isinstance) {
7031
expr_ty target;
7032
expr_ty annotation;
7033
expr_ty value;
7034
int simple;
7035
7036
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
7037
return 1;
7038
}
7039
if (tmp == NULL) {
7040
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
7041
return 1;
7042
}
7043
else {
7044
int res;
7045
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
7046
goto failed;
7047
}
7048
res = obj2ast_expr(state, tmp, &target, arena);
7049
_Py_LeaveRecursiveCall();
7050
if (res != 0) goto failed;
7051
Py_CLEAR(tmp);
7052
}
7053
if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
7054
return 1;
7055
}
7056
if (tmp == NULL) {
7057
PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
7058
return 1;
7059
}
7060
else {
7061
int res;
7062
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
7063
goto failed;
7064
}
7065
res = obj2ast_expr(state, tmp, &annotation, arena);
7066
_Py_LeaveRecursiveCall();
7067
if (res != 0) goto failed;
7068
Py_CLEAR(tmp);
7069
}
7070
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
7071
return 1;
7072
}
7073
if (tmp == NULL || tmp == Py_None) {
7074
Py_CLEAR(tmp);
7075
value = NULL;
7076
}
7077
else {
7078
int res;
7079
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
7080
goto failed;
7081
}
7082
res = obj2ast_expr(state, tmp, &value, arena);
7083
_Py_LeaveRecursiveCall();
7084
if (res != 0) goto failed;
7085
Py_CLEAR(tmp);
7086
}
7087
if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
7088
return 1;
7089
}
7090
if (tmp == NULL) {
7091
PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
7092
return 1;
7093
}
7094
else {
7095
int res;
7096
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
7097
goto failed;
7098
}
7099
res = obj2ast_int(state, tmp, &simple, arena);
7100
_Py_LeaveRecursiveCall();
7101
if (res != 0) goto failed;
7102
Py_CLEAR(tmp);
7103
}
7104
*out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
7105
col_offset, end_lineno, end_col_offset, arena);
7106
if (*out == NULL) goto failed;
7107
return 0;
7108
}
7109
tp = state->For_type;
7110
isinstance = PyObject_IsInstance(obj, tp);
7111
if (isinstance == -1) {
7112
return 1;
7113
}
7114
if (isinstance) {
7115
expr_ty target;
7116
expr_ty iter;
7117
asdl_stmt_seq* body;
7118
asdl_stmt_seq* orelse;
7119
string type_comment;
7120
7121
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
7122
return 1;
7123
}
7124
if (tmp == NULL) {
7125
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
7126
return 1;
7127
}
7128
else {
7129
int res;
7130
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
7131
goto failed;
7132
}
7133
res = obj2ast_expr(state, tmp, &target, arena);
7134
_Py_LeaveRecursiveCall();
7135
if (res != 0) goto failed;
7136
Py_CLEAR(tmp);
7137
}
7138
if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
7139
return 1;
7140
}
7141
if (tmp == NULL) {
7142
PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
7143
return 1;
7144
}
7145
else {
7146
int res;
7147
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
7148
goto failed;
7149
}
7150
res = obj2ast_expr(state, tmp, &iter, arena);
7151
_Py_LeaveRecursiveCall();
7152
if (res != 0) goto failed;
7153
Py_CLEAR(tmp);
7154
}
7155
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7156
return 1;
7157
}
7158
if (tmp == NULL) {
7159
tmp = PyList_New(0);
7160
if (tmp == NULL) {
7161
return 1;
7162
}
7163
}
7164
{
7165
int res;
7166
Py_ssize_t len;
7167
Py_ssize_t i;
7168
if (!PyList_Check(tmp)) {
7169
PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7170
goto failed;
7171
}
7172
len = PyList_GET_SIZE(tmp);
7173
body = _Py_asdl_stmt_seq_new(len, arena);
7174
if (body == NULL) goto failed;
7175
for (i = 0; i < len; i++) {
7176
stmt_ty val;
7177
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7178
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
7179
goto failed;
7180
}
7181
res = obj2ast_stmt(state, tmp2, &val, arena);
7182
_Py_LeaveRecursiveCall();
7183
Py_DECREF(tmp2);
7184
if (res != 0) goto failed;
7185
if (len != PyList_GET_SIZE(tmp)) {
7186
PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
7187
goto failed;
7188
}
7189
asdl_seq_SET(body, i, val);
7190
}
7191
Py_CLEAR(tmp);
7192
}
7193
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7194
return 1;
7195
}
7196
if (tmp == NULL) {
7197
tmp = PyList_New(0);
7198
if (tmp == NULL) {
7199
return 1;
7200
}
7201
}
7202
{
7203
int res;
7204
Py_ssize_t len;
7205
Py_ssize_t i;
7206
if (!PyList_Check(tmp)) {
7207
PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7208
goto failed;
7209
}
7210
len = PyList_GET_SIZE(tmp);
7211
orelse = _Py_asdl_stmt_seq_new(len, arena);
7212
if (orelse == NULL) goto failed;
7213
for (i = 0; i < len; i++) {
7214
stmt_ty val;
7215
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7216
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
7217
goto failed;
7218
}
7219
res = obj2ast_stmt(state, tmp2, &val, arena);
7220
_Py_LeaveRecursiveCall();
7221
Py_DECREF(tmp2);
7222
if (res != 0) goto failed;
7223
if (len != PyList_GET_SIZE(tmp)) {
7224
PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
7225
goto failed;
7226
}
7227
asdl_seq_SET(orelse, i, val);
7228
}
7229
Py_CLEAR(tmp);
7230
}
7231
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7232
return 1;
7233
}
7234
if (tmp == NULL || tmp == Py_None) {
7235
Py_CLEAR(tmp);
7236
type_comment = NULL;
7237
}
7238
else {
7239
int res;
7240
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
7241
goto failed;
7242
}
7243
res = obj2ast_string(state, tmp, &type_comment, arena);
7244
_Py_LeaveRecursiveCall();
7245
if (res != 0) goto failed;
7246
Py_CLEAR(tmp);
7247
}
7248
*out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
7249
col_offset, end_lineno, end_col_offset, arena);
7250
if (*out == NULL) goto failed;
7251
return 0;
7252
}
7253
tp = state->AsyncFor_type;
7254
isinstance = PyObject_IsInstance(obj, tp);
7255
if (isinstance == -1) {
7256
return 1;
7257
}
7258
if (isinstance) {
7259
expr_ty target;
7260
expr_ty iter;
7261
asdl_stmt_seq* body;
7262
asdl_stmt_seq* orelse;
7263
string type_comment;
7264
7265
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
7266
return 1;
7267
}
7268
if (tmp == NULL) {
7269
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
7270
return 1;
7271
}
7272
else {
7273
int res;
7274
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
7275
goto failed;
7276
}
7277
res = obj2ast_expr(state, tmp, &target, arena);
7278
_Py_LeaveRecursiveCall();
7279
if (res != 0) goto failed;
7280
Py_CLEAR(tmp);
7281
}
7282
if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
7283
return 1;
7284
}
7285
if (tmp == NULL) {
7286
PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
7287
return 1;
7288
}
7289
else {
7290
int res;
7291
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
7292
goto failed;
7293
}
7294
res = obj2ast_expr(state, tmp, &iter, arena);
7295
_Py_LeaveRecursiveCall();
7296
if (res != 0) goto failed;
7297
Py_CLEAR(tmp);
7298
}
7299
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7300
return 1;
7301
}
7302
if (tmp == NULL) {
7303
tmp = PyList_New(0);
7304
if (tmp == NULL) {
7305
return 1;
7306
}
7307
}
7308
{
7309
int res;
7310
Py_ssize_t len;
7311
Py_ssize_t i;
7312
if (!PyList_Check(tmp)) {
7313
PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7314
goto failed;
7315
}
7316
len = PyList_GET_SIZE(tmp);
7317
body = _Py_asdl_stmt_seq_new(len, arena);
7318
if (body == NULL) goto failed;
7319
for (i = 0; i < len; i++) {
7320
stmt_ty val;
7321
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7322
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
7323
goto failed;
7324
}
7325
res = obj2ast_stmt(state, tmp2, &val, arena);
7326
_Py_LeaveRecursiveCall();
7327
Py_DECREF(tmp2);
7328
if (res != 0) goto failed;
7329
if (len != PyList_GET_SIZE(tmp)) {
7330
PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
7331
goto failed;
7332
}
7333
asdl_seq_SET(body, i, val);
7334
}
7335
Py_CLEAR(tmp);
7336
}
7337
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7338
return 1;
7339
}
7340
if (tmp == NULL) {
7341
tmp = PyList_New(0);
7342
if (tmp == NULL) {
7343
return 1;
7344
}
7345
}
7346
{
7347
int res;
7348
Py_ssize_t len;
7349
Py_ssize_t i;
7350
if (!PyList_Check(tmp)) {
7351
PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7352
goto failed;
7353
}
7354
len = PyList_GET_SIZE(tmp);
7355
orelse = _Py_asdl_stmt_seq_new(len, arena);
7356
if (orelse == NULL) goto failed;
7357
for (i = 0; i < len; i++) {
7358
stmt_ty val;
7359
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7360
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
7361
goto failed;
7362
}
7363
res = obj2ast_stmt(state, tmp2, &val, arena);
7364
_Py_LeaveRecursiveCall();
7365
Py_DECREF(tmp2);
7366
if (res != 0) goto failed;
7367
if (len != PyList_GET_SIZE(tmp)) {
7368
PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
7369
goto failed;
7370
}
7371
asdl_seq_SET(orelse, i, val);
7372
}
7373
Py_CLEAR(tmp);
7374
}
7375
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7376
return 1;
7377
}
7378
if (tmp == NULL || tmp == Py_None) {
7379
Py_CLEAR(tmp);
7380
type_comment = NULL;
7381
}
7382
else {
7383
int res;
7384
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
7385
goto failed;
7386
}
7387
res = obj2ast_string(state, tmp, &type_comment, arena);
7388
_Py_LeaveRecursiveCall();
7389
if (res != 0) goto failed;
7390
Py_CLEAR(tmp);
7391
}
7392
*out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
7393
lineno, col_offset, end_lineno, end_col_offset,
7394
arena);
7395
if (*out == NULL) goto failed;
7396
return 0;
7397
}
7398
tp = state->While_type;
7399
isinstance = PyObject_IsInstance(obj, tp);
7400
if (isinstance == -1) {
7401
return 1;
7402
}
7403
if (isinstance) {
7404
expr_ty test;
7405
asdl_stmt_seq* body;
7406
asdl_stmt_seq* orelse;
7407
7408
if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
7409
return 1;
7410
}
7411
if (tmp == NULL) {
7412
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
7413
return 1;
7414
}
7415
else {
7416
int res;
7417
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
7418
goto failed;
7419
}
7420
res = obj2ast_expr(state, tmp, &test, arena);
7421
_Py_LeaveRecursiveCall();
7422
if (res != 0) goto failed;
7423
Py_CLEAR(tmp);
7424
}
7425
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7426
return 1;
7427
}
7428
if (tmp == NULL) {
7429
tmp = PyList_New(0);
7430
if (tmp == NULL) {
7431
return 1;
7432
}
7433
}
7434
{
7435
int res;
7436
Py_ssize_t len;
7437
Py_ssize_t i;
7438
if (!PyList_Check(tmp)) {
7439
PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7440
goto failed;
7441
}
7442
len = PyList_GET_SIZE(tmp);
7443
body = _Py_asdl_stmt_seq_new(len, arena);
7444
if (body == NULL) goto failed;
7445
for (i = 0; i < len; i++) {
7446
stmt_ty val;
7447
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7448
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
7449
goto failed;
7450
}
7451
res = obj2ast_stmt(state, tmp2, &val, arena);
7452
_Py_LeaveRecursiveCall();
7453
Py_DECREF(tmp2);
7454
if (res != 0) goto failed;
7455
if (len != PyList_GET_SIZE(tmp)) {
7456
PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
7457
goto failed;
7458
}
7459
asdl_seq_SET(body, i, val);
7460
}
7461
Py_CLEAR(tmp);
7462
}
7463
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7464
return 1;
7465
}
7466
if (tmp == NULL) {
7467
tmp = PyList_New(0);
7468
if (tmp == NULL) {
7469
return 1;
7470
}
7471
}
7472
{
7473
int res;
7474
Py_ssize_t len;
7475
Py_ssize_t i;
7476
if (!PyList_Check(tmp)) {
7477
PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7478
goto failed;
7479
}
7480
len = PyList_GET_SIZE(tmp);
7481
orelse = _Py_asdl_stmt_seq_new(len, arena);
7482
if (orelse == NULL) goto failed;
7483
for (i = 0; i < len; i++) {
7484
stmt_ty val;
7485
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7486
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
7487
goto failed;
7488
}
7489
res = obj2ast_stmt(state, tmp2, &val, arena);
7490
_Py_LeaveRecursiveCall();
7491
Py_DECREF(tmp2);
7492
if (res != 0) goto failed;
7493
if (len != PyList_GET_SIZE(tmp)) {
7494
PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
7495
goto failed;
7496
}
7497
asdl_seq_SET(orelse, i, val);
7498
}
7499
Py_CLEAR(tmp);
7500
}
7501
*out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
7502
end_col_offset, arena);
7503
if (*out == NULL) goto failed;
7504
return 0;
7505
}
7506
tp = state->If_type;
7507
isinstance = PyObject_IsInstance(obj, tp);
7508
if (isinstance == -1) {
7509
return 1;
7510
}
7511
if (isinstance) {
7512
expr_ty test;
7513
asdl_stmt_seq* body;
7514
asdl_stmt_seq* orelse;
7515
7516
if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
7517
return 1;
7518
}
7519
if (tmp == NULL) {
7520
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
7521
return 1;
7522
}
7523
else {
7524
int res;
7525
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7526
goto failed;
7527
}
7528
res = obj2ast_expr(state, tmp, &test, arena);
7529
_Py_LeaveRecursiveCall();
7530
if (res != 0) goto failed;
7531
Py_CLEAR(tmp);
7532
}
7533
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7534
return 1;
7535
}
7536
if (tmp == NULL) {
7537
tmp = PyList_New(0);
7538
if (tmp == NULL) {
7539
return 1;
7540
}
7541
}
7542
{
7543
int res;
7544
Py_ssize_t len;
7545
Py_ssize_t i;
7546
if (!PyList_Check(tmp)) {
7547
PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7548
goto failed;
7549
}
7550
len = PyList_GET_SIZE(tmp);
7551
body = _Py_asdl_stmt_seq_new(len, arena);
7552
if (body == NULL) goto failed;
7553
for (i = 0; i < len; i++) {
7554
stmt_ty val;
7555
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7556
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7557
goto failed;
7558
}
7559
res = obj2ast_stmt(state, tmp2, &val, arena);
7560
_Py_LeaveRecursiveCall();
7561
Py_DECREF(tmp2);
7562
if (res != 0) goto failed;
7563
if (len != PyList_GET_SIZE(tmp)) {
7564
PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
7565
goto failed;
7566
}
7567
asdl_seq_SET(body, i, val);
7568
}
7569
Py_CLEAR(tmp);
7570
}
7571
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7572
return 1;
7573
}
7574
if (tmp == NULL) {
7575
tmp = PyList_New(0);
7576
if (tmp == NULL) {
7577
return 1;
7578
}
7579
}
7580
{
7581
int res;
7582
Py_ssize_t len;
7583
Py_ssize_t i;
7584
if (!PyList_Check(tmp)) {
7585
PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7586
goto failed;
7587
}
7588
len = PyList_GET_SIZE(tmp);
7589
orelse = _Py_asdl_stmt_seq_new(len, arena);
7590
if (orelse == NULL) goto failed;
7591
for (i = 0; i < len; i++) {
7592
stmt_ty val;
7593
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7594
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7595
goto failed;
7596
}
7597
res = obj2ast_stmt(state, tmp2, &val, arena);
7598
_Py_LeaveRecursiveCall();
7599
Py_DECREF(tmp2);
7600
if (res != 0) goto failed;
7601
if (len != PyList_GET_SIZE(tmp)) {
7602
PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
7603
goto failed;
7604
}
7605
asdl_seq_SET(orelse, i, val);
7606
}
7607
Py_CLEAR(tmp);
7608
}
7609
*out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
7610
end_col_offset, arena);
7611
if (*out == NULL) goto failed;
7612
return 0;
7613
}
7614
tp = state->With_type;
7615
isinstance = PyObject_IsInstance(obj, tp);
7616
if (isinstance == -1) {
7617
return 1;
7618
}
7619
if (isinstance) {
7620
asdl_withitem_seq* items;
7621
asdl_stmt_seq* body;
7622
string type_comment;
7623
7624
if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
7625
return 1;
7626
}
7627
if (tmp == NULL) {
7628
tmp = PyList_New(0);
7629
if (tmp == NULL) {
7630
return 1;
7631
}
7632
}
7633
{
7634
int res;
7635
Py_ssize_t len;
7636
Py_ssize_t i;
7637
if (!PyList_Check(tmp)) {
7638
PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7639
goto failed;
7640
}
7641
len = PyList_GET_SIZE(tmp);
7642
items = _Py_asdl_withitem_seq_new(len, arena);
7643
if (items == NULL) goto failed;
7644
for (i = 0; i < len; i++) {
7645
withitem_ty val;
7646
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7647
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7648
goto failed;
7649
}
7650
res = obj2ast_withitem(state, tmp2, &val, arena);
7651
_Py_LeaveRecursiveCall();
7652
Py_DECREF(tmp2);
7653
if (res != 0) goto failed;
7654
if (len != PyList_GET_SIZE(tmp)) {
7655
PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
7656
goto failed;
7657
}
7658
asdl_seq_SET(items, i, val);
7659
}
7660
Py_CLEAR(tmp);
7661
}
7662
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7663
return 1;
7664
}
7665
if (tmp == NULL) {
7666
tmp = PyList_New(0);
7667
if (tmp == NULL) {
7668
return 1;
7669
}
7670
}
7671
{
7672
int res;
7673
Py_ssize_t len;
7674
Py_ssize_t i;
7675
if (!PyList_Check(tmp)) {
7676
PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7677
goto failed;
7678
}
7679
len = PyList_GET_SIZE(tmp);
7680
body = _Py_asdl_stmt_seq_new(len, arena);
7681
if (body == NULL) goto failed;
7682
for (i = 0; i < len; i++) {
7683
stmt_ty val;
7684
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7685
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7686
goto failed;
7687
}
7688
res = obj2ast_stmt(state, tmp2, &val, arena);
7689
_Py_LeaveRecursiveCall();
7690
Py_DECREF(tmp2);
7691
if (res != 0) goto failed;
7692
if (len != PyList_GET_SIZE(tmp)) {
7693
PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
7694
goto failed;
7695
}
7696
asdl_seq_SET(body, i, val);
7697
}
7698
Py_CLEAR(tmp);
7699
}
7700
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7701
return 1;
7702
}
7703
if (tmp == NULL || tmp == Py_None) {
7704
Py_CLEAR(tmp);
7705
type_comment = NULL;
7706
}
7707
else {
7708
int res;
7709
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7710
goto failed;
7711
}
7712
res = obj2ast_string(state, tmp, &type_comment, arena);
7713
_Py_LeaveRecursiveCall();
7714
if (res != 0) goto failed;
7715
Py_CLEAR(tmp);
7716
}
7717
*out = _PyAST_With(items, body, type_comment, lineno, col_offset,
7718
end_lineno, end_col_offset, arena);
7719
if (*out == NULL) goto failed;
7720
return 0;
7721
}
7722
tp = state->AsyncWith_type;
7723
isinstance = PyObject_IsInstance(obj, tp);
7724
if (isinstance == -1) {
7725
return 1;
7726
}
7727
if (isinstance) {
7728
asdl_withitem_seq* items;
7729
asdl_stmt_seq* body;
7730
string type_comment;
7731
7732
if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
7733
return 1;
7734
}
7735
if (tmp == NULL) {
7736
tmp = PyList_New(0);
7737
if (tmp == NULL) {
7738
return 1;
7739
}
7740
}
7741
{
7742
int res;
7743
Py_ssize_t len;
7744
Py_ssize_t i;
7745
if (!PyList_Check(tmp)) {
7746
PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7747
goto failed;
7748
}
7749
len = PyList_GET_SIZE(tmp);
7750
items = _Py_asdl_withitem_seq_new(len, arena);
7751
if (items == NULL) goto failed;
7752
for (i = 0; i < len; i++) {
7753
withitem_ty val;
7754
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7755
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7756
goto failed;
7757
}
7758
res = obj2ast_withitem(state, tmp2, &val, arena);
7759
_Py_LeaveRecursiveCall();
7760
Py_DECREF(tmp2);
7761
if (res != 0) goto failed;
7762
if (len != PyList_GET_SIZE(tmp)) {
7763
PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
7764
goto failed;
7765
}
7766
asdl_seq_SET(items, i, val);
7767
}
7768
Py_CLEAR(tmp);
7769
}
7770
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7771
return 1;
7772
}
7773
if (tmp == NULL) {
7774
tmp = PyList_New(0);
7775
if (tmp == NULL) {
7776
return 1;
7777
}
7778
}
7779
{
7780
int res;
7781
Py_ssize_t len;
7782
Py_ssize_t i;
7783
if (!PyList_Check(tmp)) {
7784
PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7785
goto failed;
7786
}
7787
len = PyList_GET_SIZE(tmp);
7788
body = _Py_asdl_stmt_seq_new(len, arena);
7789
if (body == NULL) goto failed;
7790
for (i = 0; i < len; i++) {
7791
stmt_ty val;
7792
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7793
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7794
goto failed;
7795
}
7796
res = obj2ast_stmt(state, tmp2, &val, arena);
7797
_Py_LeaveRecursiveCall();
7798
Py_DECREF(tmp2);
7799
if (res != 0) goto failed;
7800
if (len != PyList_GET_SIZE(tmp)) {
7801
PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
7802
goto failed;
7803
}
7804
asdl_seq_SET(body, i, val);
7805
}
7806
Py_CLEAR(tmp);
7807
}
7808
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7809
return 1;
7810
}
7811
if (tmp == NULL || tmp == Py_None) {
7812
Py_CLEAR(tmp);
7813
type_comment = NULL;
7814
}
7815
else {
7816
int res;
7817
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7818
goto failed;
7819
}
7820
res = obj2ast_string(state, tmp, &type_comment, arena);
7821
_Py_LeaveRecursiveCall();
7822
if (res != 0) goto failed;
7823
Py_CLEAR(tmp);
7824
}
7825
*out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
7826
end_lineno, end_col_offset, arena);
7827
if (*out == NULL) goto failed;
7828
return 0;
7829
}
7830
tp = state->Match_type;
7831
isinstance = PyObject_IsInstance(obj, tp);
7832
if (isinstance == -1) {
7833
return 1;
7834
}
7835
if (isinstance) {
7836
expr_ty subject;
7837
asdl_match_case_seq* cases;
7838
7839
if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
7840
return 1;
7841
}
7842
if (tmp == NULL) {
7843
PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
7844
return 1;
7845
}
7846
else {
7847
int res;
7848
if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7849
goto failed;
7850
}
7851
res = obj2ast_expr(state, tmp, &subject, arena);
7852
_Py_LeaveRecursiveCall();
7853
if (res != 0) goto failed;
7854
Py_CLEAR(tmp);
7855
}
7856
if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
7857
return 1;
7858
}
7859
if (tmp == NULL) {
7860
tmp = PyList_New(0);
7861
if (tmp == NULL) {
7862
return 1;
7863
}
7864
}
7865
{
7866
int res;
7867
Py_ssize_t len;
7868
Py_ssize_t i;
7869
if (!PyList_Check(tmp)) {
7870
PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7871
goto failed;
7872
}
7873
len = PyList_GET_SIZE(tmp);
7874
cases = _Py_asdl_match_case_seq_new(len, arena);
7875
if (cases == NULL) goto failed;
7876
for (i = 0; i < len; i++) {
7877
match_case_ty val;
7878
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7879
if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7880
goto failed;
7881
}
7882
res = obj2ast_match_case(state, tmp2, &val, arena);
7883
_Py_LeaveRecursiveCall();
7884
Py_DECREF(tmp2);
7885
if (res != 0) goto failed;
7886
if (len != PyList_GET_SIZE(tmp)) {
7887
PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
7888
goto failed;
7889
}
7890
asdl_seq_SET(cases, i, val);
7891
}
7892
Py_CLEAR(tmp);
7893
}
7894
*out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
7895
end_col_offset, arena);
7896
if (*out == NULL) goto failed;
7897
return 0;
7898
}
7899
tp = state->Raise_type;
7900
isinstance = PyObject_IsInstance(obj, tp);
7901
if (isinstance == -1) {
7902
return 1;
7903
}
7904
if (isinstance) {
7905
expr_ty exc;
7906
expr_ty cause;
7907
7908
if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
7909
return 1;
7910
}
7911
if (tmp == NULL || tmp == Py_None) {
7912
Py_CLEAR(tmp);
7913
exc = NULL;
7914
}
7915
else {
7916
int res;
7917
if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7918
goto failed;
7919
}
7920
res = obj2ast_expr(state, tmp, &exc, arena);
7921
_Py_LeaveRecursiveCall();
7922
if (res != 0) goto failed;
7923
Py_CLEAR(tmp);
7924
}
7925
if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
7926
return 1;
7927
}
7928
if (tmp == NULL || tmp == Py_None) {
7929
Py_CLEAR(tmp);
7930
cause = NULL;
7931
}
7932
else {
7933
int res;
7934
if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7935
goto failed;
7936
}
7937
res = obj2ast_expr(state, tmp, &cause, arena);
7938
_Py_LeaveRecursiveCall();
7939
if (res != 0) goto failed;
7940
Py_CLEAR(tmp);
7941
}
7942
*out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
7943
end_col_offset, arena);
7944
if (*out == NULL) goto failed;
7945
return 0;
7946
}
7947
tp = state->Try_type;
7948
isinstance = PyObject_IsInstance(obj, tp);
7949
if (isinstance == -1) {
7950
return 1;
7951
}
7952
if (isinstance) {
7953
asdl_stmt_seq* body;
7954
asdl_excepthandler_seq* handlers;
7955
asdl_stmt_seq* orelse;
7956
asdl_stmt_seq* finalbody;
7957
7958
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7959
return 1;
7960
}
7961
if (tmp == NULL) {
7962
tmp = PyList_New(0);
7963
if (tmp == NULL) {
7964
return 1;
7965
}
7966
}
7967
{
7968
int res;
7969
Py_ssize_t len;
7970
Py_ssize_t i;
7971
if (!PyList_Check(tmp)) {
7972
PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7973
goto failed;
7974
}
7975
len = PyList_GET_SIZE(tmp);
7976
body = _Py_asdl_stmt_seq_new(len, arena);
7977
if (body == NULL) goto failed;
7978
for (i = 0; i < len; i++) {
7979
stmt_ty val;
7980
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
7981
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7982
goto failed;
7983
}
7984
res = obj2ast_stmt(state, tmp2, &val, arena);
7985
_Py_LeaveRecursiveCall();
7986
Py_DECREF(tmp2);
7987
if (res != 0) goto failed;
7988
if (len != PyList_GET_SIZE(tmp)) {
7989
PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
7990
goto failed;
7991
}
7992
asdl_seq_SET(body, i, val);
7993
}
7994
Py_CLEAR(tmp);
7995
}
7996
if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
7997
return 1;
7998
}
7999
if (tmp == NULL) {
8000
tmp = PyList_New(0);
8001
if (tmp == NULL) {
8002
return 1;
8003
}
8004
}
8005
{
8006
int res;
8007
Py_ssize_t len;
8008
Py_ssize_t i;
8009
if (!PyList_Check(tmp)) {
8010
PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8011
goto failed;
8012
}
8013
len = PyList_GET_SIZE(tmp);
8014
handlers = _Py_asdl_excepthandler_seq_new(len, arena);
8015
if (handlers == NULL) goto failed;
8016
for (i = 0; i < len; i++) {
8017
excepthandler_ty val;
8018
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8019
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
8020
goto failed;
8021
}
8022
res = obj2ast_excepthandler(state, tmp2, &val, arena);
8023
_Py_LeaveRecursiveCall();
8024
Py_DECREF(tmp2);
8025
if (res != 0) goto failed;
8026
if (len != PyList_GET_SIZE(tmp)) {
8027
PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
8028
goto failed;
8029
}
8030
asdl_seq_SET(handlers, i, val);
8031
}
8032
Py_CLEAR(tmp);
8033
}
8034
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
8035
return 1;
8036
}
8037
if (tmp == NULL) {
8038
tmp = PyList_New(0);
8039
if (tmp == NULL) {
8040
return 1;
8041
}
8042
}
8043
{
8044
int res;
8045
Py_ssize_t len;
8046
Py_ssize_t i;
8047
if (!PyList_Check(tmp)) {
8048
PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8049
goto failed;
8050
}
8051
len = PyList_GET_SIZE(tmp);
8052
orelse = _Py_asdl_stmt_seq_new(len, arena);
8053
if (orelse == NULL) goto failed;
8054
for (i = 0; i < len; i++) {
8055
stmt_ty val;
8056
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8057
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
8058
goto failed;
8059
}
8060
res = obj2ast_stmt(state, tmp2, &val, arena);
8061
_Py_LeaveRecursiveCall();
8062
Py_DECREF(tmp2);
8063
if (res != 0) goto failed;
8064
if (len != PyList_GET_SIZE(tmp)) {
8065
PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
8066
goto failed;
8067
}
8068
asdl_seq_SET(orelse, i, val);
8069
}
8070
Py_CLEAR(tmp);
8071
}
8072
if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
8073
return 1;
8074
}
8075
if (tmp == NULL) {
8076
tmp = PyList_New(0);
8077
if (tmp == NULL) {
8078
return 1;
8079
}
8080
}
8081
{
8082
int res;
8083
Py_ssize_t len;
8084
Py_ssize_t i;
8085
if (!PyList_Check(tmp)) {
8086
PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8087
goto failed;
8088
}
8089
len = PyList_GET_SIZE(tmp);
8090
finalbody = _Py_asdl_stmt_seq_new(len, arena);
8091
if (finalbody == NULL) goto failed;
8092
for (i = 0; i < len; i++) {
8093
stmt_ty val;
8094
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8095
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
8096
goto failed;
8097
}
8098
res = obj2ast_stmt(state, tmp2, &val, arena);
8099
_Py_LeaveRecursiveCall();
8100
Py_DECREF(tmp2);
8101
if (res != 0) goto failed;
8102
if (len != PyList_GET_SIZE(tmp)) {
8103
PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
8104
goto failed;
8105
}
8106
asdl_seq_SET(finalbody, i, val);
8107
}
8108
Py_CLEAR(tmp);
8109
}
8110
*out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
8111
col_offset, end_lineno, end_col_offset, arena);
8112
if (*out == NULL) goto failed;
8113
return 0;
8114
}
8115
tp = state->TryStar_type;
8116
isinstance = PyObject_IsInstance(obj, tp);
8117
if (isinstance == -1) {
8118
return 1;
8119
}
8120
if (isinstance) {
8121
asdl_stmt_seq* body;
8122
asdl_excepthandler_seq* handlers;
8123
asdl_stmt_seq* orelse;
8124
asdl_stmt_seq* finalbody;
8125
8126
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8127
return 1;
8128
}
8129
if (tmp == NULL) {
8130
tmp = PyList_New(0);
8131
if (tmp == NULL) {
8132
return 1;
8133
}
8134
}
8135
{
8136
int res;
8137
Py_ssize_t len;
8138
Py_ssize_t i;
8139
if (!PyList_Check(tmp)) {
8140
PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8141
goto failed;
8142
}
8143
len = PyList_GET_SIZE(tmp);
8144
body = _Py_asdl_stmt_seq_new(len, arena);
8145
if (body == NULL) goto failed;
8146
for (i = 0; i < len; i++) {
8147
stmt_ty val;
8148
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8149
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
8150
goto failed;
8151
}
8152
res = obj2ast_stmt(state, tmp2, &val, arena);
8153
_Py_LeaveRecursiveCall();
8154
Py_DECREF(tmp2);
8155
if (res != 0) goto failed;
8156
if (len != PyList_GET_SIZE(tmp)) {
8157
PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
8158
goto failed;
8159
}
8160
asdl_seq_SET(body, i, val);
8161
}
8162
Py_CLEAR(tmp);
8163
}
8164
if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
8165
return 1;
8166
}
8167
if (tmp == NULL) {
8168
tmp = PyList_New(0);
8169
if (tmp == NULL) {
8170
return 1;
8171
}
8172
}
8173
{
8174
int res;
8175
Py_ssize_t len;
8176
Py_ssize_t i;
8177
if (!PyList_Check(tmp)) {
8178
PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8179
goto failed;
8180
}
8181
len = PyList_GET_SIZE(tmp);
8182
handlers = _Py_asdl_excepthandler_seq_new(len, arena);
8183
if (handlers == NULL) goto failed;
8184
for (i = 0; i < len; i++) {
8185
excepthandler_ty val;
8186
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8187
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
8188
goto failed;
8189
}
8190
res = obj2ast_excepthandler(state, tmp2, &val, arena);
8191
_Py_LeaveRecursiveCall();
8192
Py_DECREF(tmp2);
8193
if (res != 0) goto failed;
8194
if (len != PyList_GET_SIZE(tmp)) {
8195
PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
8196
goto failed;
8197
}
8198
asdl_seq_SET(handlers, i, val);
8199
}
8200
Py_CLEAR(tmp);
8201
}
8202
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
8203
return 1;
8204
}
8205
if (tmp == NULL) {
8206
tmp = PyList_New(0);
8207
if (tmp == NULL) {
8208
return 1;
8209
}
8210
}
8211
{
8212
int res;
8213
Py_ssize_t len;
8214
Py_ssize_t i;
8215
if (!PyList_Check(tmp)) {
8216
PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8217
goto failed;
8218
}
8219
len = PyList_GET_SIZE(tmp);
8220
orelse = _Py_asdl_stmt_seq_new(len, arena);
8221
if (orelse == NULL) goto failed;
8222
for (i = 0; i < len; i++) {
8223
stmt_ty val;
8224
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8225
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
8226
goto failed;
8227
}
8228
res = obj2ast_stmt(state, tmp2, &val, arena);
8229
_Py_LeaveRecursiveCall();
8230
Py_DECREF(tmp2);
8231
if (res != 0) goto failed;
8232
if (len != PyList_GET_SIZE(tmp)) {
8233
PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
8234
goto failed;
8235
}
8236
asdl_seq_SET(orelse, i, val);
8237
}
8238
Py_CLEAR(tmp);
8239
}
8240
if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
8241
return 1;
8242
}
8243
if (tmp == NULL) {
8244
tmp = PyList_New(0);
8245
if (tmp == NULL) {
8246
return 1;
8247
}
8248
}
8249
{
8250
int res;
8251
Py_ssize_t len;
8252
Py_ssize_t i;
8253
if (!PyList_Check(tmp)) {
8254
PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8255
goto failed;
8256
}
8257
len = PyList_GET_SIZE(tmp);
8258
finalbody = _Py_asdl_stmt_seq_new(len, arena);
8259
if (finalbody == NULL) goto failed;
8260
for (i = 0; i < len; i++) {
8261
stmt_ty val;
8262
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8263
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
8264
goto failed;
8265
}
8266
res = obj2ast_stmt(state, tmp2, &val, arena);
8267
_Py_LeaveRecursiveCall();
8268
Py_DECREF(tmp2);
8269
if (res != 0) goto failed;
8270
if (len != PyList_GET_SIZE(tmp)) {
8271
PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
8272
goto failed;
8273
}
8274
asdl_seq_SET(finalbody, i, val);
8275
}
8276
Py_CLEAR(tmp);
8277
}
8278
*out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
8279
col_offset, end_lineno, end_col_offset, arena);
8280
if (*out == NULL) goto failed;
8281
return 0;
8282
}
8283
tp = state->Assert_type;
8284
isinstance = PyObject_IsInstance(obj, tp);
8285
if (isinstance == -1) {
8286
return 1;
8287
}
8288
if (isinstance) {
8289
expr_ty test;
8290
expr_ty msg;
8291
8292
if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
8293
return 1;
8294
}
8295
if (tmp == NULL) {
8296
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
8297
return 1;
8298
}
8299
else {
8300
int res;
8301
if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
8302
goto failed;
8303
}
8304
res = obj2ast_expr(state, tmp, &test, arena);
8305
_Py_LeaveRecursiveCall();
8306
if (res != 0) goto failed;
8307
Py_CLEAR(tmp);
8308
}
8309
if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
8310
return 1;
8311
}
8312
if (tmp == NULL || tmp == Py_None) {
8313
Py_CLEAR(tmp);
8314
msg = NULL;
8315
}
8316
else {
8317
int res;
8318
if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
8319
goto failed;
8320
}
8321
res = obj2ast_expr(state, tmp, &msg, arena);
8322
_Py_LeaveRecursiveCall();
8323
if (res != 0) goto failed;
8324
Py_CLEAR(tmp);
8325
}
8326
*out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
8327
end_col_offset, arena);
8328
if (*out == NULL) goto failed;
8329
return 0;
8330
}
8331
tp = state->Import_type;
8332
isinstance = PyObject_IsInstance(obj, tp);
8333
if (isinstance == -1) {
8334
return 1;
8335
}
8336
if (isinstance) {
8337
asdl_alias_seq* names;
8338
8339
if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
8340
return 1;
8341
}
8342
if (tmp == NULL) {
8343
tmp = PyList_New(0);
8344
if (tmp == NULL) {
8345
return 1;
8346
}
8347
}
8348
{
8349
int res;
8350
Py_ssize_t len;
8351
Py_ssize_t i;
8352
if (!PyList_Check(tmp)) {
8353
PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8354
goto failed;
8355
}
8356
len = PyList_GET_SIZE(tmp);
8357
names = _Py_asdl_alias_seq_new(len, arena);
8358
if (names == NULL) goto failed;
8359
for (i = 0; i < len; i++) {
8360
alias_ty val;
8361
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8362
if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
8363
goto failed;
8364
}
8365
res = obj2ast_alias(state, tmp2, &val, arena);
8366
_Py_LeaveRecursiveCall();
8367
Py_DECREF(tmp2);
8368
if (res != 0) goto failed;
8369
if (len != PyList_GET_SIZE(tmp)) {
8370
PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
8371
goto failed;
8372
}
8373
asdl_seq_SET(names, i, val);
8374
}
8375
Py_CLEAR(tmp);
8376
}
8377
*out = _PyAST_Import(names, lineno, col_offset, end_lineno,
8378
end_col_offset, arena);
8379
if (*out == NULL) goto failed;
8380
return 0;
8381
}
8382
tp = state->ImportFrom_type;
8383
isinstance = PyObject_IsInstance(obj, tp);
8384
if (isinstance == -1) {
8385
return 1;
8386
}
8387
if (isinstance) {
8388
identifier module;
8389
asdl_alias_seq* names;
8390
int level;
8391
8392
if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
8393
return 1;
8394
}
8395
if (tmp == NULL || tmp == Py_None) {
8396
Py_CLEAR(tmp);
8397
module = NULL;
8398
}
8399
else {
8400
int res;
8401
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
8402
goto failed;
8403
}
8404
res = obj2ast_identifier(state, tmp, &module, arena);
8405
_Py_LeaveRecursiveCall();
8406
if (res != 0) goto failed;
8407
Py_CLEAR(tmp);
8408
}
8409
if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
8410
return 1;
8411
}
8412
if (tmp == NULL) {
8413
tmp = PyList_New(0);
8414
if (tmp == NULL) {
8415
return 1;
8416
}
8417
}
8418
{
8419
int res;
8420
Py_ssize_t len;
8421
Py_ssize_t i;
8422
if (!PyList_Check(tmp)) {
8423
PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8424
goto failed;
8425
}
8426
len = PyList_GET_SIZE(tmp);
8427
names = _Py_asdl_alias_seq_new(len, arena);
8428
if (names == NULL) goto failed;
8429
for (i = 0; i < len; i++) {
8430
alias_ty val;
8431
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8432
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
8433
goto failed;
8434
}
8435
res = obj2ast_alias(state, tmp2, &val, arena);
8436
_Py_LeaveRecursiveCall();
8437
Py_DECREF(tmp2);
8438
if (res != 0) goto failed;
8439
if (len != PyList_GET_SIZE(tmp)) {
8440
PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
8441
goto failed;
8442
}
8443
asdl_seq_SET(names, i, val);
8444
}
8445
Py_CLEAR(tmp);
8446
}
8447
if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
8448
return 1;
8449
}
8450
if (tmp == NULL || tmp == Py_None) {
8451
Py_CLEAR(tmp);
8452
level = 0;
8453
}
8454
else {
8455
int res;
8456
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
8457
goto failed;
8458
}
8459
res = obj2ast_int(state, tmp, &level, arena);
8460
_Py_LeaveRecursiveCall();
8461
if (res != 0) goto failed;
8462
Py_CLEAR(tmp);
8463
}
8464
*out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
8465
end_lineno, end_col_offset, arena);
8466
if (*out == NULL) goto failed;
8467
return 0;
8468
}
8469
tp = state->Global_type;
8470
isinstance = PyObject_IsInstance(obj, tp);
8471
if (isinstance == -1) {
8472
return 1;
8473
}
8474
if (isinstance) {
8475
asdl_identifier_seq* names;
8476
8477
if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
8478
return 1;
8479
}
8480
if (tmp == NULL) {
8481
tmp = PyList_New(0);
8482
if (tmp == NULL) {
8483
return 1;
8484
}
8485
}
8486
{
8487
int res;
8488
Py_ssize_t len;
8489
Py_ssize_t i;
8490
if (!PyList_Check(tmp)) {
8491
PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8492
goto failed;
8493
}
8494
len = PyList_GET_SIZE(tmp);
8495
names = _Py_asdl_identifier_seq_new(len, arena);
8496
if (names == NULL) goto failed;
8497
for (i = 0; i < len; i++) {
8498
identifier val;
8499
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8500
if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
8501
goto failed;
8502
}
8503
res = obj2ast_identifier(state, tmp2, &val, arena);
8504
_Py_LeaveRecursiveCall();
8505
Py_DECREF(tmp2);
8506
if (res != 0) goto failed;
8507
if (len != PyList_GET_SIZE(tmp)) {
8508
PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
8509
goto failed;
8510
}
8511
asdl_seq_SET(names, i, val);
8512
}
8513
Py_CLEAR(tmp);
8514
}
8515
*out = _PyAST_Global(names, lineno, col_offset, end_lineno,
8516
end_col_offset, arena);
8517
if (*out == NULL) goto failed;
8518
return 0;
8519
}
8520
tp = state->Nonlocal_type;
8521
isinstance = PyObject_IsInstance(obj, tp);
8522
if (isinstance == -1) {
8523
return 1;
8524
}
8525
if (isinstance) {
8526
asdl_identifier_seq* names;
8527
8528
if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
8529
return 1;
8530
}
8531
if (tmp == NULL) {
8532
tmp = PyList_New(0);
8533
if (tmp == NULL) {
8534
return 1;
8535
}
8536
}
8537
{
8538
int res;
8539
Py_ssize_t len;
8540
Py_ssize_t i;
8541
if (!PyList_Check(tmp)) {
8542
PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8543
goto failed;
8544
}
8545
len = PyList_GET_SIZE(tmp);
8546
names = _Py_asdl_identifier_seq_new(len, arena);
8547
if (names == NULL) goto failed;
8548
for (i = 0; i < len; i++) {
8549
identifier val;
8550
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8551
if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
8552
goto failed;
8553
}
8554
res = obj2ast_identifier(state, tmp2, &val, arena);
8555
_Py_LeaveRecursiveCall();
8556
Py_DECREF(tmp2);
8557
if (res != 0) goto failed;
8558
if (len != PyList_GET_SIZE(tmp)) {
8559
PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
8560
goto failed;
8561
}
8562
asdl_seq_SET(names, i, val);
8563
}
8564
Py_CLEAR(tmp);
8565
}
8566
*out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
8567
end_col_offset, arena);
8568
if (*out == NULL) goto failed;
8569
return 0;
8570
}
8571
tp = state->Expr_type;
8572
isinstance = PyObject_IsInstance(obj, tp);
8573
if (isinstance == -1) {
8574
return 1;
8575
}
8576
if (isinstance) {
8577
expr_ty value;
8578
8579
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8580
return 1;
8581
}
8582
if (tmp == NULL) {
8583
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
8584
return 1;
8585
}
8586
else {
8587
int res;
8588
if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
8589
goto failed;
8590
}
8591
res = obj2ast_expr(state, tmp, &value, arena);
8592
_Py_LeaveRecursiveCall();
8593
if (res != 0) goto failed;
8594
Py_CLEAR(tmp);
8595
}
8596
*out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
8597
end_col_offset, arena);
8598
if (*out == NULL) goto failed;
8599
return 0;
8600
}
8601
tp = state->Pass_type;
8602
isinstance = PyObject_IsInstance(obj, tp);
8603
if (isinstance == -1) {
8604
return 1;
8605
}
8606
if (isinstance) {
8607
8608
*out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
8609
arena);
8610
if (*out == NULL) goto failed;
8611
return 0;
8612
}
8613
tp = state->Break_type;
8614
isinstance = PyObject_IsInstance(obj, tp);
8615
if (isinstance == -1) {
8616
return 1;
8617
}
8618
if (isinstance) {
8619
8620
*out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
8621
arena);
8622
if (*out == NULL) goto failed;
8623
return 0;
8624
}
8625
tp = state->Continue_type;
8626
isinstance = PyObject_IsInstance(obj, tp);
8627
if (isinstance == -1) {
8628
return 1;
8629
}
8630
if (isinstance) {
8631
8632
*out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
8633
arena);
8634
if (*out == NULL) goto failed;
8635
return 0;
8636
}
8637
8638
PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
8639
failed:
8640
Py_XDECREF(tmp);
8641
return 1;
8642
}
8643
8644
int
8645
obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
8646
arena)
8647
{
8648
int isinstance;
8649
8650
PyObject *tmp = NULL;
8651
PyObject *tp;
8652
int lineno;
8653
int col_offset;
8654
int end_lineno;
8655
int end_col_offset;
8656
8657
if (obj == Py_None) {
8658
*out = NULL;
8659
return 0;
8660
}
8661
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
8662
return 1;
8663
}
8664
if (tmp == NULL) {
8665
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
8666
return 1;
8667
}
8668
else {
8669
int res;
8670
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8671
goto failed;
8672
}
8673
res = obj2ast_int(state, tmp, &lineno, arena);
8674
_Py_LeaveRecursiveCall();
8675
if (res != 0) goto failed;
8676
Py_CLEAR(tmp);
8677
}
8678
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
8679
return 1;
8680
}
8681
if (tmp == NULL) {
8682
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
8683
return 1;
8684
}
8685
else {
8686
int res;
8687
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8688
goto failed;
8689
}
8690
res = obj2ast_int(state, tmp, &col_offset, arena);
8691
_Py_LeaveRecursiveCall();
8692
if (res != 0) goto failed;
8693
Py_CLEAR(tmp);
8694
}
8695
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
8696
return 1;
8697
}
8698
if (tmp == NULL || tmp == Py_None) {
8699
Py_CLEAR(tmp);
8700
end_lineno = lineno;
8701
}
8702
else {
8703
int res;
8704
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8705
goto failed;
8706
}
8707
res = obj2ast_int(state, tmp, &end_lineno, arena);
8708
_Py_LeaveRecursiveCall();
8709
if (res != 0) goto failed;
8710
Py_CLEAR(tmp);
8711
}
8712
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
8713
return 1;
8714
}
8715
if (tmp == NULL || tmp == Py_None) {
8716
Py_CLEAR(tmp);
8717
end_col_offset = col_offset;
8718
}
8719
else {
8720
int res;
8721
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8722
goto failed;
8723
}
8724
res = obj2ast_int(state, tmp, &end_col_offset, arena);
8725
_Py_LeaveRecursiveCall();
8726
if (res != 0) goto failed;
8727
Py_CLEAR(tmp);
8728
}
8729
tp = state->BoolOp_type;
8730
isinstance = PyObject_IsInstance(obj, tp);
8731
if (isinstance == -1) {
8732
return 1;
8733
}
8734
if (isinstance) {
8735
boolop_ty op;
8736
asdl_expr_seq* values;
8737
8738
if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8739
return 1;
8740
}
8741
if (tmp == NULL) {
8742
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
8743
return 1;
8744
}
8745
else {
8746
int res;
8747
if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
8748
goto failed;
8749
}
8750
res = obj2ast_boolop(state, tmp, &op, arena);
8751
_Py_LeaveRecursiveCall();
8752
if (res != 0) goto failed;
8753
Py_CLEAR(tmp);
8754
}
8755
if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
8756
return 1;
8757
}
8758
if (tmp == NULL) {
8759
tmp = PyList_New(0);
8760
if (tmp == NULL) {
8761
return 1;
8762
}
8763
}
8764
{
8765
int res;
8766
Py_ssize_t len;
8767
Py_ssize_t i;
8768
if (!PyList_Check(tmp)) {
8769
PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8770
goto failed;
8771
}
8772
len = PyList_GET_SIZE(tmp);
8773
values = _Py_asdl_expr_seq_new(len, arena);
8774
if (values == NULL) goto failed;
8775
for (i = 0; i < len; i++) {
8776
expr_ty val;
8777
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
8778
if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
8779
goto failed;
8780
}
8781
res = obj2ast_expr(state, tmp2, &val, arena);
8782
_Py_LeaveRecursiveCall();
8783
Py_DECREF(tmp2);
8784
if (res != 0) goto failed;
8785
if (len != PyList_GET_SIZE(tmp)) {
8786
PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
8787
goto failed;
8788
}
8789
asdl_seq_SET(values, i, val);
8790
}
8791
Py_CLEAR(tmp);
8792
}
8793
*out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
8794
end_col_offset, arena);
8795
if (*out == NULL) goto failed;
8796
return 0;
8797
}
8798
tp = state->NamedExpr_type;
8799
isinstance = PyObject_IsInstance(obj, tp);
8800
if (isinstance == -1) {
8801
return 1;
8802
}
8803
if (isinstance) {
8804
expr_ty target;
8805
expr_ty value;
8806
8807
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
8808
return 1;
8809
}
8810
if (tmp == NULL) {
8811
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
8812
return 1;
8813
}
8814
else {
8815
int res;
8816
if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8817
goto failed;
8818
}
8819
res = obj2ast_expr(state, tmp, &target, arena);
8820
_Py_LeaveRecursiveCall();
8821
if (res != 0) goto failed;
8822
Py_CLEAR(tmp);
8823
}
8824
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8825
return 1;
8826
}
8827
if (tmp == NULL) {
8828
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
8829
return 1;
8830
}
8831
else {
8832
int res;
8833
if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8834
goto failed;
8835
}
8836
res = obj2ast_expr(state, tmp, &value, arena);
8837
_Py_LeaveRecursiveCall();
8838
if (res != 0) goto failed;
8839
Py_CLEAR(tmp);
8840
}
8841
*out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
8842
end_col_offset, arena);
8843
if (*out == NULL) goto failed;
8844
return 0;
8845
}
8846
tp = state->BinOp_type;
8847
isinstance = PyObject_IsInstance(obj, tp);
8848
if (isinstance == -1) {
8849
return 1;
8850
}
8851
if (isinstance) {
8852
expr_ty left;
8853
operator_ty op;
8854
expr_ty right;
8855
8856
if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
8857
return 1;
8858
}
8859
if (tmp == NULL) {
8860
PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
8861
return 1;
8862
}
8863
else {
8864
int res;
8865
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8866
goto failed;
8867
}
8868
res = obj2ast_expr(state, tmp, &left, arena);
8869
_Py_LeaveRecursiveCall();
8870
if (res != 0) goto failed;
8871
Py_CLEAR(tmp);
8872
}
8873
if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8874
return 1;
8875
}
8876
if (tmp == NULL) {
8877
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
8878
return 1;
8879
}
8880
else {
8881
int res;
8882
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8883
goto failed;
8884
}
8885
res = obj2ast_operator(state, tmp, &op, arena);
8886
_Py_LeaveRecursiveCall();
8887
if (res != 0) goto failed;
8888
Py_CLEAR(tmp);
8889
}
8890
if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
8891
return 1;
8892
}
8893
if (tmp == NULL) {
8894
PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
8895
return 1;
8896
}
8897
else {
8898
int res;
8899
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8900
goto failed;
8901
}
8902
res = obj2ast_expr(state, tmp, &right, arena);
8903
_Py_LeaveRecursiveCall();
8904
if (res != 0) goto failed;
8905
Py_CLEAR(tmp);
8906
}
8907
*out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
8908
end_col_offset, arena);
8909
if (*out == NULL) goto failed;
8910
return 0;
8911
}
8912
tp = state->UnaryOp_type;
8913
isinstance = PyObject_IsInstance(obj, tp);
8914
if (isinstance == -1) {
8915
return 1;
8916
}
8917
if (isinstance) {
8918
unaryop_ty op;
8919
expr_ty operand;
8920
8921
if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8922
return 1;
8923
}
8924
if (tmp == NULL) {
8925
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
8926
return 1;
8927
}
8928
else {
8929
int res;
8930
if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8931
goto failed;
8932
}
8933
res = obj2ast_unaryop(state, tmp, &op, arena);
8934
_Py_LeaveRecursiveCall();
8935
if (res != 0) goto failed;
8936
Py_CLEAR(tmp);
8937
}
8938
if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
8939
return 1;
8940
}
8941
if (tmp == NULL) {
8942
PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
8943
return 1;
8944
}
8945
else {
8946
int res;
8947
if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8948
goto failed;
8949
}
8950
res = obj2ast_expr(state, tmp, &operand, arena);
8951
_Py_LeaveRecursiveCall();
8952
if (res != 0) goto failed;
8953
Py_CLEAR(tmp);
8954
}
8955
*out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
8956
end_col_offset, arena);
8957
if (*out == NULL) goto failed;
8958
return 0;
8959
}
8960
tp = state->Lambda_type;
8961
isinstance = PyObject_IsInstance(obj, tp);
8962
if (isinstance == -1) {
8963
return 1;
8964
}
8965
if (isinstance) {
8966
arguments_ty args;
8967
expr_ty body;
8968
8969
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
8970
return 1;
8971
}
8972
if (tmp == NULL) {
8973
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
8974
return 1;
8975
}
8976
else {
8977
int res;
8978
if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8979
goto failed;
8980
}
8981
res = obj2ast_arguments(state, tmp, &args, arena);
8982
_Py_LeaveRecursiveCall();
8983
if (res != 0) goto failed;
8984
Py_CLEAR(tmp);
8985
}
8986
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8987
return 1;
8988
}
8989
if (tmp == NULL) {
8990
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
8991
return 1;
8992
}
8993
else {
8994
int res;
8995
if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8996
goto failed;
8997
}
8998
res = obj2ast_expr(state, tmp, &body, arena);
8999
_Py_LeaveRecursiveCall();
9000
if (res != 0) goto failed;
9001
Py_CLEAR(tmp);
9002
}
9003
*out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
9004
end_col_offset, arena);
9005
if (*out == NULL) goto failed;
9006
return 0;
9007
}
9008
tp = state->IfExp_type;
9009
isinstance = PyObject_IsInstance(obj, tp);
9010
if (isinstance == -1) {
9011
return 1;
9012
}
9013
if (isinstance) {
9014
expr_ty test;
9015
expr_ty body;
9016
expr_ty orelse;
9017
9018
if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
9019
return 1;
9020
}
9021
if (tmp == NULL) {
9022
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
9023
return 1;
9024
}
9025
else {
9026
int res;
9027
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
9028
goto failed;
9029
}
9030
res = obj2ast_expr(state, tmp, &test, arena);
9031
_Py_LeaveRecursiveCall();
9032
if (res != 0) goto failed;
9033
Py_CLEAR(tmp);
9034
}
9035
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
9036
return 1;
9037
}
9038
if (tmp == NULL) {
9039
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
9040
return 1;
9041
}
9042
else {
9043
int res;
9044
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
9045
goto failed;
9046
}
9047
res = obj2ast_expr(state, tmp, &body, arena);
9048
_Py_LeaveRecursiveCall();
9049
if (res != 0) goto failed;
9050
Py_CLEAR(tmp);
9051
}
9052
if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
9053
return 1;
9054
}
9055
if (tmp == NULL) {
9056
PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
9057
return 1;
9058
}
9059
else {
9060
int res;
9061
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
9062
goto failed;
9063
}
9064
res = obj2ast_expr(state, tmp, &orelse, arena);
9065
_Py_LeaveRecursiveCall();
9066
if (res != 0) goto failed;
9067
Py_CLEAR(tmp);
9068
}
9069
*out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
9070
end_col_offset, arena);
9071
if (*out == NULL) goto failed;
9072
return 0;
9073
}
9074
tp = state->Dict_type;
9075
isinstance = PyObject_IsInstance(obj, tp);
9076
if (isinstance == -1) {
9077
return 1;
9078
}
9079
if (isinstance) {
9080
asdl_expr_seq* keys;
9081
asdl_expr_seq* values;
9082
9083
if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
9084
return 1;
9085
}
9086
if (tmp == NULL) {
9087
tmp = PyList_New(0);
9088
if (tmp == NULL) {
9089
return 1;
9090
}
9091
}
9092
{
9093
int res;
9094
Py_ssize_t len;
9095
Py_ssize_t i;
9096
if (!PyList_Check(tmp)) {
9097
PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9098
goto failed;
9099
}
9100
len = PyList_GET_SIZE(tmp);
9101
keys = _Py_asdl_expr_seq_new(len, arena);
9102
if (keys == NULL) goto failed;
9103
for (i = 0; i < len; i++) {
9104
expr_ty val;
9105
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9106
if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
9107
goto failed;
9108
}
9109
res = obj2ast_expr(state, tmp2, &val, arena);
9110
_Py_LeaveRecursiveCall();
9111
Py_DECREF(tmp2);
9112
if (res != 0) goto failed;
9113
if (len != PyList_GET_SIZE(tmp)) {
9114
PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
9115
goto failed;
9116
}
9117
asdl_seq_SET(keys, i, val);
9118
}
9119
Py_CLEAR(tmp);
9120
}
9121
if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
9122
return 1;
9123
}
9124
if (tmp == NULL) {
9125
tmp = PyList_New(0);
9126
if (tmp == NULL) {
9127
return 1;
9128
}
9129
}
9130
{
9131
int res;
9132
Py_ssize_t len;
9133
Py_ssize_t i;
9134
if (!PyList_Check(tmp)) {
9135
PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9136
goto failed;
9137
}
9138
len = PyList_GET_SIZE(tmp);
9139
values = _Py_asdl_expr_seq_new(len, arena);
9140
if (values == NULL) goto failed;
9141
for (i = 0; i < len; i++) {
9142
expr_ty val;
9143
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9144
if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
9145
goto failed;
9146
}
9147
res = obj2ast_expr(state, tmp2, &val, arena);
9148
_Py_LeaveRecursiveCall();
9149
Py_DECREF(tmp2);
9150
if (res != 0) goto failed;
9151
if (len != PyList_GET_SIZE(tmp)) {
9152
PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
9153
goto failed;
9154
}
9155
asdl_seq_SET(values, i, val);
9156
}
9157
Py_CLEAR(tmp);
9158
}
9159
*out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
9160
end_col_offset, arena);
9161
if (*out == NULL) goto failed;
9162
return 0;
9163
}
9164
tp = state->Set_type;
9165
isinstance = PyObject_IsInstance(obj, tp);
9166
if (isinstance == -1) {
9167
return 1;
9168
}
9169
if (isinstance) {
9170
asdl_expr_seq* elts;
9171
9172
if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
9173
return 1;
9174
}
9175
if (tmp == NULL) {
9176
tmp = PyList_New(0);
9177
if (tmp == NULL) {
9178
return 1;
9179
}
9180
}
9181
{
9182
int res;
9183
Py_ssize_t len;
9184
Py_ssize_t i;
9185
if (!PyList_Check(tmp)) {
9186
PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9187
goto failed;
9188
}
9189
len = PyList_GET_SIZE(tmp);
9190
elts = _Py_asdl_expr_seq_new(len, arena);
9191
if (elts == NULL) goto failed;
9192
for (i = 0; i < len; i++) {
9193
expr_ty val;
9194
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9195
if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
9196
goto failed;
9197
}
9198
res = obj2ast_expr(state, tmp2, &val, arena);
9199
_Py_LeaveRecursiveCall();
9200
Py_DECREF(tmp2);
9201
if (res != 0) goto failed;
9202
if (len != PyList_GET_SIZE(tmp)) {
9203
PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
9204
goto failed;
9205
}
9206
asdl_seq_SET(elts, i, val);
9207
}
9208
Py_CLEAR(tmp);
9209
}
9210
*out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
9211
arena);
9212
if (*out == NULL) goto failed;
9213
return 0;
9214
}
9215
tp = state->ListComp_type;
9216
isinstance = PyObject_IsInstance(obj, tp);
9217
if (isinstance == -1) {
9218
return 1;
9219
}
9220
if (isinstance) {
9221
expr_ty elt;
9222
asdl_comprehension_seq* generators;
9223
9224
if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
9225
return 1;
9226
}
9227
if (tmp == NULL) {
9228
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
9229
return 1;
9230
}
9231
else {
9232
int res;
9233
if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
9234
goto failed;
9235
}
9236
res = obj2ast_expr(state, tmp, &elt, arena);
9237
_Py_LeaveRecursiveCall();
9238
if (res != 0) goto failed;
9239
Py_CLEAR(tmp);
9240
}
9241
if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
9242
return 1;
9243
}
9244
if (tmp == NULL) {
9245
tmp = PyList_New(0);
9246
if (tmp == NULL) {
9247
return 1;
9248
}
9249
}
9250
{
9251
int res;
9252
Py_ssize_t len;
9253
Py_ssize_t i;
9254
if (!PyList_Check(tmp)) {
9255
PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9256
goto failed;
9257
}
9258
len = PyList_GET_SIZE(tmp);
9259
generators = _Py_asdl_comprehension_seq_new(len, arena);
9260
if (generators == NULL) goto failed;
9261
for (i = 0; i < len; i++) {
9262
comprehension_ty val;
9263
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9264
if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
9265
goto failed;
9266
}
9267
res = obj2ast_comprehension(state, tmp2, &val, arena);
9268
_Py_LeaveRecursiveCall();
9269
Py_DECREF(tmp2);
9270
if (res != 0) goto failed;
9271
if (len != PyList_GET_SIZE(tmp)) {
9272
PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
9273
goto failed;
9274
}
9275
asdl_seq_SET(generators, i, val);
9276
}
9277
Py_CLEAR(tmp);
9278
}
9279
*out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
9280
end_col_offset, arena);
9281
if (*out == NULL) goto failed;
9282
return 0;
9283
}
9284
tp = state->SetComp_type;
9285
isinstance = PyObject_IsInstance(obj, tp);
9286
if (isinstance == -1) {
9287
return 1;
9288
}
9289
if (isinstance) {
9290
expr_ty elt;
9291
asdl_comprehension_seq* generators;
9292
9293
if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
9294
return 1;
9295
}
9296
if (tmp == NULL) {
9297
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
9298
return 1;
9299
}
9300
else {
9301
int res;
9302
if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
9303
goto failed;
9304
}
9305
res = obj2ast_expr(state, tmp, &elt, arena);
9306
_Py_LeaveRecursiveCall();
9307
if (res != 0) goto failed;
9308
Py_CLEAR(tmp);
9309
}
9310
if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
9311
return 1;
9312
}
9313
if (tmp == NULL) {
9314
tmp = PyList_New(0);
9315
if (tmp == NULL) {
9316
return 1;
9317
}
9318
}
9319
{
9320
int res;
9321
Py_ssize_t len;
9322
Py_ssize_t i;
9323
if (!PyList_Check(tmp)) {
9324
PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9325
goto failed;
9326
}
9327
len = PyList_GET_SIZE(tmp);
9328
generators = _Py_asdl_comprehension_seq_new(len, arena);
9329
if (generators == NULL) goto failed;
9330
for (i = 0; i < len; i++) {
9331
comprehension_ty val;
9332
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9333
if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
9334
goto failed;
9335
}
9336
res = obj2ast_comprehension(state, tmp2, &val, arena);
9337
_Py_LeaveRecursiveCall();
9338
Py_DECREF(tmp2);
9339
if (res != 0) goto failed;
9340
if (len != PyList_GET_SIZE(tmp)) {
9341
PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
9342
goto failed;
9343
}
9344
asdl_seq_SET(generators, i, val);
9345
}
9346
Py_CLEAR(tmp);
9347
}
9348
*out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
9349
end_col_offset, arena);
9350
if (*out == NULL) goto failed;
9351
return 0;
9352
}
9353
tp = state->DictComp_type;
9354
isinstance = PyObject_IsInstance(obj, tp);
9355
if (isinstance == -1) {
9356
return 1;
9357
}
9358
if (isinstance) {
9359
expr_ty key;
9360
expr_ty value;
9361
asdl_comprehension_seq* generators;
9362
9363
if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
9364
return 1;
9365
}
9366
if (tmp == NULL) {
9367
PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
9368
return 1;
9369
}
9370
else {
9371
int res;
9372
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
9373
goto failed;
9374
}
9375
res = obj2ast_expr(state, tmp, &key, arena);
9376
_Py_LeaveRecursiveCall();
9377
if (res != 0) goto failed;
9378
Py_CLEAR(tmp);
9379
}
9380
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9381
return 1;
9382
}
9383
if (tmp == NULL) {
9384
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
9385
return 1;
9386
}
9387
else {
9388
int res;
9389
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
9390
goto failed;
9391
}
9392
res = obj2ast_expr(state, tmp, &value, arena);
9393
_Py_LeaveRecursiveCall();
9394
if (res != 0) goto failed;
9395
Py_CLEAR(tmp);
9396
}
9397
if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
9398
return 1;
9399
}
9400
if (tmp == NULL) {
9401
tmp = PyList_New(0);
9402
if (tmp == NULL) {
9403
return 1;
9404
}
9405
}
9406
{
9407
int res;
9408
Py_ssize_t len;
9409
Py_ssize_t i;
9410
if (!PyList_Check(tmp)) {
9411
PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9412
goto failed;
9413
}
9414
len = PyList_GET_SIZE(tmp);
9415
generators = _Py_asdl_comprehension_seq_new(len, arena);
9416
if (generators == NULL) goto failed;
9417
for (i = 0; i < len; i++) {
9418
comprehension_ty val;
9419
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9420
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
9421
goto failed;
9422
}
9423
res = obj2ast_comprehension(state, tmp2, &val, arena);
9424
_Py_LeaveRecursiveCall();
9425
Py_DECREF(tmp2);
9426
if (res != 0) goto failed;
9427
if (len != PyList_GET_SIZE(tmp)) {
9428
PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
9429
goto failed;
9430
}
9431
asdl_seq_SET(generators, i, val);
9432
}
9433
Py_CLEAR(tmp);
9434
}
9435
*out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
9436
end_lineno, end_col_offset, arena);
9437
if (*out == NULL) goto failed;
9438
return 0;
9439
}
9440
tp = state->GeneratorExp_type;
9441
isinstance = PyObject_IsInstance(obj, tp);
9442
if (isinstance == -1) {
9443
return 1;
9444
}
9445
if (isinstance) {
9446
expr_ty elt;
9447
asdl_comprehension_seq* generators;
9448
9449
if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
9450
return 1;
9451
}
9452
if (tmp == NULL) {
9453
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
9454
return 1;
9455
}
9456
else {
9457
int res;
9458
if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
9459
goto failed;
9460
}
9461
res = obj2ast_expr(state, tmp, &elt, arena);
9462
_Py_LeaveRecursiveCall();
9463
if (res != 0) goto failed;
9464
Py_CLEAR(tmp);
9465
}
9466
if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
9467
return 1;
9468
}
9469
if (tmp == NULL) {
9470
tmp = PyList_New(0);
9471
if (tmp == NULL) {
9472
return 1;
9473
}
9474
}
9475
{
9476
int res;
9477
Py_ssize_t len;
9478
Py_ssize_t i;
9479
if (!PyList_Check(tmp)) {
9480
PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9481
goto failed;
9482
}
9483
len = PyList_GET_SIZE(tmp);
9484
generators = _Py_asdl_comprehension_seq_new(len, arena);
9485
if (generators == NULL) goto failed;
9486
for (i = 0; i < len; i++) {
9487
comprehension_ty val;
9488
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9489
if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
9490
goto failed;
9491
}
9492
res = obj2ast_comprehension(state, tmp2, &val, arena);
9493
_Py_LeaveRecursiveCall();
9494
Py_DECREF(tmp2);
9495
if (res != 0) goto failed;
9496
if (len != PyList_GET_SIZE(tmp)) {
9497
PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
9498
goto failed;
9499
}
9500
asdl_seq_SET(generators, i, val);
9501
}
9502
Py_CLEAR(tmp);
9503
}
9504
*out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
9505
end_lineno, end_col_offset, arena);
9506
if (*out == NULL) goto failed;
9507
return 0;
9508
}
9509
tp = state->Await_type;
9510
isinstance = PyObject_IsInstance(obj, tp);
9511
if (isinstance == -1) {
9512
return 1;
9513
}
9514
if (isinstance) {
9515
expr_ty value;
9516
9517
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9518
return 1;
9519
}
9520
if (tmp == NULL) {
9521
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
9522
return 1;
9523
}
9524
else {
9525
int res;
9526
if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
9527
goto failed;
9528
}
9529
res = obj2ast_expr(state, tmp, &value, arena);
9530
_Py_LeaveRecursiveCall();
9531
if (res != 0) goto failed;
9532
Py_CLEAR(tmp);
9533
}
9534
*out = _PyAST_Await(value, lineno, col_offset, end_lineno,
9535
end_col_offset, arena);
9536
if (*out == NULL) goto failed;
9537
return 0;
9538
}
9539
tp = state->Yield_type;
9540
isinstance = PyObject_IsInstance(obj, tp);
9541
if (isinstance == -1) {
9542
return 1;
9543
}
9544
if (isinstance) {
9545
expr_ty value;
9546
9547
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9548
return 1;
9549
}
9550
if (tmp == NULL || tmp == Py_None) {
9551
Py_CLEAR(tmp);
9552
value = NULL;
9553
}
9554
else {
9555
int res;
9556
if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
9557
goto failed;
9558
}
9559
res = obj2ast_expr(state, tmp, &value, arena);
9560
_Py_LeaveRecursiveCall();
9561
if (res != 0) goto failed;
9562
Py_CLEAR(tmp);
9563
}
9564
*out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
9565
end_col_offset, arena);
9566
if (*out == NULL) goto failed;
9567
return 0;
9568
}
9569
tp = state->YieldFrom_type;
9570
isinstance = PyObject_IsInstance(obj, tp);
9571
if (isinstance == -1) {
9572
return 1;
9573
}
9574
if (isinstance) {
9575
expr_ty value;
9576
9577
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9578
return 1;
9579
}
9580
if (tmp == NULL) {
9581
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
9582
return 1;
9583
}
9584
else {
9585
int res;
9586
if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
9587
goto failed;
9588
}
9589
res = obj2ast_expr(state, tmp, &value, arena);
9590
_Py_LeaveRecursiveCall();
9591
if (res != 0) goto failed;
9592
Py_CLEAR(tmp);
9593
}
9594
*out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
9595
end_col_offset, arena);
9596
if (*out == NULL) goto failed;
9597
return 0;
9598
}
9599
tp = state->Compare_type;
9600
isinstance = PyObject_IsInstance(obj, tp);
9601
if (isinstance == -1) {
9602
return 1;
9603
}
9604
if (isinstance) {
9605
expr_ty left;
9606
asdl_int_seq* ops;
9607
asdl_expr_seq* comparators;
9608
9609
if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
9610
return 1;
9611
}
9612
if (tmp == NULL) {
9613
PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
9614
return 1;
9615
}
9616
else {
9617
int res;
9618
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9619
goto failed;
9620
}
9621
res = obj2ast_expr(state, tmp, &left, arena);
9622
_Py_LeaveRecursiveCall();
9623
if (res != 0) goto failed;
9624
Py_CLEAR(tmp);
9625
}
9626
if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
9627
return 1;
9628
}
9629
if (tmp == NULL) {
9630
tmp = PyList_New(0);
9631
if (tmp == NULL) {
9632
return 1;
9633
}
9634
}
9635
{
9636
int res;
9637
Py_ssize_t len;
9638
Py_ssize_t i;
9639
if (!PyList_Check(tmp)) {
9640
PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9641
goto failed;
9642
}
9643
len = PyList_GET_SIZE(tmp);
9644
ops = _Py_asdl_int_seq_new(len, arena);
9645
if (ops == NULL) goto failed;
9646
for (i = 0; i < len; i++) {
9647
cmpop_ty val;
9648
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9649
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9650
goto failed;
9651
}
9652
res = obj2ast_cmpop(state, tmp2, &val, arena);
9653
_Py_LeaveRecursiveCall();
9654
Py_DECREF(tmp2);
9655
if (res != 0) goto failed;
9656
if (len != PyList_GET_SIZE(tmp)) {
9657
PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
9658
goto failed;
9659
}
9660
asdl_seq_SET(ops, i, val);
9661
}
9662
Py_CLEAR(tmp);
9663
}
9664
if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
9665
return 1;
9666
}
9667
if (tmp == NULL) {
9668
tmp = PyList_New(0);
9669
if (tmp == NULL) {
9670
return 1;
9671
}
9672
}
9673
{
9674
int res;
9675
Py_ssize_t len;
9676
Py_ssize_t i;
9677
if (!PyList_Check(tmp)) {
9678
PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9679
goto failed;
9680
}
9681
len = PyList_GET_SIZE(tmp);
9682
comparators = _Py_asdl_expr_seq_new(len, arena);
9683
if (comparators == NULL) goto failed;
9684
for (i = 0; i < len; i++) {
9685
expr_ty val;
9686
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9687
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9688
goto failed;
9689
}
9690
res = obj2ast_expr(state, tmp2, &val, arena);
9691
_Py_LeaveRecursiveCall();
9692
Py_DECREF(tmp2);
9693
if (res != 0) goto failed;
9694
if (len != PyList_GET_SIZE(tmp)) {
9695
PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
9696
goto failed;
9697
}
9698
asdl_seq_SET(comparators, i, val);
9699
}
9700
Py_CLEAR(tmp);
9701
}
9702
*out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
9703
end_lineno, end_col_offset, arena);
9704
if (*out == NULL) goto failed;
9705
return 0;
9706
}
9707
tp = state->Call_type;
9708
isinstance = PyObject_IsInstance(obj, tp);
9709
if (isinstance == -1) {
9710
return 1;
9711
}
9712
if (isinstance) {
9713
expr_ty func;
9714
asdl_expr_seq* args;
9715
asdl_keyword_seq* keywords;
9716
9717
if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
9718
return 1;
9719
}
9720
if (tmp == NULL) {
9721
PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
9722
return 1;
9723
}
9724
else {
9725
int res;
9726
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9727
goto failed;
9728
}
9729
res = obj2ast_expr(state, tmp, &func, arena);
9730
_Py_LeaveRecursiveCall();
9731
if (res != 0) goto failed;
9732
Py_CLEAR(tmp);
9733
}
9734
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
9735
return 1;
9736
}
9737
if (tmp == NULL) {
9738
tmp = PyList_New(0);
9739
if (tmp == NULL) {
9740
return 1;
9741
}
9742
}
9743
{
9744
int res;
9745
Py_ssize_t len;
9746
Py_ssize_t i;
9747
if (!PyList_Check(tmp)) {
9748
PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9749
goto failed;
9750
}
9751
len = PyList_GET_SIZE(tmp);
9752
args = _Py_asdl_expr_seq_new(len, arena);
9753
if (args == NULL) goto failed;
9754
for (i = 0; i < len; i++) {
9755
expr_ty val;
9756
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9757
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9758
goto failed;
9759
}
9760
res = obj2ast_expr(state, tmp2, &val, arena);
9761
_Py_LeaveRecursiveCall();
9762
Py_DECREF(tmp2);
9763
if (res != 0) goto failed;
9764
if (len != PyList_GET_SIZE(tmp)) {
9765
PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
9766
goto failed;
9767
}
9768
asdl_seq_SET(args, i, val);
9769
}
9770
Py_CLEAR(tmp);
9771
}
9772
if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
9773
return 1;
9774
}
9775
if (tmp == NULL) {
9776
tmp = PyList_New(0);
9777
if (tmp == NULL) {
9778
return 1;
9779
}
9780
}
9781
{
9782
int res;
9783
Py_ssize_t len;
9784
Py_ssize_t i;
9785
if (!PyList_Check(tmp)) {
9786
PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9787
goto failed;
9788
}
9789
len = PyList_GET_SIZE(tmp);
9790
keywords = _Py_asdl_keyword_seq_new(len, arena);
9791
if (keywords == NULL) goto failed;
9792
for (i = 0; i < len; i++) {
9793
keyword_ty val;
9794
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9795
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9796
goto failed;
9797
}
9798
res = obj2ast_keyword(state, tmp2, &val, arena);
9799
_Py_LeaveRecursiveCall();
9800
Py_DECREF(tmp2);
9801
if (res != 0) goto failed;
9802
if (len != PyList_GET_SIZE(tmp)) {
9803
PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
9804
goto failed;
9805
}
9806
asdl_seq_SET(keywords, i, val);
9807
}
9808
Py_CLEAR(tmp);
9809
}
9810
*out = _PyAST_Call(func, args, keywords, lineno, col_offset,
9811
end_lineno, end_col_offset, arena);
9812
if (*out == NULL) goto failed;
9813
return 0;
9814
}
9815
tp = state->FormattedValue_type;
9816
isinstance = PyObject_IsInstance(obj, tp);
9817
if (isinstance == -1) {
9818
return 1;
9819
}
9820
if (isinstance) {
9821
expr_ty value;
9822
int conversion;
9823
expr_ty format_spec;
9824
9825
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9826
return 1;
9827
}
9828
if (tmp == NULL) {
9829
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
9830
return 1;
9831
}
9832
else {
9833
int res;
9834
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9835
goto failed;
9836
}
9837
res = obj2ast_expr(state, tmp, &value, arena);
9838
_Py_LeaveRecursiveCall();
9839
if (res != 0) goto failed;
9840
Py_CLEAR(tmp);
9841
}
9842
if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
9843
return 1;
9844
}
9845
if (tmp == NULL) {
9846
PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
9847
return 1;
9848
}
9849
else {
9850
int res;
9851
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9852
goto failed;
9853
}
9854
res = obj2ast_int(state, tmp, &conversion, arena);
9855
_Py_LeaveRecursiveCall();
9856
if (res != 0) goto failed;
9857
Py_CLEAR(tmp);
9858
}
9859
if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
9860
return 1;
9861
}
9862
if (tmp == NULL || tmp == Py_None) {
9863
Py_CLEAR(tmp);
9864
format_spec = NULL;
9865
}
9866
else {
9867
int res;
9868
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9869
goto failed;
9870
}
9871
res = obj2ast_expr(state, tmp, &format_spec, arena);
9872
_Py_LeaveRecursiveCall();
9873
if (res != 0) goto failed;
9874
Py_CLEAR(tmp);
9875
}
9876
*out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
9877
col_offset, end_lineno, end_col_offset,
9878
arena);
9879
if (*out == NULL) goto failed;
9880
return 0;
9881
}
9882
tp = state->JoinedStr_type;
9883
isinstance = PyObject_IsInstance(obj, tp);
9884
if (isinstance == -1) {
9885
return 1;
9886
}
9887
if (isinstance) {
9888
asdl_expr_seq* values;
9889
9890
if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
9891
return 1;
9892
}
9893
if (tmp == NULL) {
9894
tmp = PyList_New(0);
9895
if (tmp == NULL) {
9896
return 1;
9897
}
9898
}
9899
{
9900
int res;
9901
Py_ssize_t len;
9902
Py_ssize_t i;
9903
if (!PyList_Check(tmp)) {
9904
PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9905
goto failed;
9906
}
9907
len = PyList_GET_SIZE(tmp);
9908
values = _Py_asdl_expr_seq_new(len, arena);
9909
if (values == NULL) goto failed;
9910
for (i = 0; i < len; i++) {
9911
expr_ty val;
9912
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
9913
if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
9914
goto failed;
9915
}
9916
res = obj2ast_expr(state, tmp2, &val, arena);
9917
_Py_LeaveRecursiveCall();
9918
Py_DECREF(tmp2);
9919
if (res != 0) goto failed;
9920
if (len != PyList_GET_SIZE(tmp)) {
9921
PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
9922
goto failed;
9923
}
9924
asdl_seq_SET(values, i, val);
9925
}
9926
Py_CLEAR(tmp);
9927
}
9928
*out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
9929
end_col_offset, arena);
9930
if (*out == NULL) goto failed;
9931
return 0;
9932
}
9933
tp = state->Constant_type;
9934
isinstance = PyObject_IsInstance(obj, tp);
9935
if (isinstance == -1) {
9936
return 1;
9937
}
9938
if (isinstance) {
9939
constant value;
9940
string kind;
9941
9942
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9943
return 1;
9944
}
9945
if (tmp == NULL) {
9946
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
9947
return 1;
9948
}
9949
else {
9950
int res;
9951
if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9952
goto failed;
9953
}
9954
res = obj2ast_constant(state, tmp, &value, arena);
9955
_Py_LeaveRecursiveCall();
9956
if (res != 0) goto failed;
9957
Py_CLEAR(tmp);
9958
}
9959
if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
9960
return 1;
9961
}
9962
if (tmp == NULL || tmp == Py_None) {
9963
Py_CLEAR(tmp);
9964
kind = NULL;
9965
}
9966
else {
9967
int res;
9968
if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9969
goto failed;
9970
}
9971
res = obj2ast_string(state, tmp, &kind, arena);
9972
_Py_LeaveRecursiveCall();
9973
if (res != 0) goto failed;
9974
Py_CLEAR(tmp);
9975
}
9976
*out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
9977
end_col_offset, arena);
9978
if (*out == NULL) goto failed;
9979
return 0;
9980
}
9981
tp = state->Attribute_type;
9982
isinstance = PyObject_IsInstance(obj, tp);
9983
if (isinstance == -1) {
9984
return 1;
9985
}
9986
if (isinstance) {
9987
expr_ty value;
9988
identifier attr;
9989
expr_context_ty ctx;
9990
9991
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9992
return 1;
9993
}
9994
if (tmp == NULL) {
9995
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
9996
return 1;
9997
}
9998
else {
9999
int res;
10000
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
10001
goto failed;
10002
}
10003
res = obj2ast_expr(state, tmp, &value, arena);
10004
_Py_LeaveRecursiveCall();
10005
if (res != 0) goto failed;
10006
Py_CLEAR(tmp);
10007
}
10008
if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
10009
return 1;
10010
}
10011
if (tmp == NULL) {
10012
PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
10013
return 1;
10014
}
10015
else {
10016
int res;
10017
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
10018
goto failed;
10019
}
10020
res = obj2ast_identifier(state, tmp, &attr, arena);
10021
_Py_LeaveRecursiveCall();
10022
if (res != 0) goto failed;
10023
Py_CLEAR(tmp);
10024
}
10025
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10026
return 1;
10027
}
10028
if (tmp == NULL) {
10029
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
10030
return 1;
10031
}
10032
else {
10033
int res;
10034
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
10035
goto failed;
10036
}
10037
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10038
_Py_LeaveRecursiveCall();
10039
if (res != 0) goto failed;
10040
Py_CLEAR(tmp);
10041
}
10042
*out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
10043
end_lineno, end_col_offset, arena);
10044
if (*out == NULL) goto failed;
10045
return 0;
10046
}
10047
tp = state->Subscript_type;
10048
isinstance = PyObject_IsInstance(obj, tp);
10049
if (isinstance == -1) {
10050
return 1;
10051
}
10052
if (isinstance) {
10053
expr_ty value;
10054
expr_ty slice;
10055
expr_context_ty ctx;
10056
10057
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
10058
return 1;
10059
}
10060
if (tmp == NULL) {
10061
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
10062
return 1;
10063
}
10064
else {
10065
int res;
10066
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
10067
goto failed;
10068
}
10069
res = obj2ast_expr(state, tmp, &value, arena);
10070
_Py_LeaveRecursiveCall();
10071
if (res != 0) goto failed;
10072
Py_CLEAR(tmp);
10073
}
10074
if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
10075
return 1;
10076
}
10077
if (tmp == NULL) {
10078
PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
10079
return 1;
10080
}
10081
else {
10082
int res;
10083
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
10084
goto failed;
10085
}
10086
res = obj2ast_expr(state, tmp, &slice, arena);
10087
_Py_LeaveRecursiveCall();
10088
if (res != 0) goto failed;
10089
Py_CLEAR(tmp);
10090
}
10091
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10092
return 1;
10093
}
10094
if (tmp == NULL) {
10095
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
10096
return 1;
10097
}
10098
else {
10099
int res;
10100
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
10101
goto failed;
10102
}
10103
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10104
_Py_LeaveRecursiveCall();
10105
if (res != 0) goto failed;
10106
Py_CLEAR(tmp);
10107
}
10108
*out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
10109
end_lineno, end_col_offset, arena);
10110
if (*out == NULL) goto failed;
10111
return 0;
10112
}
10113
tp = state->Starred_type;
10114
isinstance = PyObject_IsInstance(obj, tp);
10115
if (isinstance == -1) {
10116
return 1;
10117
}
10118
if (isinstance) {
10119
expr_ty value;
10120
expr_context_ty ctx;
10121
10122
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
10123
return 1;
10124
}
10125
if (tmp == NULL) {
10126
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
10127
return 1;
10128
}
10129
else {
10130
int res;
10131
if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
10132
goto failed;
10133
}
10134
res = obj2ast_expr(state, tmp, &value, arena);
10135
_Py_LeaveRecursiveCall();
10136
if (res != 0) goto failed;
10137
Py_CLEAR(tmp);
10138
}
10139
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10140
return 1;
10141
}
10142
if (tmp == NULL) {
10143
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
10144
return 1;
10145
}
10146
else {
10147
int res;
10148
if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
10149
goto failed;
10150
}
10151
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10152
_Py_LeaveRecursiveCall();
10153
if (res != 0) goto failed;
10154
Py_CLEAR(tmp);
10155
}
10156
*out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
10157
end_col_offset, arena);
10158
if (*out == NULL) goto failed;
10159
return 0;
10160
}
10161
tp = state->Name_type;
10162
isinstance = PyObject_IsInstance(obj, tp);
10163
if (isinstance == -1) {
10164
return 1;
10165
}
10166
if (isinstance) {
10167
identifier id;
10168
expr_context_ty ctx;
10169
10170
if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
10171
return 1;
10172
}
10173
if (tmp == NULL) {
10174
PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
10175
return 1;
10176
}
10177
else {
10178
int res;
10179
if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
10180
goto failed;
10181
}
10182
res = obj2ast_identifier(state, tmp, &id, arena);
10183
_Py_LeaveRecursiveCall();
10184
if (res != 0) goto failed;
10185
Py_CLEAR(tmp);
10186
}
10187
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10188
return 1;
10189
}
10190
if (tmp == NULL) {
10191
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
10192
return 1;
10193
}
10194
else {
10195
int res;
10196
if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
10197
goto failed;
10198
}
10199
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10200
_Py_LeaveRecursiveCall();
10201
if (res != 0) goto failed;
10202
Py_CLEAR(tmp);
10203
}
10204
*out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
10205
end_col_offset, arena);
10206
if (*out == NULL) goto failed;
10207
return 0;
10208
}
10209
tp = state->List_type;
10210
isinstance = PyObject_IsInstance(obj, tp);
10211
if (isinstance == -1) {
10212
return 1;
10213
}
10214
if (isinstance) {
10215
asdl_expr_seq* elts;
10216
expr_context_ty ctx;
10217
10218
if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
10219
return 1;
10220
}
10221
if (tmp == NULL) {
10222
tmp = PyList_New(0);
10223
if (tmp == NULL) {
10224
return 1;
10225
}
10226
}
10227
{
10228
int res;
10229
Py_ssize_t len;
10230
Py_ssize_t i;
10231
if (!PyList_Check(tmp)) {
10232
PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10233
goto failed;
10234
}
10235
len = PyList_GET_SIZE(tmp);
10236
elts = _Py_asdl_expr_seq_new(len, arena);
10237
if (elts == NULL) goto failed;
10238
for (i = 0; i < len; i++) {
10239
expr_ty val;
10240
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10241
if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
10242
goto failed;
10243
}
10244
res = obj2ast_expr(state, tmp2, &val, arena);
10245
_Py_LeaveRecursiveCall();
10246
Py_DECREF(tmp2);
10247
if (res != 0) goto failed;
10248
if (len != PyList_GET_SIZE(tmp)) {
10249
PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
10250
goto failed;
10251
}
10252
asdl_seq_SET(elts, i, val);
10253
}
10254
Py_CLEAR(tmp);
10255
}
10256
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10257
return 1;
10258
}
10259
if (tmp == NULL) {
10260
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
10261
return 1;
10262
}
10263
else {
10264
int res;
10265
if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
10266
goto failed;
10267
}
10268
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10269
_Py_LeaveRecursiveCall();
10270
if (res != 0) goto failed;
10271
Py_CLEAR(tmp);
10272
}
10273
*out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
10274
end_col_offset, arena);
10275
if (*out == NULL) goto failed;
10276
return 0;
10277
}
10278
tp = state->Tuple_type;
10279
isinstance = PyObject_IsInstance(obj, tp);
10280
if (isinstance == -1) {
10281
return 1;
10282
}
10283
if (isinstance) {
10284
asdl_expr_seq* elts;
10285
expr_context_ty ctx;
10286
10287
if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
10288
return 1;
10289
}
10290
if (tmp == NULL) {
10291
tmp = PyList_New(0);
10292
if (tmp == NULL) {
10293
return 1;
10294
}
10295
}
10296
{
10297
int res;
10298
Py_ssize_t len;
10299
Py_ssize_t i;
10300
if (!PyList_Check(tmp)) {
10301
PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10302
goto failed;
10303
}
10304
len = PyList_GET_SIZE(tmp);
10305
elts = _Py_asdl_expr_seq_new(len, arena);
10306
if (elts == NULL) goto failed;
10307
for (i = 0; i < len; i++) {
10308
expr_ty val;
10309
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10310
if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
10311
goto failed;
10312
}
10313
res = obj2ast_expr(state, tmp2, &val, arena);
10314
_Py_LeaveRecursiveCall();
10315
Py_DECREF(tmp2);
10316
if (res != 0) goto failed;
10317
if (len != PyList_GET_SIZE(tmp)) {
10318
PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
10319
goto failed;
10320
}
10321
asdl_seq_SET(elts, i, val);
10322
}
10323
Py_CLEAR(tmp);
10324
}
10325
if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
10326
return 1;
10327
}
10328
if (tmp == NULL) {
10329
PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
10330
return 1;
10331
}
10332
else {
10333
int res;
10334
if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
10335
goto failed;
10336
}
10337
res = obj2ast_expr_context(state, tmp, &ctx, arena);
10338
_Py_LeaveRecursiveCall();
10339
if (res != 0) goto failed;
10340
Py_CLEAR(tmp);
10341
}
10342
*out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
10343
end_col_offset, arena);
10344
if (*out == NULL) goto failed;
10345
return 0;
10346
}
10347
tp = state->Slice_type;
10348
isinstance = PyObject_IsInstance(obj, tp);
10349
if (isinstance == -1) {
10350
return 1;
10351
}
10352
if (isinstance) {
10353
expr_ty lower;
10354
expr_ty upper;
10355
expr_ty step;
10356
10357
if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
10358
return 1;
10359
}
10360
if (tmp == NULL || tmp == Py_None) {
10361
Py_CLEAR(tmp);
10362
lower = NULL;
10363
}
10364
else {
10365
int res;
10366
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
10367
goto failed;
10368
}
10369
res = obj2ast_expr(state, tmp, &lower, arena);
10370
_Py_LeaveRecursiveCall();
10371
if (res != 0) goto failed;
10372
Py_CLEAR(tmp);
10373
}
10374
if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
10375
return 1;
10376
}
10377
if (tmp == NULL || tmp == Py_None) {
10378
Py_CLEAR(tmp);
10379
upper = NULL;
10380
}
10381
else {
10382
int res;
10383
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
10384
goto failed;
10385
}
10386
res = obj2ast_expr(state, tmp, &upper, arena);
10387
_Py_LeaveRecursiveCall();
10388
if (res != 0) goto failed;
10389
Py_CLEAR(tmp);
10390
}
10391
if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
10392
return 1;
10393
}
10394
if (tmp == NULL || tmp == Py_None) {
10395
Py_CLEAR(tmp);
10396
step = NULL;
10397
}
10398
else {
10399
int res;
10400
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
10401
goto failed;
10402
}
10403
res = obj2ast_expr(state, tmp, &step, arena);
10404
_Py_LeaveRecursiveCall();
10405
if (res != 0) goto failed;
10406
Py_CLEAR(tmp);
10407
}
10408
*out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
10409
end_col_offset, arena);
10410
if (*out == NULL) goto failed;
10411
return 0;
10412
}
10413
10414
PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
10415
failed:
10416
Py_XDECREF(tmp);
10417
return 1;
10418
}
10419
10420
int
10421
obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
10422
out, PyArena* arena)
10423
{
10424
int isinstance;
10425
10426
isinstance = PyObject_IsInstance(obj, state->Load_type);
10427
if (isinstance == -1) {
10428
return 1;
10429
}
10430
if (isinstance) {
10431
*out = Load;
10432
return 0;
10433
}
10434
isinstance = PyObject_IsInstance(obj, state->Store_type);
10435
if (isinstance == -1) {
10436
return 1;
10437
}
10438
if (isinstance) {
10439
*out = Store;
10440
return 0;
10441
}
10442
isinstance = PyObject_IsInstance(obj, state->Del_type);
10443
if (isinstance == -1) {
10444
return 1;
10445
}
10446
if (isinstance) {
10447
*out = Del;
10448
return 0;
10449
}
10450
10451
PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
10452
return 1;
10453
}
10454
10455
int
10456
obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
10457
arena)
10458
{
10459
int isinstance;
10460
10461
isinstance = PyObject_IsInstance(obj, state->And_type);
10462
if (isinstance == -1) {
10463
return 1;
10464
}
10465
if (isinstance) {
10466
*out = And;
10467
return 0;
10468
}
10469
isinstance = PyObject_IsInstance(obj, state->Or_type);
10470
if (isinstance == -1) {
10471
return 1;
10472
}
10473
if (isinstance) {
10474
*out = Or;
10475
return 0;
10476
}
10477
10478
PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
10479
return 1;
10480
}
10481
10482
int
10483
obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
10484
PyArena* arena)
10485
{
10486
int isinstance;
10487
10488
isinstance = PyObject_IsInstance(obj, state->Add_type);
10489
if (isinstance == -1) {
10490
return 1;
10491
}
10492
if (isinstance) {
10493
*out = Add;
10494
return 0;
10495
}
10496
isinstance = PyObject_IsInstance(obj, state->Sub_type);
10497
if (isinstance == -1) {
10498
return 1;
10499
}
10500
if (isinstance) {
10501
*out = Sub;
10502
return 0;
10503
}
10504
isinstance = PyObject_IsInstance(obj, state->Mult_type);
10505
if (isinstance == -1) {
10506
return 1;
10507
}
10508
if (isinstance) {
10509
*out = Mult;
10510
return 0;
10511
}
10512
isinstance = PyObject_IsInstance(obj, state->MatMult_type);
10513
if (isinstance == -1) {
10514
return 1;
10515
}
10516
if (isinstance) {
10517
*out = MatMult;
10518
return 0;
10519
}
10520
isinstance = PyObject_IsInstance(obj, state->Div_type);
10521
if (isinstance == -1) {
10522
return 1;
10523
}
10524
if (isinstance) {
10525
*out = Div;
10526
return 0;
10527
}
10528
isinstance = PyObject_IsInstance(obj, state->Mod_type);
10529
if (isinstance == -1) {
10530
return 1;
10531
}
10532
if (isinstance) {
10533
*out = Mod;
10534
return 0;
10535
}
10536
isinstance = PyObject_IsInstance(obj, state->Pow_type);
10537
if (isinstance == -1) {
10538
return 1;
10539
}
10540
if (isinstance) {
10541
*out = Pow;
10542
return 0;
10543
}
10544
isinstance = PyObject_IsInstance(obj, state->LShift_type);
10545
if (isinstance == -1) {
10546
return 1;
10547
}
10548
if (isinstance) {
10549
*out = LShift;
10550
return 0;
10551
}
10552
isinstance = PyObject_IsInstance(obj, state->RShift_type);
10553
if (isinstance == -1) {
10554
return 1;
10555
}
10556
if (isinstance) {
10557
*out = RShift;
10558
return 0;
10559
}
10560
isinstance = PyObject_IsInstance(obj, state->BitOr_type);
10561
if (isinstance == -1) {
10562
return 1;
10563
}
10564
if (isinstance) {
10565
*out = BitOr;
10566
return 0;
10567
}
10568
isinstance = PyObject_IsInstance(obj, state->BitXor_type);
10569
if (isinstance == -1) {
10570
return 1;
10571
}
10572
if (isinstance) {
10573
*out = BitXor;
10574
return 0;
10575
}
10576
isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
10577
if (isinstance == -1) {
10578
return 1;
10579
}
10580
if (isinstance) {
10581
*out = BitAnd;
10582
return 0;
10583
}
10584
isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
10585
if (isinstance == -1) {
10586
return 1;
10587
}
10588
if (isinstance) {
10589
*out = FloorDiv;
10590
return 0;
10591
}
10592
10593
PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
10594
return 1;
10595
}
10596
10597
int
10598
obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
10599
PyArena* arena)
10600
{
10601
int isinstance;
10602
10603
isinstance = PyObject_IsInstance(obj, state->Invert_type);
10604
if (isinstance == -1) {
10605
return 1;
10606
}
10607
if (isinstance) {
10608
*out = Invert;
10609
return 0;
10610
}
10611
isinstance = PyObject_IsInstance(obj, state->Not_type);
10612
if (isinstance == -1) {
10613
return 1;
10614
}
10615
if (isinstance) {
10616
*out = Not;
10617
return 0;
10618
}
10619
isinstance = PyObject_IsInstance(obj, state->UAdd_type);
10620
if (isinstance == -1) {
10621
return 1;
10622
}
10623
if (isinstance) {
10624
*out = UAdd;
10625
return 0;
10626
}
10627
isinstance = PyObject_IsInstance(obj, state->USub_type);
10628
if (isinstance == -1) {
10629
return 1;
10630
}
10631
if (isinstance) {
10632
*out = USub;
10633
return 0;
10634
}
10635
10636
PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
10637
return 1;
10638
}
10639
10640
int
10641
obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
10642
arena)
10643
{
10644
int isinstance;
10645
10646
isinstance = PyObject_IsInstance(obj, state->Eq_type);
10647
if (isinstance == -1) {
10648
return 1;
10649
}
10650
if (isinstance) {
10651
*out = Eq;
10652
return 0;
10653
}
10654
isinstance = PyObject_IsInstance(obj, state->NotEq_type);
10655
if (isinstance == -1) {
10656
return 1;
10657
}
10658
if (isinstance) {
10659
*out = NotEq;
10660
return 0;
10661
}
10662
isinstance = PyObject_IsInstance(obj, state->Lt_type);
10663
if (isinstance == -1) {
10664
return 1;
10665
}
10666
if (isinstance) {
10667
*out = Lt;
10668
return 0;
10669
}
10670
isinstance = PyObject_IsInstance(obj, state->LtE_type);
10671
if (isinstance == -1) {
10672
return 1;
10673
}
10674
if (isinstance) {
10675
*out = LtE;
10676
return 0;
10677
}
10678
isinstance = PyObject_IsInstance(obj, state->Gt_type);
10679
if (isinstance == -1) {
10680
return 1;
10681
}
10682
if (isinstance) {
10683
*out = Gt;
10684
return 0;
10685
}
10686
isinstance = PyObject_IsInstance(obj, state->GtE_type);
10687
if (isinstance == -1) {
10688
return 1;
10689
}
10690
if (isinstance) {
10691
*out = GtE;
10692
return 0;
10693
}
10694
isinstance = PyObject_IsInstance(obj, state->Is_type);
10695
if (isinstance == -1) {
10696
return 1;
10697
}
10698
if (isinstance) {
10699
*out = Is;
10700
return 0;
10701
}
10702
isinstance = PyObject_IsInstance(obj, state->IsNot_type);
10703
if (isinstance == -1) {
10704
return 1;
10705
}
10706
if (isinstance) {
10707
*out = IsNot;
10708
return 0;
10709
}
10710
isinstance = PyObject_IsInstance(obj, state->In_type);
10711
if (isinstance == -1) {
10712
return 1;
10713
}
10714
if (isinstance) {
10715
*out = In;
10716
return 0;
10717
}
10718
isinstance = PyObject_IsInstance(obj, state->NotIn_type);
10719
if (isinstance == -1) {
10720
return 1;
10721
}
10722
if (isinstance) {
10723
*out = NotIn;
10724
return 0;
10725
}
10726
10727
PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
10728
return 1;
10729
}
10730
10731
int
10732
obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
10733
out, PyArena* arena)
10734
{
10735
PyObject* tmp = NULL;
10736
expr_ty target;
10737
expr_ty iter;
10738
asdl_expr_seq* ifs;
10739
int is_async;
10740
10741
if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
10742
return 1;
10743
}
10744
if (tmp == NULL) {
10745
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
10746
return 1;
10747
}
10748
else {
10749
int res;
10750
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10751
goto failed;
10752
}
10753
res = obj2ast_expr(state, tmp, &target, arena);
10754
_Py_LeaveRecursiveCall();
10755
if (res != 0) goto failed;
10756
Py_CLEAR(tmp);
10757
}
10758
if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
10759
return 1;
10760
}
10761
if (tmp == NULL) {
10762
PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
10763
return 1;
10764
}
10765
else {
10766
int res;
10767
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10768
goto failed;
10769
}
10770
res = obj2ast_expr(state, tmp, &iter, arena);
10771
_Py_LeaveRecursiveCall();
10772
if (res != 0) goto failed;
10773
Py_CLEAR(tmp);
10774
}
10775
if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
10776
return 1;
10777
}
10778
if (tmp == NULL) {
10779
tmp = PyList_New(0);
10780
if (tmp == NULL) {
10781
return 1;
10782
}
10783
}
10784
{
10785
int res;
10786
Py_ssize_t len;
10787
Py_ssize_t i;
10788
if (!PyList_Check(tmp)) {
10789
PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10790
goto failed;
10791
}
10792
len = PyList_GET_SIZE(tmp);
10793
ifs = _Py_asdl_expr_seq_new(len, arena);
10794
if (ifs == NULL) goto failed;
10795
for (i = 0; i < len; i++) {
10796
expr_ty val;
10797
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10798
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10799
goto failed;
10800
}
10801
res = obj2ast_expr(state, tmp2, &val, arena);
10802
_Py_LeaveRecursiveCall();
10803
Py_DECREF(tmp2);
10804
if (res != 0) goto failed;
10805
if (len != PyList_GET_SIZE(tmp)) {
10806
PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
10807
goto failed;
10808
}
10809
asdl_seq_SET(ifs, i, val);
10810
}
10811
Py_CLEAR(tmp);
10812
}
10813
if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
10814
return 1;
10815
}
10816
if (tmp == NULL) {
10817
PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
10818
return 1;
10819
}
10820
else {
10821
int res;
10822
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10823
goto failed;
10824
}
10825
res = obj2ast_int(state, tmp, &is_async, arena);
10826
_Py_LeaveRecursiveCall();
10827
if (res != 0) goto failed;
10828
Py_CLEAR(tmp);
10829
}
10830
*out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
10831
if (*out == NULL) goto failed;
10832
return 0;
10833
failed:
10834
Py_XDECREF(tmp);
10835
return 1;
10836
}
10837
10838
int
10839
obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
10840
out, PyArena* arena)
10841
{
10842
int isinstance;
10843
10844
PyObject *tmp = NULL;
10845
PyObject *tp;
10846
int lineno;
10847
int col_offset;
10848
int end_lineno;
10849
int end_col_offset;
10850
10851
if (obj == Py_None) {
10852
*out = NULL;
10853
return 0;
10854
}
10855
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10856
return 1;
10857
}
10858
if (tmp == NULL) {
10859
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
10860
return 1;
10861
}
10862
else {
10863
int res;
10864
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10865
goto failed;
10866
}
10867
res = obj2ast_int(state, tmp, &lineno, arena);
10868
_Py_LeaveRecursiveCall();
10869
if (res != 0) goto failed;
10870
Py_CLEAR(tmp);
10871
}
10872
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10873
return 1;
10874
}
10875
if (tmp == NULL) {
10876
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
10877
return 1;
10878
}
10879
else {
10880
int res;
10881
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10882
goto failed;
10883
}
10884
res = obj2ast_int(state, tmp, &col_offset, arena);
10885
_Py_LeaveRecursiveCall();
10886
if (res != 0) goto failed;
10887
Py_CLEAR(tmp);
10888
}
10889
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10890
return 1;
10891
}
10892
if (tmp == NULL || tmp == Py_None) {
10893
Py_CLEAR(tmp);
10894
end_lineno = lineno;
10895
}
10896
else {
10897
int res;
10898
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10899
goto failed;
10900
}
10901
res = obj2ast_int(state, tmp, &end_lineno, arena);
10902
_Py_LeaveRecursiveCall();
10903
if (res != 0) goto failed;
10904
Py_CLEAR(tmp);
10905
}
10906
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10907
return 1;
10908
}
10909
if (tmp == NULL || tmp == Py_None) {
10910
Py_CLEAR(tmp);
10911
end_col_offset = col_offset;
10912
}
10913
else {
10914
int res;
10915
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10916
goto failed;
10917
}
10918
res = obj2ast_int(state, tmp, &end_col_offset, arena);
10919
_Py_LeaveRecursiveCall();
10920
if (res != 0) goto failed;
10921
Py_CLEAR(tmp);
10922
}
10923
tp = state->ExceptHandler_type;
10924
isinstance = PyObject_IsInstance(obj, tp);
10925
if (isinstance == -1) {
10926
return 1;
10927
}
10928
if (isinstance) {
10929
expr_ty type;
10930
identifier name;
10931
asdl_stmt_seq* body;
10932
10933
if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
10934
return 1;
10935
}
10936
if (tmp == NULL || tmp == Py_None) {
10937
Py_CLEAR(tmp);
10938
type = NULL;
10939
}
10940
else {
10941
int res;
10942
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10943
goto failed;
10944
}
10945
res = obj2ast_expr(state, tmp, &type, arena);
10946
_Py_LeaveRecursiveCall();
10947
if (res != 0) goto failed;
10948
Py_CLEAR(tmp);
10949
}
10950
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
10951
return 1;
10952
}
10953
if (tmp == NULL || tmp == Py_None) {
10954
Py_CLEAR(tmp);
10955
name = NULL;
10956
}
10957
else {
10958
int res;
10959
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10960
goto failed;
10961
}
10962
res = obj2ast_identifier(state, tmp, &name, arena);
10963
_Py_LeaveRecursiveCall();
10964
if (res != 0) goto failed;
10965
Py_CLEAR(tmp);
10966
}
10967
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10968
return 1;
10969
}
10970
if (tmp == NULL) {
10971
tmp = PyList_New(0);
10972
if (tmp == NULL) {
10973
return 1;
10974
}
10975
}
10976
{
10977
int res;
10978
Py_ssize_t len;
10979
Py_ssize_t i;
10980
if (!PyList_Check(tmp)) {
10981
PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10982
goto failed;
10983
}
10984
len = PyList_GET_SIZE(tmp);
10985
body = _Py_asdl_stmt_seq_new(len, arena);
10986
if (body == NULL) goto failed;
10987
for (i = 0; i < len; i++) {
10988
stmt_ty val;
10989
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10990
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10991
goto failed;
10992
}
10993
res = obj2ast_stmt(state, tmp2, &val, arena);
10994
_Py_LeaveRecursiveCall();
10995
Py_DECREF(tmp2);
10996
if (res != 0) goto failed;
10997
if (len != PyList_GET_SIZE(tmp)) {
10998
PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
10999
goto failed;
11000
}
11001
asdl_seq_SET(body, i, val);
11002
}
11003
Py_CLEAR(tmp);
11004
}
11005
*out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
11006
end_lineno, end_col_offset, arena);
11007
if (*out == NULL) goto failed;
11008
return 0;
11009
}
11010
11011
PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
11012
failed:
11013
Py_XDECREF(tmp);
11014
return 1;
11015
}
11016
11017
int
11018
obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
11019
PyArena* arena)
11020
{
11021
PyObject* tmp = NULL;
11022
asdl_arg_seq* posonlyargs;
11023
asdl_arg_seq* args;
11024
arg_ty vararg;
11025
asdl_arg_seq* kwonlyargs;
11026
asdl_expr_seq* kw_defaults;
11027
arg_ty kwarg;
11028
asdl_expr_seq* defaults;
11029
11030
if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
11031
return 1;
11032
}
11033
if (tmp == NULL) {
11034
tmp = PyList_New(0);
11035
if (tmp == NULL) {
11036
return 1;
11037
}
11038
}
11039
{
11040
int res;
11041
Py_ssize_t len;
11042
Py_ssize_t i;
11043
if (!PyList_Check(tmp)) {
11044
PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11045
goto failed;
11046
}
11047
len = PyList_GET_SIZE(tmp);
11048
posonlyargs = _Py_asdl_arg_seq_new(len, arena);
11049
if (posonlyargs == NULL) goto failed;
11050
for (i = 0; i < len; i++) {
11051
arg_ty val;
11052
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11053
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11054
goto failed;
11055
}
11056
res = obj2ast_arg(state, tmp2, &val, arena);
11057
_Py_LeaveRecursiveCall();
11058
Py_DECREF(tmp2);
11059
if (res != 0) goto failed;
11060
if (len != PyList_GET_SIZE(tmp)) {
11061
PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
11062
goto failed;
11063
}
11064
asdl_seq_SET(posonlyargs, i, val);
11065
}
11066
Py_CLEAR(tmp);
11067
}
11068
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
11069
return 1;
11070
}
11071
if (tmp == NULL) {
11072
tmp = PyList_New(0);
11073
if (tmp == NULL) {
11074
return 1;
11075
}
11076
}
11077
{
11078
int res;
11079
Py_ssize_t len;
11080
Py_ssize_t i;
11081
if (!PyList_Check(tmp)) {
11082
PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11083
goto failed;
11084
}
11085
len = PyList_GET_SIZE(tmp);
11086
args = _Py_asdl_arg_seq_new(len, arena);
11087
if (args == NULL) goto failed;
11088
for (i = 0; i < len; i++) {
11089
arg_ty val;
11090
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11091
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11092
goto failed;
11093
}
11094
res = obj2ast_arg(state, tmp2, &val, arena);
11095
_Py_LeaveRecursiveCall();
11096
Py_DECREF(tmp2);
11097
if (res != 0) goto failed;
11098
if (len != PyList_GET_SIZE(tmp)) {
11099
PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
11100
goto failed;
11101
}
11102
asdl_seq_SET(args, i, val);
11103
}
11104
Py_CLEAR(tmp);
11105
}
11106
if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
11107
return 1;
11108
}
11109
if (tmp == NULL || tmp == Py_None) {
11110
Py_CLEAR(tmp);
11111
vararg = NULL;
11112
}
11113
else {
11114
int res;
11115
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11116
goto failed;
11117
}
11118
res = obj2ast_arg(state, tmp, &vararg, arena);
11119
_Py_LeaveRecursiveCall();
11120
if (res != 0) goto failed;
11121
Py_CLEAR(tmp);
11122
}
11123
if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
11124
return 1;
11125
}
11126
if (tmp == NULL) {
11127
tmp = PyList_New(0);
11128
if (tmp == NULL) {
11129
return 1;
11130
}
11131
}
11132
{
11133
int res;
11134
Py_ssize_t len;
11135
Py_ssize_t i;
11136
if (!PyList_Check(tmp)) {
11137
PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11138
goto failed;
11139
}
11140
len = PyList_GET_SIZE(tmp);
11141
kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
11142
if (kwonlyargs == NULL) goto failed;
11143
for (i = 0; i < len; i++) {
11144
arg_ty val;
11145
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11146
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11147
goto failed;
11148
}
11149
res = obj2ast_arg(state, tmp2, &val, arena);
11150
_Py_LeaveRecursiveCall();
11151
Py_DECREF(tmp2);
11152
if (res != 0) goto failed;
11153
if (len != PyList_GET_SIZE(tmp)) {
11154
PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
11155
goto failed;
11156
}
11157
asdl_seq_SET(kwonlyargs, i, val);
11158
}
11159
Py_CLEAR(tmp);
11160
}
11161
if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
11162
return 1;
11163
}
11164
if (tmp == NULL) {
11165
tmp = PyList_New(0);
11166
if (tmp == NULL) {
11167
return 1;
11168
}
11169
}
11170
{
11171
int res;
11172
Py_ssize_t len;
11173
Py_ssize_t i;
11174
if (!PyList_Check(tmp)) {
11175
PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11176
goto failed;
11177
}
11178
len = PyList_GET_SIZE(tmp);
11179
kw_defaults = _Py_asdl_expr_seq_new(len, arena);
11180
if (kw_defaults == NULL) goto failed;
11181
for (i = 0; i < len; i++) {
11182
expr_ty val;
11183
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11184
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11185
goto failed;
11186
}
11187
res = obj2ast_expr(state, tmp2, &val, arena);
11188
_Py_LeaveRecursiveCall();
11189
Py_DECREF(tmp2);
11190
if (res != 0) goto failed;
11191
if (len != PyList_GET_SIZE(tmp)) {
11192
PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
11193
goto failed;
11194
}
11195
asdl_seq_SET(kw_defaults, i, val);
11196
}
11197
Py_CLEAR(tmp);
11198
}
11199
if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
11200
return 1;
11201
}
11202
if (tmp == NULL || tmp == Py_None) {
11203
Py_CLEAR(tmp);
11204
kwarg = NULL;
11205
}
11206
else {
11207
int res;
11208
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11209
goto failed;
11210
}
11211
res = obj2ast_arg(state, tmp, &kwarg, arena);
11212
_Py_LeaveRecursiveCall();
11213
if (res != 0) goto failed;
11214
Py_CLEAR(tmp);
11215
}
11216
if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
11217
return 1;
11218
}
11219
if (tmp == NULL) {
11220
tmp = PyList_New(0);
11221
if (tmp == NULL) {
11222
return 1;
11223
}
11224
}
11225
{
11226
int res;
11227
Py_ssize_t len;
11228
Py_ssize_t i;
11229
if (!PyList_Check(tmp)) {
11230
PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11231
goto failed;
11232
}
11233
len = PyList_GET_SIZE(tmp);
11234
defaults = _Py_asdl_expr_seq_new(len, arena);
11235
if (defaults == NULL) goto failed;
11236
for (i = 0; i < len; i++) {
11237
expr_ty val;
11238
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11239
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
11240
goto failed;
11241
}
11242
res = obj2ast_expr(state, tmp2, &val, arena);
11243
_Py_LeaveRecursiveCall();
11244
Py_DECREF(tmp2);
11245
if (res != 0) goto failed;
11246
if (len != PyList_GET_SIZE(tmp)) {
11247
PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
11248
goto failed;
11249
}
11250
asdl_seq_SET(defaults, i, val);
11251
}
11252
Py_CLEAR(tmp);
11253
}
11254
*out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
11255
kwarg, defaults, arena);
11256
if (*out == NULL) goto failed;
11257
return 0;
11258
failed:
11259
Py_XDECREF(tmp);
11260
return 1;
11261
}
11262
11263
int
11264
obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
11265
{
11266
PyObject* tmp = NULL;
11267
identifier arg;
11268
expr_ty annotation;
11269
string type_comment;
11270
int lineno;
11271
int col_offset;
11272
int end_lineno;
11273
int end_col_offset;
11274
11275
if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
11276
return 1;
11277
}
11278
if (tmp == NULL) {
11279
PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
11280
return 1;
11281
}
11282
else {
11283
int res;
11284
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11285
goto failed;
11286
}
11287
res = obj2ast_identifier(state, tmp, &arg, arena);
11288
_Py_LeaveRecursiveCall();
11289
if (res != 0) goto failed;
11290
Py_CLEAR(tmp);
11291
}
11292
if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
11293
return 1;
11294
}
11295
if (tmp == NULL || tmp == Py_None) {
11296
Py_CLEAR(tmp);
11297
annotation = NULL;
11298
}
11299
else {
11300
int res;
11301
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11302
goto failed;
11303
}
11304
res = obj2ast_expr(state, tmp, &annotation, arena);
11305
_Py_LeaveRecursiveCall();
11306
if (res != 0) goto failed;
11307
Py_CLEAR(tmp);
11308
}
11309
if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
11310
return 1;
11311
}
11312
if (tmp == NULL || tmp == Py_None) {
11313
Py_CLEAR(tmp);
11314
type_comment = NULL;
11315
}
11316
else {
11317
int res;
11318
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11319
goto failed;
11320
}
11321
res = obj2ast_string(state, tmp, &type_comment, arena);
11322
_Py_LeaveRecursiveCall();
11323
if (res != 0) goto failed;
11324
Py_CLEAR(tmp);
11325
}
11326
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11327
return 1;
11328
}
11329
if (tmp == NULL) {
11330
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
11331
return 1;
11332
}
11333
else {
11334
int res;
11335
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11336
goto failed;
11337
}
11338
res = obj2ast_int(state, tmp, &lineno, arena);
11339
_Py_LeaveRecursiveCall();
11340
if (res != 0) goto failed;
11341
Py_CLEAR(tmp);
11342
}
11343
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11344
return 1;
11345
}
11346
if (tmp == NULL) {
11347
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
11348
return 1;
11349
}
11350
else {
11351
int res;
11352
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11353
goto failed;
11354
}
11355
res = obj2ast_int(state, tmp, &col_offset, arena);
11356
_Py_LeaveRecursiveCall();
11357
if (res != 0) goto failed;
11358
Py_CLEAR(tmp);
11359
}
11360
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11361
return 1;
11362
}
11363
if (tmp == NULL || tmp == Py_None) {
11364
Py_CLEAR(tmp);
11365
end_lineno = lineno;
11366
}
11367
else {
11368
int res;
11369
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11370
goto failed;
11371
}
11372
res = obj2ast_int(state, tmp, &end_lineno, arena);
11373
_Py_LeaveRecursiveCall();
11374
if (res != 0) goto failed;
11375
Py_CLEAR(tmp);
11376
}
11377
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11378
return 1;
11379
}
11380
if (tmp == NULL || tmp == Py_None) {
11381
Py_CLEAR(tmp);
11382
end_col_offset = col_offset;
11383
}
11384
else {
11385
int res;
11386
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
11387
goto failed;
11388
}
11389
res = obj2ast_int(state, tmp, &end_col_offset, arena);
11390
_Py_LeaveRecursiveCall();
11391
if (res != 0) goto failed;
11392
Py_CLEAR(tmp);
11393
}
11394
*out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
11395
end_lineno, end_col_offset, arena);
11396
if (*out == NULL) goto failed;
11397
return 0;
11398
failed:
11399
Py_XDECREF(tmp);
11400
return 1;
11401
}
11402
11403
int
11404
obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
11405
PyArena* arena)
11406
{
11407
PyObject* tmp = NULL;
11408
identifier arg;
11409
expr_ty value;
11410
int lineno;
11411
int col_offset;
11412
int end_lineno;
11413
int end_col_offset;
11414
11415
if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
11416
return 1;
11417
}
11418
if (tmp == NULL || tmp == Py_None) {
11419
Py_CLEAR(tmp);
11420
arg = NULL;
11421
}
11422
else {
11423
int res;
11424
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11425
goto failed;
11426
}
11427
res = obj2ast_identifier(state, tmp, &arg, arena);
11428
_Py_LeaveRecursiveCall();
11429
if (res != 0) goto failed;
11430
Py_CLEAR(tmp);
11431
}
11432
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11433
return 1;
11434
}
11435
if (tmp == NULL) {
11436
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
11437
return 1;
11438
}
11439
else {
11440
int res;
11441
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11442
goto failed;
11443
}
11444
res = obj2ast_expr(state, tmp, &value, arena);
11445
_Py_LeaveRecursiveCall();
11446
if (res != 0) goto failed;
11447
Py_CLEAR(tmp);
11448
}
11449
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11450
return 1;
11451
}
11452
if (tmp == NULL) {
11453
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
11454
return 1;
11455
}
11456
else {
11457
int res;
11458
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11459
goto failed;
11460
}
11461
res = obj2ast_int(state, tmp, &lineno, arena);
11462
_Py_LeaveRecursiveCall();
11463
if (res != 0) goto failed;
11464
Py_CLEAR(tmp);
11465
}
11466
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11467
return 1;
11468
}
11469
if (tmp == NULL) {
11470
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
11471
return 1;
11472
}
11473
else {
11474
int res;
11475
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11476
goto failed;
11477
}
11478
res = obj2ast_int(state, tmp, &col_offset, arena);
11479
_Py_LeaveRecursiveCall();
11480
if (res != 0) goto failed;
11481
Py_CLEAR(tmp);
11482
}
11483
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11484
return 1;
11485
}
11486
if (tmp == NULL || tmp == Py_None) {
11487
Py_CLEAR(tmp);
11488
end_lineno = lineno;
11489
}
11490
else {
11491
int res;
11492
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11493
goto failed;
11494
}
11495
res = obj2ast_int(state, tmp, &end_lineno, arena);
11496
_Py_LeaveRecursiveCall();
11497
if (res != 0) goto failed;
11498
Py_CLEAR(tmp);
11499
}
11500
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11501
return 1;
11502
}
11503
if (tmp == NULL || tmp == Py_None) {
11504
Py_CLEAR(tmp);
11505
end_col_offset = col_offset;
11506
}
11507
else {
11508
int res;
11509
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
11510
goto failed;
11511
}
11512
res = obj2ast_int(state, tmp, &end_col_offset, arena);
11513
_Py_LeaveRecursiveCall();
11514
if (res != 0) goto failed;
11515
Py_CLEAR(tmp);
11516
}
11517
*out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
11518
end_col_offset, arena);
11519
if (*out == NULL) goto failed;
11520
return 0;
11521
failed:
11522
Py_XDECREF(tmp);
11523
return 1;
11524
}
11525
11526
int
11527
obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
11528
arena)
11529
{
11530
PyObject* tmp = NULL;
11531
identifier name;
11532
identifier asname;
11533
int lineno;
11534
int col_offset;
11535
int end_lineno;
11536
int end_col_offset;
11537
11538
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11539
return 1;
11540
}
11541
if (tmp == NULL) {
11542
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
11543
return 1;
11544
}
11545
else {
11546
int res;
11547
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11548
goto failed;
11549
}
11550
res = obj2ast_identifier(state, tmp, &name, arena);
11551
_Py_LeaveRecursiveCall();
11552
if (res != 0) goto failed;
11553
Py_CLEAR(tmp);
11554
}
11555
if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
11556
return 1;
11557
}
11558
if (tmp == NULL || tmp == Py_None) {
11559
Py_CLEAR(tmp);
11560
asname = NULL;
11561
}
11562
else {
11563
int res;
11564
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11565
goto failed;
11566
}
11567
res = obj2ast_identifier(state, tmp, &asname, arena);
11568
_Py_LeaveRecursiveCall();
11569
if (res != 0) goto failed;
11570
Py_CLEAR(tmp);
11571
}
11572
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11573
return 1;
11574
}
11575
if (tmp == NULL) {
11576
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
11577
return 1;
11578
}
11579
else {
11580
int res;
11581
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11582
goto failed;
11583
}
11584
res = obj2ast_int(state, tmp, &lineno, arena);
11585
_Py_LeaveRecursiveCall();
11586
if (res != 0) goto failed;
11587
Py_CLEAR(tmp);
11588
}
11589
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11590
return 1;
11591
}
11592
if (tmp == NULL) {
11593
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
11594
return 1;
11595
}
11596
else {
11597
int res;
11598
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11599
goto failed;
11600
}
11601
res = obj2ast_int(state, tmp, &col_offset, arena);
11602
_Py_LeaveRecursiveCall();
11603
if (res != 0) goto failed;
11604
Py_CLEAR(tmp);
11605
}
11606
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11607
return 1;
11608
}
11609
if (tmp == NULL || tmp == Py_None) {
11610
Py_CLEAR(tmp);
11611
end_lineno = lineno;
11612
}
11613
else {
11614
int res;
11615
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11616
goto failed;
11617
}
11618
res = obj2ast_int(state, tmp, &end_lineno, arena);
11619
_Py_LeaveRecursiveCall();
11620
if (res != 0) goto failed;
11621
Py_CLEAR(tmp);
11622
}
11623
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11624
return 1;
11625
}
11626
if (tmp == NULL || tmp == Py_None) {
11627
Py_CLEAR(tmp);
11628
end_col_offset = col_offset;
11629
}
11630
else {
11631
int res;
11632
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11633
goto failed;
11634
}
11635
res = obj2ast_int(state, tmp, &end_col_offset, arena);
11636
_Py_LeaveRecursiveCall();
11637
if (res != 0) goto failed;
11638
Py_CLEAR(tmp);
11639
}
11640
*out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
11641
end_col_offset, arena);
11642
if (*out == NULL) goto failed;
11643
return 0;
11644
failed:
11645
Py_XDECREF(tmp);
11646
return 1;
11647
}
11648
11649
int
11650
obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
11651
PyArena* arena)
11652
{
11653
PyObject* tmp = NULL;
11654
expr_ty context_expr;
11655
expr_ty optional_vars;
11656
11657
if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
11658
return 1;
11659
}
11660
if (tmp == NULL) {
11661
PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
11662
return 1;
11663
}
11664
else {
11665
int res;
11666
if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
11667
goto failed;
11668
}
11669
res = obj2ast_expr(state, tmp, &context_expr, arena);
11670
_Py_LeaveRecursiveCall();
11671
if (res != 0) goto failed;
11672
Py_CLEAR(tmp);
11673
}
11674
if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
11675
return 1;
11676
}
11677
if (tmp == NULL || tmp == Py_None) {
11678
Py_CLEAR(tmp);
11679
optional_vars = NULL;
11680
}
11681
else {
11682
int res;
11683
if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
11684
goto failed;
11685
}
11686
res = obj2ast_expr(state, tmp, &optional_vars, arena);
11687
_Py_LeaveRecursiveCall();
11688
if (res != 0) goto failed;
11689
Py_CLEAR(tmp);
11690
}
11691
*out = _PyAST_withitem(context_expr, optional_vars, arena);
11692
if (*out == NULL) goto failed;
11693
return 0;
11694
failed:
11695
Py_XDECREF(tmp);
11696
return 1;
11697
}
11698
11699
int
11700
obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
11701
PyArena* arena)
11702
{
11703
PyObject* tmp = NULL;
11704
pattern_ty pattern;
11705
expr_ty guard;
11706
asdl_stmt_seq* body;
11707
11708
if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11709
return 1;
11710
}
11711
if (tmp == NULL) {
11712
PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
11713
return 1;
11714
}
11715
else {
11716
int res;
11717
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11718
goto failed;
11719
}
11720
res = obj2ast_pattern(state, tmp, &pattern, arena);
11721
_Py_LeaveRecursiveCall();
11722
if (res != 0) goto failed;
11723
Py_CLEAR(tmp);
11724
}
11725
if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
11726
return 1;
11727
}
11728
if (tmp == NULL || tmp == Py_None) {
11729
Py_CLEAR(tmp);
11730
guard = NULL;
11731
}
11732
else {
11733
int res;
11734
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11735
goto failed;
11736
}
11737
res = obj2ast_expr(state, tmp, &guard, arena);
11738
_Py_LeaveRecursiveCall();
11739
if (res != 0) goto failed;
11740
Py_CLEAR(tmp);
11741
}
11742
if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
11743
return 1;
11744
}
11745
if (tmp == NULL) {
11746
tmp = PyList_New(0);
11747
if (tmp == NULL) {
11748
return 1;
11749
}
11750
}
11751
{
11752
int res;
11753
Py_ssize_t len;
11754
Py_ssize_t i;
11755
if (!PyList_Check(tmp)) {
11756
PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11757
goto failed;
11758
}
11759
len = PyList_GET_SIZE(tmp);
11760
body = _Py_asdl_stmt_seq_new(len, arena);
11761
if (body == NULL) goto failed;
11762
for (i = 0; i < len; i++) {
11763
stmt_ty val;
11764
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11765
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11766
goto failed;
11767
}
11768
res = obj2ast_stmt(state, tmp2, &val, arena);
11769
_Py_LeaveRecursiveCall();
11770
Py_DECREF(tmp2);
11771
if (res != 0) goto failed;
11772
if (len != PyList_GET_SIZE(tmp)) {
11773
PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
11774
goto failed;
11775
}
11776
asdl_seq_SET(body, i, val);
11777
}
11778
Py_CLEAR(tmp);
11779
}
11780
*out = _PyAST_match_case(pattern, guard, body, arena);
11781
if (*out == NULL) goto failed;
11782
return 0;
11783
failed:
11784
Py_XDECREF(tmp);
11785
return 1;
11786
}
11787
11788
int
11789
obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
11790
PyArena* arena)
11791
{
11792
int isinstance;
11793
11794
PyObject *tmp = NULL;
11795
PyObject *tp;
11796
int lineno;
11797
int col_offset;
11798
int end_lineno;
11799
int end_col_offset;
11800
11801
if (obj == Py_None) {
11802
*out = NULL;
11803
return 0;
11804
}
11805
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11806
return 1;
11807
}
11808
if (tmp == NULL) {
11809
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
11810
return 1;
11811
}
11812
else {
11813
int res;
11814
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11815
goto failed;
11816
}
11817
res = obj2ast_int(state, tmp, &lineno, arena);
11818
_Py_LeaveRecursiveCall();
11819
if (res != 0) goto failed;
11820
Py_CLEAR(tmp);
11821
}
11822
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11823
return 1;
11824
}
11825
if (tmp == NULL) {
11826
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
11827
return 1;
11828
}
11829
else {
11830
int res;
11831
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11832
goto failed;
11833
}
11834
res = obj2ast_int(state, tmp, &col_offset, arena);
11835
_Py_LeaveRecursiveCall();
11836
if (res != 0) goto failed;
11837
Py_CLEAR(tmp);
11838
}
11839
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11840
return 1;
11841
}
11842
if (tmp == NULL) {
11843
PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
11844
return 1;
11845
}
11846
else {
11847
int res;
11848
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11849
goto failed;
11850
}
11851
res = obj2ast_int(state, tmp, &end_lineno, arena);
11852
_Py_LeaveRecursiveCall();
11853
if (res != 0) goto failed;
11854
Py_CLEAR(tmp);
11855
}
11856
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11857
return 1;
11858
}
11859
if (tmp == NULL) {
11860
PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
11861
return 1;
11862
}
11863
else {
11864
int res;
11865
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11866
goto failed;
11867
}
11868
res = obj2ast_int(state, tmp, &end_col_offset, arena);
11869
_Py_LeaveRecursiveCall();
11870
if (res != 0) goto failed;
11871
Py_CLEAR(tmp);
11872
}
11873
tp = state->MatchValue_type;
11874
isinstance = PyObject_IsInstance(obj, tp);
11875
if (isinstance == -1) {
11876
return 1;
11877
}
11878
if (isinstance) {
11879
expr_ty value;
11880
11881
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11882
return 1;
11883
}
11884
if (tmp == NULL) {
11885
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
11886
return 1;
11887
}
11888
else {
11889
int res;
11890
if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
11891
goto failed;
11892
}
11893
res = obj2ast_expr(state, tmp, &value, arena);
11894
_Py_LeaveRecursiveCall();
11895
if (res != 0) goto failed;
11896
Py_CLEAR(tmp);
11897
}
11898
*out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
11899
end_col_offset, arena);
11900
if (*out == NULL) goto failed;
11901
return 0;
11902
}
11903
tp = state->MatchSingleton_type;
11904
isinstance = PyObject_IsInstance(obj, tp);
11905
if (isinstance == -1) {
11906
return 1;
11907
}
11908
if (isinstance) {
11909
constant value;
11910
11911
if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11912
return 1;
11913
}
11914
if (tmp == NULL) {
11915
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
11916
return 1;
11917
}
11918
else {
11919
int res;
11920
if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
11921
goto failed;
11922
}
11923
res = obj2ast_constant(state, tmp, &value, arena);
11924
_Py_LeaveRecursiveCall();
11925
if (res != 0) goto failed;
11926
Py_CLEAR(tmp);
11927
}
11928
*out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
11929
end_col_offset, arena);
11930
if (*out == NULL) goto failed;
11931
return 0;
11932
}
11933
tp = state->MatchSequence_type;
11934
isinstance = PyObject_IsInstance(obj, tp);
11935
if (isinstance == -1) {
11936
return 1;
11937
}
11938
if (isinstance) {
11939
asdl_pattern_seq* patterns;
11940
11941
if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11942
return 1;
11943
}
11944
if (tmp == NULL) {
11945
tmp = PyList_New(0);
11946
if (tmp == NULL) {
11947
return 1;
11948
}
11949
}
11950
{
11951
int res;
11952
Py_ssize_t len;
11953
Py_ssize_t i;
11954
if (!PyList_Check(tmp)) {
11955
PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11956
goto failed;
11957
}
11958
len = PyList_GET_SIZE(tmp);
11959
patterns = _Py_asdl_pattern_seq_new(len, arena);
11960
if (patterns == NULL) goto failed;
11961
for (i = 0; i < len; i++) {
11962
pattern_ty val;
11963
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11964
if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
11965
goto failed;
11966
}
11967
res = obj2ast_pattern(state, tmp2, &val, arena);
11968
_Py_LeaveRecursiveCall();
11969
Py_DECREF(tmp2);
11970
if (res != 0) goto failed;
11971
if (len != PyList_GET_SIZE(tmp)) {
11972
PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
11973
goto failed;
11974
}
11975
asdl_seq_SET(patterns, i, val);
11976
}
11977
Py_CLEAR(tmp);
11978
}
11979
*out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
11980
end_col_offset, arena);
11981
if (*out == NULL) goto failed;
11982
return 0;
11983
}
11984
tp = state->MatchMapping_type;
11985
isinstance = PyObject_IsInstance(obj, tp);
11986
if (isinstance == -1) {
11987
return 1;
11988
}
11989
if (isinstance) {
11990
asdl_expr_seq* keys;
11991
asdl_pattern_seq* patterns;
11992
identifier rest;
11993
11994
if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
11995
return 1;
11996
}
11997
if (tmp == NULL) {
11998
tmp = PyList_New(0);
11999
if (tmp == NULL) {
12000
return 1;
12001
}
12002
}
12003
{
12004
int res;
12005
Py_ssize_t len;
12006
Py_ssize_t i;
12007
if (!PyList_Check(tmp)) {
12008
PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12009
goto failed;
12010
}
12011
len = PyList_GET_SIZE(tmp);
12012
keys = _Py_asdl_expr_seq_new(len, arena);
12013
if (keys == NULL) goto failed;
12014
for (i = 0; i < len; i++) {
12015
expr_ty val;
12016
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12017
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
12018
goto failed;
12019
}
12020
res = obj2ast_expr(state, tmp2, &val, arena);
12021
_Py_LeaveRecursiveCall();
12022
Py_DECREF(tmp2);
12023
if (res != 0) goto failed;
12024
if (len != PyList_GET_SIZE(tmp)) {
12025
PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
12026
goto failed;
12027
}
12028
asdl_seq_SET(keys, i, val);
12029
}
12030
Py_CLEAR(tmp);
12031
}
12032
if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
12033
return 1;
12034
}
12035
if (tmp == NULL) {
12036
tmp = PyList_New(0);
12037
if (tmp == NULL) {
12038
return 1;
12039
}
12040
}
12041
{
12042
int res;
12043
Py_ssize_t len;
12044
Py_ssize_t i;
12045
if (!PyList_Check(tmp)) {
12046
PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12047
goto failed;
12048
}
12049
len = PyList_GET_SIZE(tmp);
12050
patterns = _Py_asdl_pattern_seq_new(len, arena);
12051
if (patterns == NULL) goto failed;
12052
for (i = 0; i < len; i++) {
12053
pattern_ty val;
12054
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12055
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
12056
goto failed;
12057
}
12058
res = obj2ast_pattern(state, tmp2, &val, arena);
12059
_Py_LeaveRecursiveCall();
12060
Py_DECREF(tmp2);
12061
if (res != 0) goto failed;
12062
if (len != PyList_GET_SIZE(tmp)) {
12063
PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
12064
goto failed;
12065
}
12066
asdl_seq_SET(patterns, i, val);
12067
}
12068
Py_CLEAR(tmp);
12069
}
12070
if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
12071
return 1;
12072
}
12073
if (tmp == NULL || tmp == Py_None) {
12074
Py_CLEAR(tmp);
12075
rest = NULL;
12076
}
12077
else {
12078
int res;
12079
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
12080
goto failed;
12081
}
12082
res = obj2ast_identifier(state, tmp, &rest, arena);
12083
_Py_LeaveRecursiveCall();
12084
if (res != 0) goto failed;
12085
Py_CLEAR(tmp);
12086
}
12087
*out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
12088
end_lineno, end_col_offset, arena);
12089
if (*out == NULL) goto failed;
12090
return 0;
12091
}
12092
tp = state->MatchClass_type;
12093
isinstance = PyObject_IsInstance(obj, tp);
12094
if (isinstance == -1) {
12095
return 1;
12096
}
12097
if (isinstance) {
12098
expr_ty cls;
12099
asdl_pattern_seq* patterns;
12100
asdl_identifier_seq* kwd_attrs;
12101
asdl_pattern_seq* kwd_patterns;
12102
12103
if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
12104
return 1;
12105
}
12106
if (tmp == NULL) {
12107
PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
12108
return 1;
12109
}
12110
else {
12111
int res;
12112
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
12113
goto failed;
12114
}
12115
res = obj2ast_expr(state, tmp, &cls, arena);
12116
_Py_LeaveRecursiveCall();
12117
if (res != 0) goto failed;
12118
Py_CLEAR(tmp);
12119
}
12120
if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
12121
return 1;
12122
}
12123
if (tmp == NULL) {
12124
tmp = PyList_New(0);
12125
if (tmp == NULL) {
12126
return 1;
12127
}
12128
}
12129
{
12130
int res;
12131
Py_ssize_t len;
12132
Py_ssize_t i;
12133
if (!PyList_Check(tmp)) {
12134
PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12135
goto failed;
12136
}
12137
len = PyList_GET_SIZE(tmp);
12138
patterns = _Py_asdl_pattern_seq_new(len, arena);
12139
if (patterns == NULL) goto failed;
12140
for (i = 0; i < len; i++) {
12141
pattern_ty val;
12142
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12143
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
12144
goto failed;
12145
}
12146
res = obj2ast_pattern(state, tmp2, &val, arena);
12147
_Py_LeaveRecursiveCall();
12148
Py_DECREF(tmp2);
12149
if (res != 0) goto failed;
12150
if (len != PyList_GET_SIZE(tmp)) {
12151
PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
12152
goto failed;
12153
}
12154
asdl_seq_SET(patterns, i, val);
12155
}
12156
Py_CLEAR(tmp);
12157
}
12158
if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
12159
return 1;
12160
}
12161
if (tmp == NULL) {
12162
tmp = PyList_New(0);
12163
if (tmp == NULL) {
12164
return 1;
12165
}
12166
}
12167
{
12168
int res;
12169
Py_ssize_t len;
12170
Py_ssize_t i;
12171
if (!PyList_Check(tmp)) {
12172
PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12173
goto failed;
12174
}
12175
len = PyList_GET_SIZE(tmp);
12176
kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
12177
if (kwd_attrs == NULL) goto failed;
12178
for (i = 0; i < len; i++) {
12179
identifier val;
12180
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12181
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
12182
goto failed;
12183
}
12184
res = obj2ast_identifier(state, tmp2, &val, arena);
12185
_Py_LeaveRecursiveCall();
12186
Py_DECREF(tmp2);
12187
if (res != 0) goto failed;
12188
if (len != PyList_GET_SIZE(tmp)) {
12189
PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
12190
goto failed;
12191
}
12192
asdl_seq_SET(kwd_attrs, i, val);
12193
}
12194
Py_CLEAR(tmp);
12195
}
12196
if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
12197
return 1;
12198
}
12199
if (tmp == NULL) {
12200
tmp = PyList_New(0);
12201
if (tmp == NULL) {
12202
return 1;
12203
}
12204
}
12205
{
12206
int res;
12207
Py_ssize_t len;
12208
Py_ssize_t i;
12209
if (!PyList_Check(tmp)) {
12210
PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12211
goto failed;
12212
}
12213
len = PyList_GET_SIZE(tmp);
12214
kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
12215
if (kwd_patterns == NULL) goto failed;
12216
for (i = 0; i < len; i++) {
12217
pattern_ty val;
12218
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12219
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
12220
goto failed;
12221
}
12222
res = obj2ast_pattern(state, tmp2, &val, arena);
12223
_Py_LeaveRecursiveCall();
12224
Py_DECREF(tmp2);
12225
if (res != 0) goto failed;
12226
if (len != PyList_GET_SIZE(tmp)) {
12227
PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
12228
goto failed;
12229
}
12230
asdl_seq_SET(kwd_patterns, i, val);
12231
}
12232
Py_CLEAR(tmp);
12233
}
12234
*out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
12235
lineno, col_offset, end_lineno,
12236
end_col_offset, arena);
12237
if (*out == NULL) goto failed;
12238
return 0;
12239
}
12240
tp = state->MatchStar_type;
12241
isinstance = PyObject_IsInstance(obj, tp);
12242
if (isinstance == -1) {
12243
return 1;
12244
}
12245
if (isinstance) {
12246
identifier name;
12247
12248
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
12249
return 1;
12250
}
12251
if (tmp == NULL || tmp == Py_None) {
12252
Py_CLEAR(tmp);
12253
name = NULL;
12254
}
12255
else {
12256
int res;
12257
if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
12258
goto failed;
12259
}
12260
res = obj2ast_identifier(state, tmp, &name, arena);
12261
_Py_LeaveRecursiveCall();
12262
if (res != 0) goto failed;
12263
Py_CLEAR(tmp);
12264
}
12265
*out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
12266
end_col_offset, arena);
12267
if (*out == NULL) goto failed;
12268
return 0;
12269
}
12270
tp = state->MatchAs_type;
12271
isinstance = PyObject_IsInstance(obj, tp);
12272
if (isinstance == -1) {
12273
return 1;
12274
}
12275
if (isinstance) {
12276
pattern_ty pattern;
12277
identifier name;
12278
12279
if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
12280
return 1;
12281
}
12282
if (tmp == NULL || tmp == Py_None) {
12283
Py_CLEAR(tmp);
12284
pattern = NULL;
12285
}
12286
else {
12287
int res;
12288
if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
12289
goto failed;
12290
}
12291
res = obj2ast_pattern(state, tmp, &pattern, arena);
12292
_Py_LeaveRecursiveCall();
12293
if (res != 0) goto failed;
12294
Py_CLEAR(tmp);
12295
}
12296
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
12297
return 1;
12298
}
12299
if (tmp == NULL || tmp == Py_None) {
12300
Py_CLEAR(tmp);
12301
name = NULL;
12302
}
12303
else {
12304
int res;
12305
if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
12306
goto failed;
12307
}
12308
res = obj2ast_identifier(state, tmp, &name, arena);
12309
_Py_LeaveRecursiveCall();
12310
if (res != 0) goto failed;
12311
Py_CLEAR(tmp);
12312
}
12313
*out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
12314
end_col_offset, arena);
12315
if (*out == NULL) goto failed;
12316
return 0;
12317
}
12318
tp = state->MatchOr_type;
12319
isinstance = PyObject_IsInstance(obj, tp);
12320
if (isinstance == -1) {
12321
return 1;
12322
}
12323
if (isinstance) {
12324
asdl_pattern_seq* patterns;
12325
12326
if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
12327
return 1;
12328
}
12329
if (tmp == NULL) {
12330
tmp = PyList_New(0);
12331
if (tmp == NULL) {
12332
return 1;
12333
}
12334
}
12335
{
12336
int res;
12337
Py_ssize_t len;
12338
Py_ssize_t i;
12339
if (!PyList_Check(tmp)) {
12340
PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12341
goto failed;
12342
}
12343
len = PyList_GET_SIZE(tmp);
12344
patterns = _Py_asdl_pattern_seq_new(len, arena);
12345
if (patterns == NULL) goto failed;
12346
for (i = 0; i < len; i++) {
12347
pattern_ty val;
12348
PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12349
if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
12350
goto failed;
12351
}
12352
res = obj2ast_pattern(state, tmp2, &val, arena);
12353
_Py_LeaveRecursiveCall();
12354
Py_DECREF(tmp2);
12355
if (res != 0) goto failed;
12356
if (len != PyList_GET_SIZE(tmp)) {
12357
PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
12358
goto failed;
12359
}
12360
asdl_seq_SET(patterns, i, val);
12361
}
12362
Py_CLEAR(tmp);
12363
}
12364
*out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
12365
end_col_offset, arena);
12366
if (*out == NULL) goto failed;
12367
return 0;
12368
}
12369
12370
PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
12371
failed:
12372
Py_XDECREF(tmp);
12373
return 1;
12374
}
12375
12376
int
12377
obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
12378
out, PyArena* arena)
12379
{
12380
int isinstance;
12381
12382
PyObject *tmp = NULL;
12383
PyObject *tp;
12384
12385
if (obj == Py_None) {
12386
*out = NULL;
12387
return 0;
12388
}
12389
tp = state->TypeIgnore_type;
12390
isinstance = PyObject_IsInstance(obj, tp);
12391
if (isinstance == -1) {
12392
return 1;
12393
}
12394
if (isinstance) {
12395
int lineno;
12396
string tag;
12397
12398
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
12399
return 1;
12400
}
12401
if (tmp == NULL) {
12402
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
12403
return 1;
12404
}
12405
else {
12406
int res;
12407
if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
12408
goto failed;
12409
}
12410
res = obj2ast_int(state, tmp, &lineno, arena);
12411
_Py_LeaveRecursiveCall();
12412
if (res != 0) goto failed;
12413
Py_CLEAR(tmp);
12414
}
12415
if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
12416
return 1;
12417
}
12418
if (tmp == NULL) {
12419
PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
12420
return 1;
12421
}
12422
else {
12423
int res;
12424
if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
12425
goto failed;
12426
}
12427
res = obj2ast_string(state, tmp, &tag, arena);
12428
_Py_LeaveRecursiveCall();
12429
if (res != 0) goto failed;
12430
Py_CLEAR(tmp);
12431
}
12432
*out = _PyAST_TypeIgnore(lineno, tag, arena);
12433
if (*out == NULL) goto failed;
12434
return 0;
12435
}
12436
12437
PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
12438
failed:
12439
Py_XDECREF(tmp);
12440
return 1;
12441
}
12442
12443
int
12444
obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
12445
PyArena* arena)
12446
{
12447
int isinstance;
12448
12449
PyObject *tmp = NULL;
12450
PyObject *tp;
12451
int lineno;
12452
int col_offset;
12453
int end_lineno;
12454
int end_col_offset;
12455
12456
if (obj == Py_None) {
12457
*out = NULL;
12458
return 0;
12459
}
12460
if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
12461
return 1;
12462
}
12463
if (tmp == NULL) {
12464
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
12465
return 1;
12466
}
12467
else {
12468
int res;
12469
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
12470
goto failed;
12471
}
12472
res = obj2ast_int(state, tmp, &lineno, arena);
12473
_Py_LeaveRecursiveCall();
12474
if (res != 0) goto failed;
12475
Py_CLEAR(tmp);
12476
}
12477
if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
12478
return 1;
12479
}
12480
if (tmp == NULL) {
12481
PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
12482
return 1;
12483
}
12484
else {
12485
int res;
12486
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
12487
goto failed;
12488
}
12489
res = obj2ast_int(state, tmp, &col_offset, arena);
12490
_Py_LeaveRecursiveCall();
12491
if (res != 0) goto failed;
12492
Py_CLEAR(tmp);
12493
}
12494
if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
12495
return 1;
12496
}
12497
if (tmp == NULL) {
12498
PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
12499
return 1;
12500
}
12501
else {
12502
int res;
12503
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
12504
goto failed;
12505
}
12506
res = obj2ast_int(state, tmp, &end_lineno, arena);
12507
_Py_LeaveRecursiveCall();
12508
if (res != 0) goto failed;
12509
Py_CLEAR(tmp);
12510
}
12511
if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
12512
return 1;
12513
}
12514
if (tmp == NULL) {
12515
PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
12516
return 1;
12517
}
12518
else {
12519
int res;
12520
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
12521
goto failed;
12522
}
12523
res = obj2ast_int(state, tmp, &end_col_offset, arena);
12524
_Py_LeaveRecursiveCall();
12525
if (res != 0) goto failed;
12526
Py_CLEAR(tmp);
12527
}
12528
tp = state->TypeVar_type;
12529
isinstance = PyObject_IsInstance(obj, tp);
12530
if (isinstance == -1) {
12531
return 1;
12532
}
12533
if (isinstance) {
12534
identifier name;
12535
expr_ty bound;
12536
12537
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
12538
return 1;
12539
}
12540
if (tmp == NULL) {
12541
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
12542
return 1;
12543
}
12544
else {
12545
int res;
12546
if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
12547
goto failed;
12548
}
12549
res = obj2ast_identifier(state, tmp, &name, arena);
12550
_Py_LeaveRecursiveCall();
12551
if (res != 0) goto failed;
12552
Py_CLEAR(tmp);
12553
}
12554
if (_PyObject_LookupAttr(obj, state->bound, &tmp) < 0) {
12555
return 1;
12556
}
12557
if (tmp == NULL || tmp == Py_None) {
12558
Py_CLEAR(tmp);
12559
bound = NULL;
12560
}
12561
else {
12562
int res;
12563
if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
12564
goto failed;
12565
}
12566
res = obj2ast_expr(state, tmp, &bound, arena);
12567
_Py_LeaveRecursiveCall();
12568
if (res != 0) goto failed;
12569
Py_CLEAR(tmp);
12570
}
12571
*out = _PyAST_TypeVar(name, bound, lineno, col_offset, end_lineno,
12572
end_col_offset, arena);
12573
if (*out == NULL) goto failed;
12574
return 0;
12575
}
12576
tp = state->ParamSpec_type;
12577
isinstance = PyObject_IsInstance(obj, tp);
12578
if (isinstance == -1) {
12579
return 1;
12580
}
12581
if (isinstance) {
12582
identifier name;
12583
12584
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
12585
return 1;
12586
}
12587
if (tmp == NULL) {
12588
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
12589
return 1;
12590
}
12591
else {
12592
int res;
12593
if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
12594
goto failed;
12595
}
12596
res = obj2ast_identifier(state, tmp, &name, arena);
12597
_Py_LeaveRecursiveCall();
12598
if (res != 0) goto failed;
12599
Py_CLEAR(tmp);
12600
}
12601
*out = _PyAST_ParamSpec(name, lineno, col_offset, end_lineno,
12602
end_col_offset, arena);
12603
if (*out == NULL) goto failed;
12604
return 0;
12605
}
12606
tp = state->TypeVarTuple_type;
12607
isinstance = PyObject_IsInstance(obj, tp);
12608
if (isinstance == -1) {
12609
return 1;
12610
}
12611
if (isinstance) {
12612
identifier name;
12613
12614
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
12615
return 1;
12616
}
12617
if (tmp == NULL) {
12618
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
12619
return 1;
12620
}
12621
else {
12622
int res;
12623
if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
12624
goto failed;
12625
}
12626
res = obj2ast_identifier(state, tmp, &name, arena);
12627
_Py_LeaveRecursiveCall();
12628
if (res != 0) goto failed;
12629
Py_CLEAR(tmp);
12630
}
12631
*out = _PyAST_TypeVarTuple(name, lineno, col_offset, end_lineno,
12632
end_col_offset, arena);
12633
if (*out == NULL) goto failed;
12634
return 0;
12635
}
12636
12637
PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
12638
failed:
12639
Py_XDECREF(tmp);
12640
return 1;
12641
}
12642
12643
12644
static int
12645
astmodule_exec(PyObject *m)
12646
{
12647
struct ast_state *state = get_ast_state();
12648
if (state == NULL) {
12649
return -1;
12650
}
12651
if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
12652
return -1;
12653
}
12654
if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
12655
return -1;
12656
}
12657
if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
12658
return -1;
12659
}
12660
if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
12661
return -1;
12662
}
12663
if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
12664
return -1;
12665
}
12666
if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
12667
return -1;
12668
}
12669
if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
12670
return -1;
12671
}
12672
if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
12673
return -1;
12674
}
12675
if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
12676
{
12677
return -1;
12678
}
12679
if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
12680
return -1;
12681
}
12682
if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
12683
return -1;
12684
}
12685
if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
12686
state->AsyncFunctionDef_type) < 0) {
12687
return -1;
12688
}
12689
if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
12690
return -1;
12691
}
12692
if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
12693
return -1;
12694
}
12695
if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
12696
return -1;
12697
}
12698
if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
12699
return -1;
12700
}
12701
if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
12702
return -1;
12703
}
12704
if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
12705
return -1;
12706
}
12707
if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
12708
return -1;
12709
}
12710
if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
12711
return -1;
12712
}
12713
if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
12714
return -1;
12715
}
12716
if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
12717
return -1;
12718
}
12719
if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
12720
return -1;
12721
}
12722
if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
12723
return -1;
12724
}
12725
if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
12726
return -1;
12727
}
12728
if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
12729
return -1;
12730
}
12731
if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
12732
return -1;
12733
}
12734
if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
12735
return -1;
12736
}
12737
if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
12738
return -1;
12739
}
12740
if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
12741
return -1;
12742
}
12743
if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
12744
return -1;
12745
}
12746
if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
12747
return -1;
12748
}
12749
if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
12750
return -1;
12751
}
12752
if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
12753
return -1;
12754
}
12755
if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
12756
return -1;
12757
}
12758
if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
12759
return -1;
12760
}
12761
if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
12762
return -1;
12763
}
12764
if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
12765
return -1;
12766
}
12767
if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
12768
return -1;
12769
}
12770
if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
12771
return -1;
12772
}
12773
if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
12774
return -1;
12775
}
12776
if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
12777
return -1;
12778
}
12779
if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
12780
return -1;
12781
}
12782
if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
12783
return -1;
12784
}
12785
if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
12786
return -1;
12787
}
12788
if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
12789
return -1;
12790
}
12791
if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
12792
return -1;
12793
}
12794
if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
12795
return -1;
12796
}
12797
if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
12798
return -1;
12799
}
12800
if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
12801
return -1;
12802
}
12803
if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
12804
{
12805
return -1;
12806
}
12807
if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
12808
return -1;
12809
}
12810
if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
12811
return -1;
12812
}
12813
if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
12814
return -1;
12815
}
12816
if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
12817
return -1;
12818
}
12819
if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
12820
return -1;
12821
}
12822
if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
12823
< 0) {
12824
return -1;
12825
}
12826
if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
12827
return -1;
12828
}
12829
if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
12830
return -1;
12831
}
12832
if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
12833
return -1;
12834
}
12835
if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
12836
return -1;
12837
}
12838
if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
12839
return -1;
12840
}
12841
if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
12842
return -1;
12843
}
12844
if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
12845
return -1;
12846
}
12847
if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
12848
return -1;
12849
}
12850
if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
12851
return -1;
12852
}
12853
if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
12854
{
12855
return -1;
12856
}
12857
if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
12858
return -1;
12859
}
12860
if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
12861
return -1;
12862
}
12863
if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
12864
return -1;
12865
}
12866
if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
12867
return -1;
12868
}
12869
if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
12870
return -1;
12871
}
12872
if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
12873
return -1;
12874
}
12875
if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
12876
return -1;
12877
}
12878
if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
12879
return -1;
12880
}
12881
if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
12882
return -1;
12883
}
12884
if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
12885
return -1;
12886
}
12887
if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
12888
return -1;
12889
}
12890
if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
12891
return -1;
12892
}
12893
if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
12894
return -1;
12895
}
12896
if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
12897
return -1;
12898
}
12899
if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
12900
return -1;
12901
}
12902
if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
12903
return -1;
12904
}
12905
if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
12906
return -1;
12907
}
12908
if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
12909
return -1;
12910
}
12911
if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
12912
return -1;
12913
}
12914
if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
12915
return -1;
12916
}
12917
if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
12918
return -1;
12919
}
12920
if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
12921
return -1;
12922
}
12923
if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
12924
return -1;
12925
}
12926
if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
12927
return -1;
12928
}
12929
if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
12930
return -1;
12931
}
12932
if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
12933
return -1;
12934
}
12935
if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
12936
return -1;
12937
}
12938
if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
12939
return -1;
12940
}
12941
if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
12942
return -1;
12943
}
12944
if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
12945
return -1;
12946
}
12947
if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
12948
return -1;
12949
}
12950
if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
12951
return -1;
12952
}
12953
if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
12954
return -1;
12955
}
12956
if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
12957
return -1;
12958
}
12959
if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
12960
return -1;
12961
}
12962
if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
12963
return -1;
12964
}
12965
if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
12966
0) {
12967
return -1;
12968
}
12969
if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
12970
0) {
12971
return -1;
12972
}
12973
if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
12974
0) {
12975
return -1;
12976
}
12977
if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
12978
return -1;
12979
}
12980
if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
12981
return -1;
12982
}
12983
if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
12984
return -1;
12985
}
12986
if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
12987
return -1;
12988
}
12989
if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
12990
return -1;
12991
}
12992
if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
12993
return -1;
12994
}
12995
if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
12996
return -1;
12997
}
12998
if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
12999
return -1;
13000
}
13001
if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
13002
< 0) {
13003
return -1;
13004
}
13005
if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
13006
0) {
13007
return -1;
13008
}
13009
if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
13010
{
13011
return -1;
13012
}
13013
if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
13014
return -1;
13015
}
13016
if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
13017
return -1;
13018
}
13019
if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
13020
return -1;
13021
}
13022
if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
13023
return -1;
13024
}
13025
if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
13026
return -1;
13027
}
13028
if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
13029
return -1;
13030
}
13031
if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
13032
return -1;
13033
}
13034
if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
13035
return -1;
13036
}
13037
if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
13038
return -1;
13039
}
13040
if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
13041
{
13042
return -1;
13043
}
13044
return 0;
13045
}
13046
13047
static PyModuleDef_Slot astmodule_slots[] = {
13048
{Py_mod_exec, astmodule_exec},
13049
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
13050
{0, NULL}
13051
};
13052
13053
static struct PyModuleDef _astmodule = {
13054
PyModuleDef_HEAD_INIT,
13055
.m_name = "_ast",
13056
// The _ast module uses a per-interpreter state (PyInterpreterState.ast)
13057
.m_size = 0,
13058
.m_slots = astmodule_slots,
13059
};
13060
13061
PyMODINIT_FUNC
13062
PyInit__ast(void)
13063
{
13064
return PyModuleDef_Init(&_astmodule);
13065
}
13066
13067
13068
PyObject* PyAST_mod2obj(mod_ty t)
13069
{
13070
struct ast_state *state = get_ast_state();
13071
if (state == NULL) {
13072
return NULL;
13073
}
13074
13075
int starting_recursion_depth;
13076
/* Be careful here to prevent overflow. */
13077
int COMPILER_STACK_FRAME_SCALE = 3;
13078
PyThreadState *tstate = _PyThreadState_GET();
13079
if (!tstate) {
13080
return 0;
13081
}
13082
state->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
13083
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
13084
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
13085
state->recursion_depth = starting_recursion_depth;
13086
13087
PyObject *result = ast2obj_mod(state, t);
13088
13089
/* Check that the recursion depth counting balanced correctly */
13090
if (result && state->recursion_depth != starting_recursion_depth) {
13091
PyErr_Format(PyExc_SystemError,
13092
"AST constructor recursion depth mismatch (before=%d, after=%d)",
13093
starting_recursion_depth, state->recursion_depth);
13094
return 0;
13095
}
13096
return result;
13097
}
13098
13099
/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
13100
mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
13101
{
13102
const char * const req_name[] = {"Module", "Expression", "Interactive"};
13103
int isinstance;
13104
13105
if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
13106
return NULL;
13107
}
13108
13109
struct ast_state *state = get_ast_state();
13110
if (state == NULL) {
13111
return NULL;
13112
}
13113
13114
PyObject *req_type[3];
13115
req_type[0] = state->Module_type;
13116
req_type[1] = state->Expression_type;
13117
req_type[2] = state->Interactive_type;
13118
13119
assert(0 <= mode && mode <= 2);
13120
13121
isinstance = PyObject_IsInstance(ast, req_type[mode]);
13122
if (isinstance == -1)
13123
return NULL;
13124
if (!isinstance) {
13125
PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
13126
req_name[mode], _PyType_Name(Py_TYPE(ast)));
13127
return NULL;
13128
}
13129
13130
mod_ty res = NULL;
13131
if (obj2ast_mod(state, ast, &res, arena) != 0)
13132
return NULL;
13133
else
13134
return res;
13135
}
13136
13137
int PyAST_Check(PyObject* obj)
13138
{
13139
struct ast_state *state = get_ast_state();
13140
if (state == NULL) {
13141
return -1;
13142
}
13143
return PyObject_IsInstance(obj, state->AST_type);
13144
}
13145
13146
13147
13148